From eca9ed9ca73827ab48f52147d273bdf4f5db4a84 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 02:40:49 +0900 Subject: [PATCH 1/4] =?UTF-8?q?FEAT=20:=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20Error/Success=20Enum=20=EA=B3=BC=20Exception=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/domain/exception/UserError.java | 30 +++++++++++++++++++ .../user/domain/exception/UserException.java | 9 ++++++ .../user/domain/exception/UserSuccess.java | 29 ++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java new file mode 100644 index 0000000..3acdf3c --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java @@ -0,0 +1,30 @@ +package org.sopt.sopkerton.user.domain.exception; + +import lombok.AllArgsConstructor; +import org.sopt.sopkerton.common.exception.base.ErrorBase; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +public enum UserError implements ErrorBase { + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "Can not found User."), + ; + + private final HttpStatus status; + private final String errorMessage; + + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java new file mode 100644 index 0000000..f17b0b6 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java @@ -0,0 +1,9 @@ +package org.sopt.sopkerton.user.domain.exception; + +import org.sopt.sopkerton.common.exception.base.ExceptionBase; + +public class UserException extends ExceptionBase { + public UserException(UserError userError) { + super(userError); + } +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java new file mode 100644 index 0000000..3af93c8 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java @@ -0,0 +1,29 @@ +package org.sopt.sopkerton.user.domain.exception; + +import lombok.AllArgsConstructor; +import org.sopt.sopkerton.common.exception.base.SuccessBase; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +public enum UserSuccess implements SuccessBase { + USER_MAIN_VIEW_SUCCESS(HttpStatus.OK, "Get User Main View Data Successful.") + ; + + private final HttpStatus status; + private final String successMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getSuccessMessage() { + return this.successMessage; + } +} From 6aef1a309a58a07012da4d33c74230d48be8dc1f Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 02:41:15 +0900 Subject: [PATCH 2/4] =?UTF-8?q?FEAT=20:=20User=20Domain=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/sopkerton/user/domain/User.java | 33 +++++++++++++++++++ .../sopkerton/user/domain/enums/Gender.java | 5 +++ .../user/infrastructure/UserRepository.java | 8 +++++ 3 files changed, 46 insertions(+) create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/User.java create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/enums/Gender.java create mode 100644 src/main/java/org/sopt/sopkerton/user/infrastructure/UserRepository.java diff --git a/src/main/java/org/sopt/sopkerton/user/domain/User.java b/src/main/java/org/sopt/sopkerton/user/domain/User.java new file mode 100644 index 0000000..94b1fca --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/User.java @@ -0,0 +1,33 @@ +package org.sopt.sopkerton.user.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.sopt.sopkerton.user.domain.enums.Gender; + +@Getter +@Entity +@Table(schema = "skt-t1-app", name = "users") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +public class User { + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + Long id; + + @Column(name = "name", nullable = false) + String name; + + @Column(name = "gender", nullable = false) + @Enumerated(value = EnumType.STRING) + Gender gender; + + @Column(name = "thumbnail") + String thumbnail; + + @Column(name = "age", nullable = false) + int age; + +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/enums/Gender.java b/src/main/java/org/sopt/sopkerton/user/domain/enums/Gender.java new file mode 100644 index 0000000..876b793 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/enums/Gender.java @@ -0,0 +1,5 @@ +package org.sopt.sopkerton.user.domain.enums; + +public enum Gender { + MALE, FEMALE +} diff --git a/src/main/java/org/sopt/sopkerton/user/infrastructure/UserRepository.java b/src/main/java/org/sopt/sopkerton/user/infrastructure/UserRepository.java new file mode 100644 index 0000000..5bc9781 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/infrastructure/UserRepository.java @@ -0,0 +1,8 @@ +package org.sopt.sopkerton.user.infrastructure; + + +import org.sopt.sopkerton.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { +} From a4a3a4c6d0304b369bb61afa10e4c83324c73f65 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 02:42:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?FEAT=20:=20MainView=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EA=B0=9D=EC=B2=B4=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A0=95=EB=B3=B4=20=EA=B0=9D=EC=B2=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopkerton/user/dto/response/MainView.java | 17 +++++++ .../sopkerton/user/service/UserService.java | 50 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/main/java/org/sopt/sopkerton/user/dto/response/MainView.java create mode 100644 src/main/java/org/sopt/sopkerton/user/service/UserService.java diff --git a/src/main/java/org/sopt/sopkerton/user/dto/response/MainView.java b/src/main/java/org/sopt/sopkerton/user/dto/response/MainView.java new file mode 100644 index 0000000..2ca1b8c --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/dto/response/MainView.java @@ -0,0 +1,17 @@ +package org.sopt.sopkerton.user.dto.response; + + +public record MainView( + long userId, + String thumbnail, + String name, + String gender, // 남성 || 여성 + int age, + String criminalHistory, + String criminalHistoryDate, + int volunteerHours, + int completedProgramCount, + int certificateCount, + double ringRate +) { +} diff --git a/src/main/java/org/sopt/sopkerton/user/service/UserService.java b/src/main/java/org/sopt/sopkerton/user/service/UserService.java new file mode 100644 index 0000000..2ada395 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/service/UserService.java @@ -0,0 +1,50 @@ +package org.sopt.sopkerton.user.service; + +import lombok.RequiredArgsConstructor; +import org.sopt.sopkerton.user.domain.User; +import org.sopt.sopkerton.user.domain.enums.Gender; +import org.sopt.sopkerton.user.domain.exception.UserError; +import org.sopt.sopkerton.user.domain.exception.UserException; +import org.sopt.sopkerton.user.dto.response.MainView; +import org.sopt.sopkerton.user.infrastructure.UserRepository; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserService { + private static final String CRIMINAL_HISTORY = "단순 절도죄"; + private static final String CRIMINAL_HISTORY_DATE = "3년전"; + private static final String MALE = "남성"; + private static final String FEMALE = "여성"; + + private static final int VOLUNTEER_HOURS = 50; + private static final int COMPLETED_PROGRAM_COUNT = 4; + private static final int CERTIFICATE_COUNT = 4; + private static final double RING_RATE = 0.65; + + private final UserRepository userRepository; + + public MainView getMainViewInfo(Long userId) { + User targetUser = userRepository.findById(userId) + .orElseThrow(() -> new UserException(UserError.USER_NOT_FOUND)); + String gender; + if (targetUser.getGender().equals(Gender.MALE)) { + gender = MALE; + } else { + gender = FEMALE; + } + return new MainView( + targetUser.getId(), + targetUser.getThumbnail(), + targetUser.getName(), + gender, + targetUser.getAge(), + CRIMINAL_HISTORY, + CRIMINAL_HISTORY_DATE, + VOLUNTEER_HOURS, + COMPLETED_PROGRAM_COUNT, + CERTIFICATE_COUNT, + RING_RATE + ); + } +} From 25f49cbdeef836155c29ee1ffdfa6acd3d6c2732 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 02:43:57 +0900 Subject: [PATCH 4/4] =?UTF-8?q?FEAT=20:=20MainView=20=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/response/ApiResponse.java | 4 ++- .../user/controller/UserController.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/sopt/sopkerton/user/controller/UserController.java diff --git a/src/main/java/org/sopt/sopkerton/common/response/ApiResponse.java b/src/main/java/org/sopt/sopkerton/common/response/ApiResponse.java index a64d7d3..38f0045 100644 --- a/src/main/java/org/sopt/sopkerton/common/response/ApiResponse.java +++ b/src/main/java/org/sopt/sopkerton/common/response/ApiResponse.java @@ -3,10 +3,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.sopt.sopkerton.common.exception.base.ErrorBase; import org.sopt.sopkerton.common.exception.base.SuccessBase; +@Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE) public class ApiResponse { @@ -21,7 +23,7 @@ public static ApiResponse success(SuccessBase success) { } public static ApiResponse success(SuccessBase success, T data) { - return new ApiResponse(success.getHttpStatusCode(), success.getSuccessMessage(), data); + return new ApiResponse<>(success.getHttpStatusCode(), success.getSuccessMessage(), data); } public static ApiResponse error(ErrorBase error) { diff --git a/src/main/java/org/sopt/sopkerton/user/controller/UserController.java b/src/main/java/org/sopt/sopkerton/user/controller/UserController.java new file mode 100644 index 0000000..24f7029 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/controller/UserController.java @@ -0,0 +1,32 @@ +package org.sopt.sopkerton.user.controller; + +import lombok.RequiredArgsConstructor; +import org.sopt.sopkerton.common.response.ApiResponse; +import org.sopt.sopkerton.user.domain.exception.UserSuccess; +import org.sopt.sopkerton.user.dto.response.MainView; +import org.sopt.sopkerton.user.service.UserService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/user") +public class UserController { + + private final UserService userService; + + @GetMapping("/info/{userId}") + public ResponseEntity> orderMainView( + @PathVariable("userId") Long userId + ) { + MainView mainViewInfo = userService.getMainViewInfo(userId); + return ResponseEntity + .status(UserSuccess.USER_MAIN_VIEW_SUCCESS.getHttpStatus()) + .body( + ApiResponse.success(UserSuccess.USER_MAIN_VIEW_SUCCESS, mainViewInfo) + ); + } +}