Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3주차] 기본과제 제출 #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/Athletes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.seminar.gosopt;

import lombok.Getter;

public class Athletes extends Person {

private SportsType type;

public SportsType getType() {
return type;
}

public Athletes(SportsType type) {
this.type = type;
}
}
15 changes: 15 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/FootballPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.seminar.gosopt;

import lombok.Getter;

@Getter
public class FootballPlayer extends Athletes{

public FootballPlayer(SportsType type) {
super(type);
}

protected void introduce() {
System.out.println("저는 " + this.getType().getValue() + "선수 입니다.");
}
}
11 changes: 11 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,16 @@
public class Main {
public static void main(String[] args) {
System.out.println("hello world");

FootballPlayer footballPlayer = new FootballPlayer(SportsType.FOOTBALL);
System.out.println(footballPlayer.getType());
footballPlayer.introduce();


Poketmon ggobugi = new Poketmon("ggobugi");
System.out.println(System.identityHashCode(ggobugi));
System.out.println(ggobugi.getClass());
System.out.println(ggobugi.getName());
System.out.println(ggobugi.getSkill());
}
}
17 changes: 17 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.seminar.gosopt;

import lombok.Getter;

public abstract class Person {

private String name;
private int age;

public String getName() {
return name;
}

public int getAge() {
return age;
}
}
51 changes: 51 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/Poketmon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.seminar.gosopt;

public class Poketmon {

private String name;
private String type;
private String skill;

public Poketmon(String name) {
this.name = name;
}

public Poketmon(String name, String type) {
this.name = name;
this.type = type;
}

public Poketmon() {

}

public Poketmon(String name, String type, String skill) {
this.name = name;
this.type = type;
this.skill = skill;
}

public String getName() {
return name;
}

public String getType() {
return type;
}

public String getSkill() {
return skill;
}

public void setName(String name) {
this.name = name;
}

public void setType(String type) {
this.type = type;
}

public void setSkill(String skill) {
this.skill = skill;
}
}
17 changes: 17 additions & 0 deletions week1/src/main/java/com/seminar/gosopt/SportsType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.seminar.gosopt;

public enum SportsType {
FOOTBALL("축구"),
BASKETBALL("농구"),
TENNIS("테니스");

private final String value;

SportsType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.seminar.gosopt.interfacepractice;

public class Pikachu implements Poketmon{

@Override
public void 몸통박치기() {
System.out.println("몸통 박치기");
}

public void 백만볼트() {
System.out.println("피카피카");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.seminar.gosopt.interfacepractice;

public interface Poketmon {

public abstract void 몸통박치기();
}
4 changes: 3 additions & 1 deletion week3/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dependencies {

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.32'
implementation 'org.springframework.boot:spring-boot-starter-validation'
}
30 changes: 30 additions & 0 deletions week3/src/main/java/com/seminar/week3/common/ApiResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.seminar.week3.common;

import com.seminar.week3.exception.ErrorStatus;
import com.seminar.week3.exception.SuccessStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
@AllArgsConstructor
public class ApiResponseDto<T> {

private final int code;
private final String message;
private T data;

public static ApiResponseDto success(SuccessStatus successStatus) {
return new ApiResponseDto<>(successStatus.getHttpStatus().value(), successStatus.getMessage());
}

public static <T> ApiResponseDto<T> success(SuccessStatus successStatus, T data) {
return new ApiResponseDto<T>(successStatus.getHttpStatus().value(), successStatus.getMessage(), data);
}

public static ApiResponseDto error(ErrorStatus errorStatus) {
return new ApiResponseDto<>(errorStatus.getHttpStatus().value(), errorStatus.getMessage());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.seminar.week3.common.advice;

import com.seminar.week3.common.ApiResponseDto;
import com.seminar.week3.exception.ErrorStatus;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ControllerExceptionAdvice {

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
protected ApiResponseDto handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) {
return ApiResponseDto.error(ErrorStatus.VALIDATION_REQUEST_MISSING_EXCEPTION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.seminar.week3.controller;


import com.seminar.week3.common.ApiResponseDto;
import com.seminar.week3.dto.member.MemberRequestDto;
import com.seminar.week3.dto.member.MemberResponseDto;
import com.seminar.week3.exception.SuccessStatus;
import com.seminar.week3.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
public class MemberController {

private final MemberService memberService;

@ResponseStatus(HttpStatus.CREATED)
public ApiResponseDto<MemberResponseDto> signup(@RequestBody @Valid MemberRequestDto dto){
return ApiResponseDto.success(SuccessStatus.SIGNUP_SUCCESS, memberService.create(dto));
}


}
34 changes: 34 additions & 0 deletions week3/src/main/java/com/seminar/week3/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.seminar.week3.domain;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String nickname;

@Column(nullable = false)
private String email;

@Column(nullable = false)
private String password;

@Builder
public Member(Long id, String nickname, String email, String password) {
this.id = id;
this.nickname = nickname;
this.email = email;
this.password = password;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.seminar.week3.dto.member;

import lombok.Data;

@Data
public class MemberRequestDto {

private Long userId;
private String nickname;
private String email;
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.seminar.week3.dto.member;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@AllArgsConstructor
public class MemberResponseDto {

private Long userId;
private String nickname;

public static MemberResponseDto of(Long userId, String nickname) {
return new MemberResponseDto(userId, nickname);
}
}
35 changes: 35 additions & 0 deletions week3/src/main/java/com/seminar/week3/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.seminar.week3.exception;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

@Getter
@RequiredArgsConstructor
public enum ErrorStatus {

/*
BAD_REQUEST
*/
VALIDATION_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."),
VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 입력되지 않았습니다."),


/*
CONFLICT
*/
CONFLICT_EMAIL_EXCEPTION(HttpStatus.CONFLICT, "이미 등록된 이메일입니다."),
CONFLICT_NICKNAME_EXCEPTION(HttpStatus.CONFLICT, "이미 등록된 닉네임입니다."),

/*
SERVER_ERROR
*/
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "예상치 못한 서버 에러가 발생했습니다."),
BAD_GATEWAY_EXCEPTION(HttpStatus.BAD_GATEWAY, "일시적인 에러가 발생하였습니다.\n잠시 후 다시 시도해주세요!"),
SERVICE_UNAVAILABLE_EXCEPTION(HttpStatus.SERVICE_UNAVAILABLE, "현재 점검 중입니다.\n잠시 후 다시 시도해주세요!"),
;

private final HttpStatus httpStatus;
private final String message;

}
18 changes: 18 additions & 0 deletions week3/src/main/java/com/seminar/week3/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.seminar.week3.exception;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

@Getter
@RequiredArgsConstructor
public enum SuccessStatus {

SIGNUP_SUCCESS(HttpStatus.CREATED, "회원가입에 성공하였습니다."),
;

private final HttpStatus httpStatus;
private final String message;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.seminar.week3.repository;

import com.seminar.week3.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {
}
Loading