From 7c6c7b8dea1823e24296b5295551a2ef80d38a0d Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 14:22:00 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=85=20=20ErrorCode=EC=99=80=20Success?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EC=9D=98=20getter=EB=A5=BC=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/apiPayload/code/BaseErrorCode.java | 10 ++++++++++ .../global/apiPayload/code/BaseSuccessCode.java | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseErrorCode.java create mode 100644 src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseSuccessCode.java diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseErrorCode.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseErrorCode.java new file mode 100644 index 0000000..42ad0f1 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,10 @@ +package com.example.spring_boot_a.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseErrorCode { + + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseSuccessCode.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseSuccessCode.java new file mode 100644 index 0000000..8c0bc5c --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/BaseSuccessCode.java @@ -0,0 +1,10 @@ +package com.example.spring_boot_a.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseSuccessCode { + + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} From e16573427991c820a3ea5dfcb4f5e3d7e3c915e3 Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 14:34:28 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=85=20=EC=84=B1=EA=B3=B5=EA=B3=BC=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=BD=94=EB=93=9C=EB=A5=BC=20Enum?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EC=96=B4=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EC=97=90=20=EC=82=AC=EC=9A=A9=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=83=9D=EC=84=B1=ED=96=88?= =?UTF-8?q?=EC=94=81=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/GeneralErrorCode.java | 28 +++++++++++++++++++ .../apiPayload/code/GeneralSuccessCode.java | 24 ++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java create mode 100644 src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralSuccessCode.java diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java new file mode 100644 index 0000000..02f168d --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java @@ -0,0 +1,28 @@ +package com.example.spring_boot_a.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralErrorCode implements BaseErrorCode { + + BAD_REQUEST(HttpStatus.BAD_REQUEST, + "COMMON400_1", + "잘못된 요청입니다."), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, + "AUTH401_1", + "인증이 필요합니다."), + FORBIDDEN(HttpStatus.FORBIDDEN, + "AUTH403_1", + "요청이 거부되었습니다."), + NOT_FOUND(HttpStatus.NOT_FOUND, + "COMMON404_1", + "요청한 리소스를 찾을 수 없습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralSuccessCode.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralSuccessCode.java new file mode 100644 index 0000000..0116425 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralSuccessCode.java @@ -0,0 +1,24 @@ +package com.example.spring_boot_a.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralSuccessCode implements BaseSuccessCode{ + + OK(HttpStatus.OK, + "COMMON200_1", + "요청이 성공적으로 처리되었습니다."), + CREATED(HttpStatus.CREATED, + "COMMON201_1", + "리소스가 성공적으로 생성되었습니다."), + NO_CONTENT(HttpStatus.NO_CONTENT, + "COMMON204_1", + "성공했지만 반환할 데이터는 없습니다."); + + private final HttpStatus status; + private final String code; + private final String message; +} From 31eb4eeb7abf5827469fd5371d7a7b404bc7ef6d Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 14:43:20 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=85=20APIResponse=20=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EC=84=B1=EA=B3=B5=EA=B3=BC=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=EB=A5=BC=20=EA=B3=B5=ED=86=B5=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EC=96=B4=EC=84=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EC=97=88=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/apiPayload/code/ApiResponse.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/com/example/spring_boot_a/global/apiPayload/code/ApiResponse.java diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/ApiResponse.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/ApiResponse.java new file mode 100644 index 0000000..db66232 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/ApiResponse.java @@ -0,0 +1,50 @@ +package com.example.spring_boot_a.global.apiPayload.code; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +public class ApiResponse { + + @JsonProperty("isSuccess") + private final Boolean isSuccess; + + @JsonProperty("code") + private final String code; + + @JsonProperty("message") + private final String message; + + @JsonProperty("result") + private T result; + + + public static ApiResponse onSuccess(BaseSuccessCode code, T result) { + return new ApiResponse<>(true, code.getCode(), code.getMessage(), result); + } + + public static ApiResponse onSuccess(BaseSuccessCode code) { + return new ApiResponse<>(true, code.getCode(), code.getMessage(), null); + } + + public static ApiResponse onSuccess(T result) { + return new ApiResponse<>(true, + GeneralSuccessCode.OK.getCode(), + GeneralSuccessCode.OK.getMessage(), + result + ); + } + + public static ApiResponse onFailure(BaseErrorCode code, T result) { + return new ApiResponse<>(false, code.getCode(), code.getMessage(), result); + } + + + public static ApiResponse onFailure(BaseErrorCode code) { + return new ApiResponse<>(false, code.getCode(), code.getMessage(), null); + } +} From db6b14b140d4856c329027406ded477c79016860 Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 19:05:47 +0900 Subject: [PATCH 4/6] =?UTF-8?q?User=EC=97=90=20=EB=8C=80=ED=95=9C=20dto?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=EB=93=A4=EA=B3=BC=20=EC=9D=B4=EB=A5=BC=20ent?= =?UTF-8?q?ity=EC=99=80=20=EC=86=8C=ED=86=B5=ED=95=A0=20Converter=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/user/converter/UserConverter.java | 65 +++++++++++++++++++ .../api/user/dto/UserRequestDto.java | 43 ++++++++++++ .../api/user/dto/UserResponseDto.java | 45 +++++++++++++ .../controller/UserController.java | 4 ++ 4 files changed, 157 insertions(+) create mode 100644 src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java create mode 100644 src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java create mode 100644 src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java create mode 100644 src/main/java/com/example/spring_boot_a/controller/UserController.java diff --git a/src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java b/src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java new file mode 100644 index 0000000..6a3ae58 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java @@ -0,0 +1,65 @@ +package com.example.spring_boot_a.api.user.converter; + +import com.example.spring_boot_a.api.user.dto.UserRequestDto; +import com.example.spring_boot_a.api.user.dto.UserResponseDto; +import com.example.spring_boot_a.domain.entity.User; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.List; + +@Component +public class UserConverter { + + public User toUser(UserRequestDto.Create request) { + User user = new User(); + user.setName(request.getName()); + user.setGender(request.getGender()); + user.setBirth(request.getBirth()); + user.setAddress(request.getAddress()); + user.setEmail(request.getEmail()); + user.setPhoneNumber(request.getPhoneNumber()); + user.setSocialType(request.getSocialType()); + user.setPoint(0); + user.setUpdatedAt(Instant.now()); + return user; + } + + public UserResponseDto.CreateResult toCreateResult(User user) { + return UserResponseDto.CreateResult.builder() + .userId(user.getUserId()) + .name(user.getName()) + .email(user.getEmail()) + .build(); + } + + public UserResponseDto.Detail toDetail(User user) { + return UserResponseDto.Detail.builder() + .userId(user.getUserId()) + .name(user.getName()) + .gender(user.getGender()) + .birth(user.getBirth()) + .address(user.getAddress()) + .email(user.getEmail()) + .phoneNumber(user.getPhoneNumber()) + .point(user.getPoint()) + .socialType(user.getSocialType()) + .updatedAt(user.getUpdatedAt()) + .build(); + } + + public UserResponseDto.Summary toSummary(User user) { + return UserResponseDto.Summary.builder() + .userId(user.getUserId()) + .name(user.getName()) + .address(user.getAddress()) + .point(user.getPoint()) + .build(); + } + + public List toSummaryList(List users) { + return users.stream() + .map(this::toSummary) + .toList(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java b/src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java new file mode 100644 index 0000000..c8887eb --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java @@ -0,0 +1,43 @@ +package com.example.spring_boot_a.api.user.dto; + +import com.example.spring_boot_a.domain.entity.enums.AddressGu; +import com.example.spring_boot_a.domain.entity.enums.Gender; +import com.example.spring_boot_a.domain.entity.enums.SocialLoginType; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +public class UserRequestDto { + + @Getter + @NoArgsConstructor + public static class Create { + + @NotBlank(message = "이름은 필수값입니다.") + private String name; + + @NotNull(message = "성별은 필수값입니다.") + private Gender gender; + + private LocalDate birth; + + @NotNull(message = "주소(구)는 필수값입니다.") + private AddressGu address; + + @NotBlank(message = "이메일은 필수값입니다.") + @Email(message = "이메일 형식이 올바르지 않습니다.") + private String email; + + @NotBlank(message = "전화번호는 필수값입니다.") + @Size(max = 20, message = "전화번호는 최대 20자입니다.") + private String phoneNumber; + + @NotNull(message = "소셜 타입은 필수값입니다.") + private SocialLoginType socialType; + } +} diff --git a/src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java b/src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java new file mode 100644 index 0000000..75fc818 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java @@ -0,0 +1,45 @@ +package com.example.spring_boot_a.api.user.dto; + +import com.example.spring_boot_a.domain.entity.enums.AddressGu; +import com.example.spring_boot_a.domain.entity.enums.Gender; +import com.example.spring_boot_a.domain.entity.enums.SocialLoginType; +import lombok.Builder; +import lombok.Getter; + +import java.time.Instant; +import java.time.LocalDate; + +public class UserResponseDto { + + @Getter + @Builder + public static class CreateResult { + private Long userId; + private String name; + private String email; + } + + @Getter + @Builder + public static class Detail { + private Long userId; + private String name; + private Gender gender; + private LocalDate birth; + private AddressGu address; + private String email; + private String phoneNumber; + private Integer point; + private SocialLoginType socialType; + private Instant updatedAt; + } + + @Getter + @Builder + public static class Summary { + private Long userId; + private String name; + private AddressGu address; + private Integer point; + } +} diff --git a/src/main/java/com/example/spring_boot_a/controller/UserController.java b/src/main/java/com/example/spring_boot_a/controller/UserController.java new file mode 100644 index 0000000..7a25cb9 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/controller/UserController.java @@ -0,0 +1,4 @@ +package com.example.spring_boot_a.controller; + +public class UserController { +} From 515b740abad4879b0d00a00e0bd38e24ec528fe0 Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 19:53:12 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=85=20UssrService=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=9B=84=20=EA=B3=B5=ED=86=B5=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?Controller=EC=83=9D=EC=84=B1=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyReviewController.java | 6 +- .../ReviewController.java | 6 +- .../controller/UserController.java | 62 +++++++++++++++++++ .../spring_boot_a/domain/entity/Store.java | 3 + .../spring_boot_a/domain/entity/Term.java | 1 + .../domain/entity/{ => etc}/Food.java | 3 +- .../domain/entity/{ => etc}/Location.java | 3 +- .../domain/entity/{ => etc}/Mission.java | 4 +- .../domain/entity/{ => etc}/Reply.java | 3 +- .../domain/entity/{ => etc}/ReviewPhoto.java | 3 +- .../domain/entity/{ => review}/Review.java | 9 +-- .../entity}/review/dto/MyReviewItemDto.java | 2 +- .../review/dto/ReviewCreateRequest.java | 2 +- .../entity}/review/dto/ReviewResponse.java | 2 +- .../review/dto/StarSummaryResponse.java | 2 +- .../domain/entity/{ => user}/User.java | 3 +- .../domain/entity/{ => user}/UserFood.java | 3 +- .../domain/entity/{ => user}/UserMission.java | 3 +- .../domain/entity/{ => user}/UserTerm.java | 3 +- .../entity}/user/converter/UserConverter.java | 8 +-- .../entity}/user/dto/UserRequestDto.java | 2 +- .../entity}/user/dto/UserResponseDto.java | 2 +- .../repository/ReplyRepository.java | 4 +- .../repository/ReviewPhotoRepository.java | 4 +- .../repository/ReviewQueryRepository.java | 4 +- .../repository/ReviewQueryRepositoryImpl.java | 4 +- .../repository/ReviewRepository.java | 4 +- .../repository/StoreRepository.java | 2 +- .../repository/UserMissionRepository.java | 4 +- .../repository/UserRepository.java | 4 +- .../service/MyReviewQueryService.java | 6 +- .../review => service}/ReviewService.java | 11 +++- .../spring_boot_a/service/UserService.java | 14 +++++ .../service/UserServiceImpl.java | 39 ++++++++++++ 34 files changed, 188 insertions(+), 47 deletions(-) rename src/main/java/com/example/spring_boot_a/{api/review => controller}/MyReviewController.java (80%) rename src/main/java/com/example/spring_boot_a/{api/review => controller}/ReviewController.java (84%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => etc}/Food.java (82%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => etc}/Location.java (82%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => etc}/Mission.java (82%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => etc}/Reply.java (76%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => etc}/ReviewPhoto.java (77%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => review}/Review.java (76%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/review/dto/MyReviewItemDto.java (81%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/review/dto/ReviewCreateRequest.java (78%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/review/dto/ReviewResponse.java (81%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/review/dto/StarSummaryResponse.java (71%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => user}/User.java (95%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => user}/UserFood.java (81%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => user}/UserMission.java (83%) rename src/main/java/com/example/spring_boot_a/domain/entity/{ => user}/UserTerm.java (82%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/user/converter/UserConverter.java (88%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/user/dto/UserRequestDto.java (95%) rename src/main/java/com/example/spring_boot_a/{api => domain/entity}/user/dto/UserResponseDto.java (94%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/ReplyRepository.java (70%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/ReviewPhotoRepository.java (70%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/ReviewQueryRepository.java (71%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/ReviewQueryRepositoryImpl.java (97%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/ReviewRepository.java (92%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/StoreRepository.java (78%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/UserMissionRepository.java (86%) rename src/main/java/com/example/spring_boot_a/{domain => }/repository/UserRepository.java (55%) rename src/main/java/com/example/spring_boot_a/{domain => }/service/MyReviewQueryService.java (75%) rename src/main/java/com/example/spring_boot_a/{api/review => service}/ReviewService.java (89%) create mode 100644 src/main/java/com/example/spring_boot_a/service/UserService.java create mode 100644 src/main/java/com/example/spring_boot_a/service/UserServiceImpl.java diff --git a/src/main/java/com/example/spring_boot_a/api/review/MyReviewController.java b/src/main/java/com/example/spring_boot_a/controller/MyReviewController.java similarity index 80% rename from src/main/java/com/example/spring_boot_a/api/review/MyReviewController.java rename to src/main/java/com/example/spring_boot_a/controller/MyReviewController.java index c7e9219..202ab63 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/MyReviewController.java +++ b/src/main/java/com/example/spring_boot_a/controller/MyReviewController.java @@ -1,7 +1,7 @@ -package com.example.spring_boot_a.api.review; +package com.example.spring_boot_a.controller; -import com.example.spring_boot_a.api.review.dto.MyReviewItemDto; -import com.example.spring_boot_a.domain.service.MyReviewQueryService; +import com.example.spring_boot_a.domain.entity.review.dto.MyReviewItemDto; +import com.example.spring_boot_a.service.MyReviewQueryService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/example/spring_boot_a/api/review/ReviewController.java b/src/main/java/com/example/spring_boot_a/controller/ReviewController.java similarity index 84% rename from src/main/java/com/example/spring_boot_a/api/review/ReviewController.java rename to src/main/java/com/example/spring_boot_a/controller/ReviewController.java index 769fcc5..1cb0a83 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/ReviewController.java +++ b/src/main/java/com/example/spring_boot_a/controller/ReviewController.java @@ -1,6 +1,10 @@ -package com.example.spring_boot_a.api.review; +package com.example.spring_boot_a.controller; import com.example.spring_boot_a.api.review.dto.*; +import com.example.spring_boot_a.domain.entity.review.dto.ReviewCreateRequest; +import com.example.spring_boot_a.domain.entity.review.dto.ReviewResponse; +import com.example.spring_boot_a.domain.entity.review.dto.StarSummaryResponse; +import com.example.spring_boot_a.service.ReviewService; import jakarta.validation.Valid; import org.springframework.data.domain.*; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/example/spring_boot_a/controller/UserController.java b/src/main/java/com/example/spring_boot_a/controller/UserController.java index 7a25cb9..7f8b57d 100644 --- a/src/main/java/com/example/spring_boot_a/controller/UserController.java +++ b/src/main/java/com/example/spring_boot_a/controller/UserController.java @@ -1,4 +1,66 @@ package com.example.spring_boot_a.controller; +import com.example.spring_boot_a.domain.entity.user.converter.UserConverter; +import com.example.spring_boot_a.domain.entity.user.dto.UserRequestDto; +import com.example.spring_boot_a.domain.entity.user.dto.UserResponseDto; +import com.example.spring_boot_a.domain.entity.user.User; +import com.example.spring_boot_a.global.apiPayload.code.ApiResponse; +import com.example.spring_boot_a.global.apiPayload.code.GeneralSuccessCode; +import com.example.spring_boot_a.service.UserService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/users") public class UserController { + + private final UserService userService; + private final UserConverter userConverter; + + + @PostMapping + public ResponseEntity> createUser( + @Valid @RequestBody UserRequestDto.Create request + ) { + User user = userConverter.toUser(request); + + User saved = userService.createUser(user); + + UserResponseDto.CreateResult responseDTO = userConverter.toCreateResult(saved); + + return ResponseEntity + .status(GeneralSuccessCode.CREATED.getStatus()) + .body(ApiResponse.onSuccess(GeneralSuccessCode.CREATED, responseDTO)); + } + + + @GetMapping("/{userId}") + public ResponseEntity> getUser( + @PathVariable Long userId + ) { + User user = userService.getUser(userId); + + UserResponseDto.Detail dto = userConverter.toDetail(user); + + return ResponseEntity + .status(GeneralSuccessCode.OK.getStatus()) + .body(ApiResponse.onSuccess(GeneralSuccessCode.OK, dto)); + } + + + @GetMapping + public ResponseEntity>> getUsers() { + List users = userService.getUsers(); + + List dtos = userConverter.toSummaryList(users); + + return ResponseEntity + .status(GeneralSuccessCode.OK.getStatus()) + .body(ApiResponse.onSuccess(GeneralSuccessCode.OK, dtos)); + } } diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Store.java b/src/main/java/com/example/spring_boot_a/domain/entity/Store.java index 22eaeaa..0cc1c6f 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Store.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/Store.java @@ -1,5 +1,8 @@ package com.example.spring_boot_a.domain.entity; +import com.example.spring_boot_a.domain.entity.etc.Location; +import com.example.spring_boot_a.domain.entity.etc.Mission; +import com.example.spring_boot_a.domain.entity.review.Review; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Term.java b/src/main/java/com/example/spring_boot_a/domain/entity/Term.java index 67b0531..fb0b259 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Term.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/Term.java @@ -1,6 +1,7 @@ package com.example.spring_boot_a.domain.entity; import com.example.spring_boot_a.domain.entity.enums.TermType; +import com.example.spring_boot_a.domain.entity.user.UserTerm; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Food.java b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Food.java similarity index 82% rename from src/main/java/com/example/spring_boot_a/domain/entity/Food.java rename to src/main/java/com/example/spring_boot_a/domain/entity/etc/Food.java index 2d131bf..5d87461 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Food.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Food.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.etc; +import com.example.spring_boot_a.domain.entity.user.UserFood; import com.example.spring_boot_a.domain.entity.enums.FoodType; import jakarta.persistence.*; import lombok.Getter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Location.java b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Location.java similarity index 82% rename from src/main/java/com/example/spring_boot_a/domain/entity/Location.java rename to src/main/java/com/example/spring_boot_a/domain/entity/etc/Location.java index 115951e..3b14f94 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Location.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Location.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.etc; +import com.example.spring_boot_a.domain.entity.Store; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Mission.java b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Mission.java similarity index 82% rename from src/main/java/com/example/spring_boot_a/domain/entity/Mission.java rename to src/main/java/com/example/spring_boot_a/domain/entity/etc/Mission.java index ac50cea..9edeb46 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Mission.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Mission.java @@ -1,5 +1,7 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.etc; +import com.example.spring_boot_a.domain.entity.Store; +import com.example.spring_boot_a.domain.entity.user.UserMission; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Reply.java b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Reply.java similarity index 76% rename from src/main/java/com/example/spring_boot_a/domain/entity/Reply.java rename to src/main/java/com/example/spring_boot_a/domain/entity/etc/Reply.java index cbed38e..293b19f 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Reply.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/etc/Reply.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.etc; +import com.example.spring_boot_a.domain.entity.review.Review; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/ReviewPhoto.java b/src/main/java/com/example/spring_boot_a/domain/entity/etc/ReviewPhoto.java similarity index 77% rename from src/main/java/com/example/spring_boot_a/domain/entity/ReviewPhoto.java rename to src/main/java/com/example/spring_boot_a/domain/entity/etc/ReviewPhoto.java index 41a9357..7b2ab0a 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/ReviewPhoto.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/etc/ReviewPhoto.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.etc; +import com.example.spring_boot_a.domain.entity.review.Review; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/Review.java b/src/main/java/com/example/spring_boot_a/domain/entity/review/Review.java similarity index 76% rename from src/main/java/com/example/spring_boot_a/domain/entity/Review.java rename to src/main/java/com/example/spring_boot_a/domain/entity/review/Review.java index 1fdc96d..a97d69b 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/Review.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/review/Review.java @@ -1,5 +1,8 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.review; +import com.example.spring_boot_a.domain.entity.etc.ReviewPhoto; +import com.example.spring_boot_a.domain.entity.Store; +import com.example.spring_boot_a.domain.entity.etc.Reply; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; @@ -25,9 +28,7 @@ public class Review { @ManyToOne(optional = false) @JoinColumn(name = "store_id") private Store store; - @ManyToOne(optional = false) @JoinColumn(name = "user_id") - private User user; - + @JoinColumn(name = "user_id") @OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true) private Set photos = new HashSet<>(); diff --git a/src/main/java/com/example/spring_boot_a/api/review/dto/MyReviewItemDto.java b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/MyReviewItemDto.java similarity index 81% rename from src/main/java/com/example/spring_boot_a/api/review/dto/MyReviewItemDto.java rename to src/main/java/com/example/spring_boot_a/domain/entity/review/dto/MyReviewItemDto.java index 67d94db..17e9297 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/dto/MyReviewItemDto.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/MyReviewItemDto.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.review.dto; +package com.example.spring_boot_a.domain.entity.review.dto; import java.time.Instant; import java.util.List; diff --git a/src/main/java/com/example/spring_boot_a/api/review/dto/ReviewCreateRequest.java b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewCreateRequest.java similarity index 78% rename from src/main/java/com/example/spring_boot_a/api/review/dto/ReviewCreateRequest.java rename to src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewCreateRequest.java index bb6a044..79bbf9c 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/dto/ReviewCreateRequest.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewCreateRequest.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.review.dto; +package com.example.spring_boot_a.domain.entity.review.dto; import jakarta.validation.constraints.*; import java.util.List; diff --git a/src/main/java/com/example/spring_boot_a/api/review/dto/ReviewResponse.java b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewResponse.java similarity index 81% rename from src/main/java/com/example/spring_boot_a/api/review/dto/ReviewResponse.java rename to src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewResponse.java index e82f2ff..4ef4e3d 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/dto/ReviewResponse.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/ReviewResponse.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.review.dto; +package com.example.spring_boot_a.domain.entity.review.dto; import java.time.Instant; import java.util.List; diff --git a/src/main/java/com/example/spring_boot_a/api/review/dto/StarSummaryResponse.java b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/StarSummaryResponse.java similarity index 71% rename from src/main/java/com/example/spring_boot_a/api/review/dto/StarSummaryResponse.java rename to src/main/java/com/example/spring_boot_a/domain/entity/review/dto/StarSummaryResponse.java index e587991..8ce6151 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/dto/StarSummaryResponse.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/review/dto/StarSummaryResponse.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.review.dto; +package com.example.spring_boot_a.domain.entity.review.dto; public record StarSummaryResponse( long s5, diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/User.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/User.java similarity index 95% rename from src/main/java/com/example/spring_boot_a/domain/entity/User.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/User.java index dbdfce4..dca91ba 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/User.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/User.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.user; +import com.example.spring_boot_a.domain.entity.review.Review; import com.example.spring_boot_a.domain.entity.enums.AddressGu; import com.example.spring_boot_a.domain.entity.enums.Gender; import com.example.spring_boot_a.domain.entity.enums.SocialLoginType; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/UserFood.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserFood.java similarity index 81% rename from src/main/java/com/example/spring_boot_a/domain/entity/UserFood.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/UserFood.java index 2769156..c25ba2f 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/UserFood.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserFood.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.user; +import com.example.spring_boot_a.domain.entity.etc.Food; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/UserMission.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserMission.java similarity index 83% rename from src/main/java/com/example/spring_boot_a/domain/entity/UserMission.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/UserMission.java index a59f1a5..60caed3 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/UserMission.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserMission.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.user; +import com.example.spring_boot_a.domain.entity.etc.Mission; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/domain/entity/UserTerm.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserTerm.java similarity index 82% rename from src/main/java/com/example/spring_boot_a/domain/entity/UserTerm.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/UserTerm.java index 5872f66..7eb2fb8 100644 --- a/src/main/java/com/example/spring_boot_a/domain/entity/UserTerm.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/UserTerm.java @@ -1,5 +1,6 @@ -package com.example.spring_boot_a.domain.entity; +package com.example.spring_boot_a.domain.entity.user; +import com.example.spring_boot_a.domain.entity.Term; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/converter/UserConverter.java similarity index 88% rename from src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/converter/UserConverter.java index 6a3ae58..e4668e4 100644 --- a/src/main/java/com/example/spring_boot_a/api/user/converter/UserConverter.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/converter/UserConverter.java @@ -1,8 +1,8 @@ -package com.example.spring_boot_a.api.user.converter; +package com.example.spring_boot_a.domain.entity.user.converter; -import com.example.spring_boot_a.api.user.dto.UserRequestDto; -import com.example.spring_boot_a.api.user.dto.UserResponseDto; -import com.example.spring_boot_a.domain.entity.User; +import com.example.spring_boot_a.domain.entity.user.dto.UserRequestDto; +import com.example.spring_boot_a.domain.entity.user.dto.UserResponseDto; +import com.example.spring_boot_a.domain.entity.user.User; import org.springframework.stereotype.Component; import java.time.Instant; diff --git a/src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserRequestDto.java similarity index 95% rename from src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserRequestDto.java index c8887eb..e364bd2 100644 --- a/src/main/java/com/example/spring_boot_a/api/user/dto/UserRequestDto.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserRequestDto.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.user.dto; +package com.example.spring_boot_a.domain.entity.user.dto; import com.example.spring_boot_a.domain.entity.enums.AddressGu; import com.example.spring_boot_a.domain.entity.enums.Gender; diff --git a/src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java b/src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserResponseDto.java similarity index 94% rename from src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java rename to src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserResponseDto.java index 75fc818..bf30f61 100644 --- a/src/main/java/com/example/spring_boot_a/api/user/dto/UserResponseDto.java +++ b/src/main/java/com/example/spring_boot_a/domain/entity/user/dto/UserResponseDto.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.api.user.dto; +package com.example.spring_boot_a.domain.entity.user.dto; import com.example.spring_boot_a.domain.entity.enums.AddressGu; import com.example.spring_boot_a.domain.entity.enums.Gender; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/ReplyRepository.java b/src/main/java/com/example/spring_boot_a/repository/ReplyRepository.java similarity index 70% rename from src/main/java/com/example/spring_boot_a/domain/repository/ReplyRepository.java rename to src/main/java/com/example/spring_boot_a/repository/ReplyRepository.java index 839e751..1649a2a 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/ReplyRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/ReplyRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.domain.entity.Reply; +import com.example.spring_boot_a.domain.entity.etc.Reply; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Collection; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewPhotoRepository.java b/src/main/java/com/example/spring_boot_a/repository/ReviewPhotoRepository.java similarity index 70% rename from src/main/java/com/example/spring_boot_a/domain/repository/ReviewPhotoRepository.java rename to src/main/java/com/example/spring_boot_a/repository/ReviewPhotoRepository.java index 269afb0..b6cd176 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewPhotoRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/ReviewPhotoRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.domain.entity.ReviewPhoto; +import com.example.spring_boot_a.domain.entity.etc.ReviewPhoto; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Collection; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepository.java b/src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepository.java similarity index 71% rename from src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepository.java rename to src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepository.java index 1e0975e..6d8a710 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.api.review.dto.MyReviewItemDto; +import com.example.spring_boot_a.domain.entity.review.dto.MyReviewItemDto; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepositoryImpl.java b/src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepositoryImpl.java similarity index 97% rename from src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepositoryImpl.java rename to src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepositoryImpl.java index a38e806..745ea4c 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewQueryRepositoryImpl.java +++ b/src/main/java/com/example/spring_boot_a/repository/ReviewQueryRepositoryImpl.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.api.review.dto.MyReviewItemDto; +import com.example.spring_boot_a.domain.entity.review.dto.MyReviewItemDto; import com.example.spring_boot_a.domain.entity.QReply; import com.example.spring_boot_a.domain.entity.QReview; import com.example.spring_boot_a.domain.entity.QReviewPhoto; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewRepository.java b/src/main/java/com/example/spring_boot_a/repository/ReviewRepository.java similarity index 92% rename from src/main/java/com/example/spring_boot_a/domain/repository/ReviewRepository.java rename to src/main/java/com/example/spring_boot_a/repository/ReviewRepository.java index df6a600..4ad20a9 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/ReviewRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/ReviewRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.domain.entity.Review; +import com.example.spring_boot_a.domain.entity.review.Review; import org.springframework.data.domain.*; import org.springframework.data.jpa.repository.*; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/StoreRepository.java b/src/main/java/com/example/spring_boot_a/repository/StoreRepository.java similarity index 78% rename from src/main/java/com/example/spring_boot_a/domain/repository/StoreRepository.java rename to src/main/java/com/example/spring_boot_a/repository/StoreRepository.java index 324bb86..5debcd8 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/StoreRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/StoreRepository.java @@ -1,4 +1,4 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; import com.example.spring_boot_a.domain.entity.Store; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/UserMissionRepository.java b/src/main/java/com/example/spring_boot_a/repository/UserMissionRepository.java similarity index 86% rename from src/main/java/com/example/spring_boot_a/domain/repository/UserMissionRepository.java rename to src/main/java/com/example/spring_boot_a/repository/UserMissionRepository.java index 73b7b6b..e939f42 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/UserMissionRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/UserMissionRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.domain.entity.UserMission; +import com.example.spring_boot_a.domain.entity.user.UserMission; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/com/example/spring_boot_a/domain/repository/UserRepository.java b/src/main/java/com/example/spring_boot_a/repository/UserRepository.java similarity index 55% rename from src/main/java/com/example/spring_boot_a/domain/repository/UserRepository.java rename to src/main/java/com/example/spring_boot_a/repository/UserRepository.java index 83328ca..acfc985 100644 --- a/src/main/java/com/example/spring_boot_a/domain/repository/UserRepository.java +++ b/src/main/java/com/example/spring_boot_a/repository/UserRepository.java @@ -1,6 +1,6 @@ -package com.example.spring_boot_a.domain.repository; +package com.example.spring_boot_a.repository; -import com.example.spring_boot_a.domain.entity.User; +import com.example.spring_boot_a.domain.entity.user.User; import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository { diff --git a/src/main/java/com/example/spring_boot_a/domain/service/MyReviewQueryService.java b/src/main/java/com/example/spring_boot_a/service/MyReviewQueryService.java similarity index 75% rename from src/main/java/com/example/spring_boot_a/domain/service/MyReviewQueryService.java rename to src/main/java/com/example/spring_boot_a/service/MyReviewQueryService.java index b1d5aa0..7e9a6a8 100644 --- a/src/main/java/com/example/spring_boot_a/domain/service/MyReviewQueryService.java +++ b/src/main/java/com/example/spring_boot_a/service/MyReviewQueryService.java @@ -1,7 +1,7 @@ -package com.example.spring_boot_a.domain.service; +package com.example.spring_boot_a.service; -import com.example.spring_boot_a.api.review.dto.MyReviewItemDto; -import com.example.spring_boot_a.domain.repository.ReviewQueryRepository; +import com.example.spring_boot_a.domain.entity.review.dto.MyReviewItemDto; +import com.example.spring_boot_a.repository.ReviewQueryRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.*; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/example/spring_boot_a/api/review/ReviewService.java b/src/main/java/com/example/spring_boot_a/service/ReviewService.java similarity index 89% rename from src/main/java/com/example/spring_boot_a/api/review/ReviewService.java rename to src/main/java/com/example/spring_boot_a/service/ReviewService.java index fb4cb04..6d4bd17 100644 --- a/src/main/java/com/example/spring_boot_a/api/review/ReviewService.java +++ b/src/main/java/com/example/spring_boot_a/service/ReviewService.java @@ -1,8 +1,15 @@ -package com.example.spring_boot_a.api.review; +package com.example.spring_boot_a.service; import com.example.spring_boot_a.api.review.dto.*; import com.example.spring_boot_a.domain.entity.*; -import com.example.spring_boot_a.domain.repository.*; +import com.example.spring_boot_a.domain.entity.etc.Reply; +import com.example.spring_boot_a.domain.entity.etc.ReviewPhoto; +import com.example.spring_boot_a.domain.entity.review.Review; +import com.example.spring_boot_a.domain.entity.review.dto.ReviewCreateRequest; +import com.example.spring_boot_a.domain.entity.review.dto.ReviewResponse; +import com.example.spring_boot_a.domain.entity.review.dto.StarSummaryResponse; +import com.example.spring_boot_a.domain.entity.user.User; +import com.example.spring_boot_a.repository.*; import jakarta.persistence.EntityNotFoundException; import org.springframework.data.domain.*; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/example/spring_boot_a/service/UserService.java b/src/main/java/com/example/spring_boot_a/service/UserService.java new file mode 100644 index 0000000..95e2342 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/service/UserService.java @@ -0,0 +1,14 @@ +package com.example.spring_boot_a.service; + +import com.example.spring_boot_a.domain.entity.user.User; + +import java.util.List; + +public interface UserService { + + User createUser(User user); + + User getUser(Long userId); + + List getUsers(); +} diff --git a/src/main/java/com/example/spring_boot_a/service/UserServiceImpl.java b/src/main/java/com/example/spring_boot_a/service/UserServiceImpl.java new file mode 100644 index 0000000..ff0545c --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/service/UserServiceImpl.java @@ -0,0 +1,39 @@ +package com.example.spring_boot_a.service; + +import com.example.spring_boot_a.domain.entity.user.User; +import com.example.spring_boot_a.repository.UserRepository; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + + + @Override + @Transactional + public User createUser(User user) { + return userRepository.save(user); + } + + + @Override + public User getUser(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> + new EntityNotFoundException("User not found. id=" + userId)); + } + + + @Override + public List getUsers() { + return userRepository.findAll(); + } +} From c76702bbb45b0aa890a1d386bb3e9a322728688f Mon Sep 17 00:00:00 2001 From: dongchan0105 Date: Tue, 11 Nov 2025 20:22:45 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E2=9C=85=20CustomException=EA=B3=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=A5=BC=20=ED=8F=AC=ED=95=A8=ED=95=9C=20=EC=9D=BC?= =?UTF-8?q?=EB=B0=98=EC=A0=81=EC=9D=B8=20=EC=98=88=EC=99=B8=EB=A5=BC=20?= =?UTF-8?q?=EA=B3=B5=ED=86=B5=EC=9C=BC=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EB=8A=94=20GlobalExcetpionHandler=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/GeneralErrorCode.java | 3 + .../global/exception/CustomException.java | 15 ++++ .../exception/GlobalExceptionHandler.java | 84 +++++++++++++++++++ .../spring_boot_a/service/ReviewService.java | 2 - 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/spring_boot_a/global/exception/CustomException.java create mode 100644 src/main/java/com/example/spring_boot_a/global/exception/GlobalExceptionHandler.java diff --git a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java index 02f168d..4ce41a5 100644 --- a/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java +++ b/src/main/java/com/example/spring_boot_a/global/apiPayload/code/GeneralErrorCode.java @@ -20,6 +20,9 @@ public enum GeneralErrorCode implements BaseErrorCode { NOT_FOUND(HttpStatus.NOT_FOUND, "COMMON404_1", "요청한 리소스를 찾을 수 없습니다."), + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, + "COMMON500_1" + ,"서버 에러입니다.") ; private final HttpStatus status; diff --git a/src/main/java/com/example/spring_boot_a/global/exception/CustomException.java b/src/main/java/com/example/spring_boot_a/global/exception/CustomException.java new file mode 100644 index 0000000..fd865b3 --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/exception/CustomException.java @@ -0,0 +1,15 @@ +package com.example.spring_boot_a.global.exception; + +import com.example.spring_boot_a.global.apiPayload.code.BaseErrorCode; +import lombok.Getter; + +@Getter +public class CustomException extends RuntimeException{ + + private final BaseErrorCode errorCode; + + public CustomException(BaseErrorCode errorCode){ + super(errorCode.getMessage()); + this.errorCode = errorCode; + } +} diff --git a/src/main/java/com/example/spring_boot_a/global/exception/GlobalExceptionHandler.java b/src/main/java/com/example/spring_boot_a/global/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..71d28ff --- /dev/null +++ b/src/main/java/com/example/spring_boot_a/global/exception/GlobalExceptionHandler.java @@ -0,0 +1,84 @@ +package com.example.spring_boot_a.global.exception; + +import com.example.spring_boot_a.global.apiPayload.code.ApiResponse; +import com.example.spring_boot_a.global.apiPayload.code.BaseErrorCode; +import com.example.spring_boot_a.global.apiPayload.code.GeneralErrorCode; +import jakarta.persistence.EntityNotFoundException; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + + @ExceptionHandler(CustomException.class) + public ResponseEntity> handleCustomException(CustomException e) { + BaseErrorCode errorCode = e.getErrorCode(); + + ApiResponse body = ApiResponse.onFailure(errorCode); + + return ResponseEntity + .status(errorCode.getStatus()) + .body(body); + } + + + @ExceptionHandler(EntityNotFoundException.class) + public ResponseEntity> handleEntityNotFound(EntityNotFoundException e) { + + ApiResponse body = ApiResponse.onFailure( + GeneralErrorCode.NOT_FOUND, + e.getMessage() // result에 상세 메시지를 실어 줄 수 있음 + ); + + return ResponseEntity + .status(GeneralErrorCode.NOT_FOUND.getStatus()) + .body(body); + } + + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidation(MethodArgumentNotValidException e) { + String msg = e.getBindingResult().getAllErrors().get(0).getDefaultMessage(); + + ApiResponse body = ApiResponse.onFailure( + GeneralErrorCode.BAD_REQUEST, + msg // result에 검증 실패 메시지 + ); + + return ResponseEntity + .status(GeneralErrorCode.BAD_REQUEST.getStatus()) + .body(body); + } + + + @ExceptionHandler(DataIntegrityViolationException.class) + public ResponseEntity> handleIntegrity(DataIntegrityViolationException e) { + + ApiResponse body = ApiResponse.onFailure( + GeneralErrorCode.BAD_REQUEST, + "데이터 제약 조건 위반(중복 등)" + ); + + return ResponseEntity + .status(GeneralErrorCode.BAD_REQUEST.getStatus()) + .body(body); + } + + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception e) { + + ApiResponse body = ApiResponse.onFailure( + GeneralErrorCode.INTERNAL_SERVER_ERROR, + e.getMessage() + ); + + return ResponseEntity + .status(GeneralErrorCode.INTERNAL_SERVER_ERROR.getStatus()) + .body(body); + } +} diff --git a/src/main/java/com/example/spring_boot_a/service/ReviewService.java b/src/main/java/com/example/spring_boot_a/service/ReviewService.java index 6d4bd17..1e9f2a4 100644 --- a/src/main/java/com/example/spring_boot_a/service/ReviewService.java +++ b/src/main/java/com/example/spring_boot_a/service/ReviewService.java @@ -1,6 +1,5 @@ package com.example.spring_boot_a.service; -import com.example.spring_boot_a.api.review.dto.*; import com.example.spring_boot_a.domain.entity.*; import com.example.spring_boot_a.domain.entity.etc.Reply; import com.example.spring_boot_a.domain.entity.etc.ReviewPhoto; @@ -47,7 +46,6 @@ public Long create(Long userId, Long storeId, ReviewCreateRequest req) { .orElseThrow(() -> new EntityNotFoundException("store not found")); Review r = new Review(); - r.setUser(user); r.setStore(store); r.setStar(req.star()); r.setContent(req.content());