From a9519787a38ff983f851d499643f5e5f37c91a02 Mon Sep 17 00:00:00 2001 From: "unsualc@likelion.org" Date: Sat, 15 Apr 2023 01:14:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?1=EC=A3=BC=EC=B0=A8=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/seminar/gosopt/Athletes.java | 16 ++++++ .../com/seminar/gosopt/FootballPlayer.java | 15 ++++++ .../main/java/com/seminar/gosopt/Main.java | 11 ++++ .../main/java/com/seminar/gosopt/Person.java | 17 +++++++ .../java/com/seminar/gosopt/Poketmon.java | 51 +++++++++++++++++++ .../java/com/seminar/gosopt/SportsType.java | 17 +++++++ .../gosopt/interfacepractice/Pikachu.java | 13 +++++ .../gosopt/interfacepractice/Poketmon.java | 6 +++ 8 files changed, 146 insertions(+) create mode 100644 week1/src/main/java/com/seminar/gosopt/Athletes.java create mode 100644 week1/src/main/java/com/seminar/gosopt/FootballPlayer.java create mode 100644 week1/src/main/java/com/seminar/gosopt/Person.java create mode 100644 week1/src/main/java/com/seminar/gosopt/Poketmon.java create mode 100644 week1/src/main/java/com/seminar/gosopt/SportsType.java create mode 100644 week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java create mode 100644 week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java diff --git a/week1/src/main/java/com/seminar/gosopt/Athletes.java b/week1/src/main/java/com/seminar/gosopt/Athletes.java new file mode 100644 index 0000000..6f44a1d --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Athletes.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java b/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java new file mode 100644 index 0000000..27fd7be --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/FootballPlayer.java @@ -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() + "선수 입니다."); + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/Main.java b/week1/src/main/java/com/seminar/gosopt/Main.java index 2b22bb9..01d8fc8 100644 --- a/week1/src/main/java/com/seminar/gosopt/Main.java +++ b/week1/src/main/java/com/seminar/gosopt/Main.java @@ -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()); } } \ No newline at end of file diff --git a/week1/src/main/java/com/seminar/gosopt/Person.java b/week1/src/main/java/com/seminar/gosopt/Person.java new file mode 100644 index 0000000..7aeed44 --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Person.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/Poketmon.java b/week1/src/main/java/com/seminar/gosopt/Poketmon.java new file mode 100644 index 0000000..e04a7cd --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/Poketmon.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/SportsType.java b/week1/src/main/java/com/seminar/gosopt/SportsType.java new file mode 100644 index 0000000..188cdbd --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/SportsType.java @@ -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; + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java new file mode 100644 index 0000000..ce4e868 --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Pikachu.java @@ -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("피카피카"); + } +} diff --git a/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java new file mode 100644 index 0000000..9c0726a --- /dev/null +++ b/week1/src/main/java/com/seminar/gosopt/interfacepractice/Poketmon.java @@ -0,0 +1,6 @@ +package com.seminar.gosopt.interfacepractice; + +public interface Poketmon { + + public abstract void 몸통박치기(); +} From 2ce3bb2cde21e1d9541147901c2c03dfcff37fa3 Mon Sep 17 00:00:00 2001 From: "unsualc@likelion.org" Date: Wed, 3 May 2023 11:38:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C=20=EC=A0=9C=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week3/build.gradle | 4 ++- .../seminar/week3/common/ApiResponseDto.java | 30 ++++++++++++++++ .../advice/ControllerExceptionAdvice.java | 19 ++++++++++ .../week3/controller/MemberController.java | 29 +++++++++++++++ .../java/com/seminar/week3/domain/Member.java | 34 ++++++++++++++++++ .../week3/dto/member/MemberRequestDto.java | 12 +++++++ .../week3/dto/member/MemberResponseDto.java | 17 +++++++++ .../seminar/week3/exception/ErrorStatus.java | 35 +++++++++++++++++++ .../week3/exception/SuccessStatus.java | 18 ++++++++++ .../week3/repository/MemberRepository.java | 7 ++++ .../seminar/week3/service/MemberService.java | 30 ++++++++++++++++ week3/src/main/resources/application.yml | 18 ++++++++++ 12 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 week3/src/main/java/com/seminar/week3/common/ApiResponseDto.java create mode 100644 week3/src/main/java/com/seminar/week3/common/advice/ControllerExceptionAdvice.java create mode 100644 week3/src/main/java/com/seminar/week3/controller/MemberController.java create mode 100644 week3/src/main/java/com/seminar/week3/domain/Member.java create mode 100644 week3/src/main/java/com/seminar/week3/dto/member/MemberRequestDto.java create mode 100644 week3/src/main/java/com/seminar/week3/dto/member/MemberResponseDto.java create mode 100644 week3/src/main/java/com/seminar/week3/exception/ErrorStatus.java create mode 100644 week3/src/main/java/com/seminar/week3/exception/SuccessStatus.java create mode 100644 week3/src/main/java/com/seminar/week3/repository/MemberRepository.java create mode 100644 week3/src/main/java/com/seminar/week3/service/MemberService.java create mode 100644 week3/src/main/resources/application.yml diff --git a/week3/build.gradle b/week3/build.gradle index 0ce6a16..ec3fd6e 100644 --- a/week3/build.gradle +++ b/week3/build.gradle @@ -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' } \ No newline at end of file diff --git a/week3/src/main/java/com/seminar/week3/common/ApiResponseDto.java b/week3/src/main/java/com/seminar/week3/common/ApiResponseDto.java new file mode 100644 index 0000000..c42c8a2 --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/common/ApiResponseDto.java @@ -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 { + + 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 ApiResponseDto success(SuccessStatus successStatus, T data) { + return new ApiResponseDto(successStatus.getHttpStatus().value(), successStatus.getMessage(), data); + } + + public static ApiResponseDto error(ErrorStatus errorStatus) { + return new ApiResponseDto<>(errorStatus.getHttpStatus().value(), errorStatus.getMessage()); + } + +} diff --git a/week3/src/main/java/com/seminar/week3/common/advice/ControllerExceptionAdvice.java b/week3/src/main/java/com/seminar/week3/common/advice/ControllerExceptionAdvice.java new file mode 100644 index 0000000..8abb8ff --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/common/advice/ControllerExceptionAdvice.java @@ -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); + } +} diff --git a/week3/src/main/java/com/seminar/week3/controller/MemberController.java b/week3/src/main/java/com/seminar/week3/controller/MemberController.java new file mode 100644 index 0000000..845c5fc --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/controller/MemberController.java @@ -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 signup(@RequestBody @Valid MemberRequestDto dto){ + return ApiResponseDto.success(SuccessStatus.SIGNUP_SUCCESS, memberService.create(dto)); + } + + +} diff --git a/week3/src/main/java/com/seminar/week3/domain/Member.java b/week3/src/main/java/com/seminar/week3/domain/Member.java new file mode 100644 index 0000000..ff173bc --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/domain/Member.java @@ -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; + } + +} diff --git a/week3/src/main/java/com/seminar/week3/dto/member/MemberRequestDto.java b/week3/src/main/java/com/seminar/week3/dto/member/MemberRequestDto.java new file mode 100644 index 0000000..16fae8d --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/dto/member/MemberRequestDto.java @@ -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; +} diff --git a/week3/src/main/java/com/seminar/week3/dto/member/MemberResponseDto.java b/week3/src/main/java/com/seminar/week3/dto/member/MemberResponseDto.java new file mode 100644 index 0000000..c59bb04 --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/dto/member/MemberResponseDto.java @@ -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); + } +} diff --git a/week3/src/main/java/com/seminar/week3/exception/ErrorStatus.java b/week3/src/main/java/com/seminar/week3/exception/ErrorStatus.java new file mode 100644 index 0000000..40ee4ed --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/exception/ErrorStatus.java @@ -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; + +} diff --git a/week3/src/main/java/com/seminar/week3/exception/SuccessStatus.java b/week3/src/main/java/com/seminar/week3/exception/SuccessStatus.java new file mode 100644 index 0000000..3a08967 --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/exception/SuccessStatus.java @@ -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; + + +} diff --git a/week3/src/main/java/com/seminar/week3/repository/MemberRepository.java b/week3/src/main/java/com/seminar/week3/repository/MemberRepository.java new file mode 100644 index 0000000..63c142d --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/repository/MemberRepository.java @@ -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 { +} diff --git a/week3/src/main/java/com/seminar/week3/service/MemberService.java b/week3/src/main/java/com/seminar/week3/service/MemberService.java new file mode 100644 index 0000000..59e63cc --- /dev/null +++ b/week3/src/main/java/com/seminar/week3/service/MemberService.java @@ -0,0 +1,30 @@ +package com.seminar.week3.service; + +import com.seminar.week3.domain.Member; +import com.seminar.week3.dto.member.MemberRequestDto; +import com.seminar.week3.dto.member.MemberResponseDto; +import com.seminar.week3.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberService { + + private final MemberRepository memberRepository; + + @Transactional + public MemberResponseDto create(MemberRequestDto memberRequestDto) { + Member member = Member.builder() + .id(memberRequestDto.getUserId()) + .nickname(memberRequestDto.getNickname()) + .email(memberRequestDto.getEmail()) + .password(memberRequestDto.getPassword()) + .build(); + + memberRepository.save(member); + + return MemberResponseDto.of(member.getId(), member.getNickname()); + } +} diff --git a/week3/src/main/resources/application.yml b/week3/src/main/resources/application.yml new file mode 100644 index 0000000..97a1745 --- /dev/null +++ b/week3/src/main/resources/application.yml @@ -0,0 +1,18 @@ +server: + port: 8083 + +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/sopt_32?useSSL=true&useUnicode=true&serverTimezone=Asia/Seoul + username: root + password: Devunan123! + + jpa: + show-sql: true + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.MySQL5InnoDBDialect \ No newline at end of file