From 670a14e939ee9e42325b6a5167c73a4fc983456a Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 03:06:13 +0900 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../off/memoir/controller/MemoirController.java | 12 ++++++------ .../domain/off/memoir/dto/MemoirRequestDTO.java | 2 -- .../domain/off/memoir/service/MemoirService.java | 7 ++----- .../domain/off/memoir/service/MemoirServiceImpl.java | 11 +++++------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index e66cda4..3465350 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -22,9 +22,9 @@ public class MemoirController { private final MemoirService memoirService; @GetMapping("/memoir-questions") - @Operation(summary = "회고 질문 조회 API",description = "회고 질문 목록을 조회하는 API입니다. Query String으로 사용자 아이디를 입력해 주세요.") - public ApiResponse> getMemoirQuestion(@RequestParam(name = "userId") Long userId){ - List memoirQuestionList = memoirService.getMemoirQuestion(userId); + @Operation(summary = "회고 질문 조회 API",description = "회고 질문 목록을 조회하는 API입니다.") + public ApiResponse> getMemoirQuestion(){ + List memoirQuestionList = memoirService.getMemoirQuestion(); return ApiResponse.onSuccess(MemoirConverter.toQuestionResultDTOList(memoirQuestionList)); } @@ -36,9 +36,9 @@ public ApiResponse writeMemoir(@RequestBody @Valid } @GetMapping("/memoirs") - @Operation(summary = "회고 조회 API",description = "특정한 날짜의 회고를 조회하는 API입니다. Query String으로 사용자 아이디와 날짜를 입력해 주세요.") - public ApiResponse writeMemoir(@RequestParam(name = "userId") Long userId, @RequestParam(name = "date") LocalDate date){ - Memoir memoir = memoirService.getMemoir(userId, date); + @Operation(summary = "회고 조회 API",description = "특정한 날짜의 회고를 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") + public ApiResponse getMemoir(@RequestParam(name = "date") LocalDate date){ + Memoir memoir = memoirService.getMemoir(date); if (memoir == null) { return ApiResponse.onSuccess(null); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index c0a2438..8eee7f7 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -11,8 +11,6 @@ public class MemoirRequestDTO { @Getter public static class WriteDTO { - @NotNull - Long userId; @NotNull LocalDate date; @Size(max = 255) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 0466a19..c41d583 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -9,16 +9,13 @@ import java.util.List; public interface MemoirService { - List getMemoirQuestion(Long userId); + List getMemoirQuestion(); - @Transactional Memoir writeMemoir(MemoirRequestDTO.WriteDTO request); - Memoir getMemoir(Long userId, LocalDate date); + Memoir getMemoir(LocalDate date); - @Transactional Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request); - @Transactional Memoir deleteMemoir(Long memoirId); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index eade991..0fe079c 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -2,6 +2,7 @@ import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; import com.onnoff.onnoff.apiPayload.exception.GeneralException; +import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.off.memoir.converter.MemoirConverter; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; @@ -29,18 +30,16 @@ public class MemoirServiceImpl implements MemoirService { private final MemoirAnswerRepository memoirAnswerRepository; private final MemoirQuestionRepository memoirQuestionRepository; - private final UserRepository userRepository; - @Override @Transactional(readOnly = true) - public List getMemoirQuestion(Long userId) { + public List getMemoirQuestion() { return memoirQuestionRepository.findAll(); } @Override @Transactional public Memoir writeMemoir(MemoirRequestDTO.WriteDTO request) { - User user = userRepository.findById(request.getUserId()).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + User user = UserContext.getUser(); if (memoirRepository.findByUserAndDate(user, request.getDate()).isPresent()) { throw new GeneralException(ErrorStatus.MEMOIR_EXIST); } @@ -63,8 +62,8 @@ public Memoir writeMemoir(MemoirRequestDTO.WriteDTO request) { @Override @Transactional(readOnly = true) - public Memoir getMemoir(Long userId, LocalDate date) { - User user = userRepository.findById(userId).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + public Memoir getMemoir(LocalDate date) { + User user = UserContext.getUser(); return memoirRepository.findByUserAndDate(user, date).orElse(null); } From bd85e92523ddc4831d56f8982c87b375ebb7f185 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 03:08:07 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20=ED=9A=8C=EA=B3=A0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=9D=91=EB=8B=B5=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/off/memoir/controller/MemoirController.java | 5 ++--- .../onnoff/domain/off/memoir/service/MemoirService.java | 2 +- .../onnoff/domain/off/memoir/service/MemoirServiceImpl.java | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 3465350..bddeb04 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -55,8 +55,7 @@ public ApiResponse updateMemoir(@RequestBody @Valid @DeleteMapping("/memoirs/{memoirId}") @Operation(summary = "회고 삭제 API",description = "기존의 회고를 삭제하는 API입니다.") - public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId){ - Memoir memoir = memoirService.deleteMemoir(memoirId); - return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); + public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId){ + return ApiResponse.onSuccess(memoirService.deleteMemoir(memoirId)); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index c41d583..66392cc 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -17,5 +17,5 @@ public interface MemoirService { Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request); - Memoir deleteMemoir(Long memoirId); + Long deleteMemoir(Long memoirId); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 0fe079c..ea7f278 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -95,9 +95,9 @@ public Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request) { @Override @Transactional - public Memoir deleteMemoir(Long memoirId) { + public Long deleteMemoir(Long memoirId) { Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); memoirRepository.delete(memoir); - return memoir; + return memoir.getId(); } } From 1af8616bd4473a6dda6abf3b51e4434ce971952d Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 03:13:58 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20=ED=9A=8C=EA=B3=A0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=9A=94=EC=B2=AD=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../off/memoir/controller/MemoirController.java | 12 ++++-------- .../domain/off/memoir/service/MemoirService.java | 2 +- .../domain/off/memoir/service/MemoirServiceImpl.java | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index bddeb04..1e399db 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -35,14 +35,10 @@ public ApiResponse writeMemoir(@RequestBody @Valid return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); } - @GetMapping("/memoirs") - @Operation(summary = "회고 조회 API",description = "특정한 날짜의 회고를 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") - public ApiResponse getMemoir(@RequestParam(name = "date") LocalDate date){ - Memoir memoir = memoirService.getMemoir(date); - - if (memoir == null) { - return ApiResponse.onSuccess(null); - } + @GetMapping("/memoirs/{memoirId}") + @Operation(summary = "회고 조회 API",description = "특정 회고를 조회하는 API입니다.") + public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId){ + Memoir memoir = memoirService.getMemoir(memoirId); return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 66392cc..5f409e5 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -13,7 +13,7 @@ public interface MemoirService { Memoir writeMemoir(MemoirRequestDTO.WriteDTO request); - Memoir getMemoir(LocalDate date); + Memoir getMemoir(Long memoirId); Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index ea7f278..ce3e835 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -62,9 +62,8 @@ public Memoir writeMemoir(MemoirRequestDTO.WriteDTO request) { @Override @Transactional(readOnly = true) - public Memoir getMemoir(LocalDate date) { - User user = UserContext.getUser(); - return memoirRepository.findByUserAndDate(user, date).orElse(null); + public Memoir getMemoir(Long memoirId) { + return memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); } @Override From 1e74f2727cca5e0be242b872a60a70212831d316 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 03:21:15 +0900 Subject: [PATCH 04/14] =?UTF-8?q?rename:=20DTO=EB=AA=85=20=EA=B5=AC?= =?UTF-8?q?=EC=B2=B4=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../off/memoir/controller/MemoirController.java | 16 ++++++++-------- .../off/memoir/converter/MemoirConverter.java | 16 ++++++++-------- .../domain/off/memoir/dto/MemoirRequestDTO.java | 12 ++++++------ .../domain/off/memoir/dto/MemoirResponseDTO.java | 8 ++++---- .../domain/off/memoir/service/MemoirService.java | 4 ++-- .../off/memoir/service/MemoirServiceImpl.java | 8 ++++---- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 1e399db..4adbd15 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -23,30 +23,30 @@ public class MemoirController { @GetMapping("/memoir-questions") @Operation(summary = "회고 질문 조회 API",description = "회고 질문 목록을 조회하는 API입니다.") - public ApiResponse> getMemoirQuestion(){ + public ApiResponse> getMemoirQuestion(){ List memoirQuestionList = memoirService.getMemoirQuestion(); - return ApiResponse.onSuccess(MemoirConverter.toQuestionResultDTOList(memoirQuestionList)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionResultDTOList(memoirQuestionList)); } @PostMapping("/memoirs") @Operation(summary = "회고 작성 API",description = "새로운 회고를 작성하는 API입니다.") - public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.WriteDTO request){ + public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request){ Memoir memoir = memoirService.writeMemoir(request); - return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } @GetMapping("/memoirs/{memoirId}") @Operation(summary = "회고 조회 API",description = "특정 회고를 조회하는 API입니다.") - public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId){ + public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId){ Memoir memoir = memoirService.getMemoir(memoirId); - return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } @PatchMapping("/memoirs") @Operation(summary = "회고 수정 API",description = "기존의 회고를 수정하는 API입니다.") - public ApiResponse updateMemoir(@RequestBody @Valid MemoirRequestDTO.UpdateDTO request){ + public ApiResponse updateMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirUpdateDTO request){ Memoir memoir = memoirService.updateMemoir(request); - return ApiResponse.onSuccess(MemoirConverter.toResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } @DeleteMapping("/memoirs/{memoirId}") diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 10fb0d6..0041fe3 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -11,9 +11,9 @@ public class MemoirConverter { - public static List toQuestionResultDTOList(List memoirQuestionList) { + public static List toMemoirQuestionResultDTOList(List memoirQuestionList) { return memoirQuestionList.stream() - .map(x -> MemoirResponseDTO.QuestionResultDTO.builder() + .map(x -> MemoirResponseDTO.MemoirQuestionResultDTO.builder() .questionId(x.getId()) .question(x.getQuestion()) .summary(x.getSummary()) @@ -21,7 +21,7 @@ public static List toQuestionResultDTOList( .collect(Collectors.toList()); } - public static Memoir toMemoir(MemoirRequestDTO.WriteDTO request) { + public static Memoir toMemoir(MemoirRequestDTO.MemoirWriteDTO request) { return Memoir.builder() .date(request.getDate()) .icon(request.getIcon()) @@ -29,19 +29,19 @@ public static Memoir toMemoir(MemoirRequestDTO.WriteDTO request) { .build(); } - public static MemoirResponseDTO.ResultDTO toResultDTO(Memoir memoir) { - return MemoirResponseDTO.ResultDTO.builder() + public static MemoirResponseDTO.MemoirResultDTO toMemoirResultDTO(Memoir memoir) { + return MemoirResponseDTO.MemoirResultDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) .icon(memoir.getIcon()) .isBookmarked(memoir.getIsBookmarked()) - .memoirAnswerList(toAnswerResultDTOList(memoir.getMemoirAnswerList())) + .memoirAnswerList(toMemoirAnswerResultDTOList(memoir.getMemoirAnswerList())) .build(); } - public static List toAnswerResultDTOList(List memoirAnswerList) { + public static List toMemoirAnswerResultDTOList(List memoirAnswerList) { return memoirAnswerList.stream() - .map(memoirAnswer -> MemoirResponseDTO.AnswerResultDTO.builder() + .map(memoirAnswer -> MemoirResponseDTO.MemoirAnswerResultDTO.builder() .answerId(memoirAnswer.getId()) .question(memoirAnswer.getMemoirQuestion().getQuestion()) .summary(memoirAnswer.getMemoirQuestion().getSummary()) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index 8eee7f7..82bc182 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -10,17 +10,17 @@ public class MemoirRequestDTO { @Getter - public static class WriteDTO { + public static class MemoirWriteDTO { @NotNull LocalDate date; @Size(max = 255) String icon; @NotEmpty - List<@Valid WriteAnswerDTO> memoirAnswerList; + List<@Valid MemoirWriteAnswerDTO> memoirAnswerList; } @Getter - public static class WriteAnswerDTO { + public static class MemoirWriteAnswerDTO { @NotNull Long questionId; @Size(max = 500) @@ -28,17 +28,17 @@ public static class WriteAnswerDTO { } @Getter - public static class UpdateDTO { + public static class MemoirUpdateDTO { @NotNull Long memoirId; @Size(max = 255) String icon; Boolean isBookmarked; - List<@Valid UpdateAnswerDTO> memoirAnswerList; + List<@Valid MemoirUpdateAnswerDTO> memoirAnswerList; } @Getter - public static class UpdateAnswerDTO { + public static class MemoirUpdateAnswerDTO { @NotNull Long answerId; @Size(max = 500) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index 4d41e90..6af2429 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -14,7 +14,7 @@ public class MemoirResponseDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class QuestionResultDTO{ + public static class MemoirQuestionResultDTO{ Long questionId; String question; String summary; @@ -24,19 +24,19 @@ public static class QuestionResultDTO{ @Getter @NoArgsConstructor @AllArgsConstructor - public static class ResultDTO { + public static class MemoirResultDTO { Long memoirId; LocalDate date; String icon; Boolean isBookmarked; - List memoirAnswerList; + List memoirAnswerList; } @Builder @Getter @NoArgsConstructor @AllArgsConstructor - public static class AnswerResultDTO{ + public static class MemoirAnswerResultDTO{ Long answerId; String question; String summary; diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 5f409e5..b55800d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -11,11 +11,11 @@ public interface MemoirService { List getMemoirQuestion(); - Memoir writeMemoir(MemoirRequestDTO.WriteDTO request); + Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request); Memoir getMemoir(Long memoirId); - Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request); + Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request); Long deleteMemoir(Long memoirId); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index ce3e835..647e712 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -38,7 +38,7 @@ public List getMemoirQuestion() { @Override @Transactional - public Memoir writeMemoir(MemoirRequestDTO.WriteDTO request) { + public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { User user = UserContext.getUser(); if (memoirRepository.findByUserAndDate(user, request.getDate()).isPresent()) { throw new GeneralException(ErrorStatus.MEMOIR_EXIST); @@ -68,7 +68,7 @@ public Memoir getMemoir(Long memoirId) { @Override @Transactional - public Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request) { + public Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request) { Memoir memoir = memoirRepository.findById(request.getMemoirId()).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); if (request.getIcon() != null) { @@ -79,9 +79,9 @@ public Memoir updateMemoir(MemoirRequestDTO.UpdateDTO request) { memoir.setIsBookmarked(request.getIsBookmarked()); } - List requestMemoirAnswerList = request.getMemoirAnswerList() == null ? new ArrayList<>() : request.getMemoirAnswerList(); + List requestMemoirAnswerList = request.getMemoirAnswerList() == null ? new ArrayList<>() : request.getMemoirAnswerList(); - for (MemoirRequestDTO.UpdateAnswerDTO memoirAnswer: requestMemoirAnswerList) { + for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer: requestMemoirAnswerList) { MemoirAnswer findMemoirAnswer = memoirAnswerRepository.findById(memoirAnswer.getAnswerId()).orElseThrow(() -> new GeneralException(ErrorStatus.ANSWER_NOT_FOUND)); if (findMemoirAnswer.getMemoir() != memoir) { throw new GeneralException(ErrorStatus.ANSWER_BAD_MATCH); From 4a502e28aacd6842a7f6a8ca589cc9fe606c512b Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 03:55:16 +0900 Subject: [PATCH 05/14] =?UTF-8?q?feat:=20=EC=88=98=EC=A0=95=20API=20?= =?UTF-8?q?=EC=84=B8=EB=B6=84=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memoir/controller/MemoirController.java | 32 ++++++++++++------- .../off/memoir/dto/MemoirRequestDTO.java | 3 -- .../off/memoir/service/MemoirService.java | 4 ++- .../off/memoir/service/MemoirServiceImpl.java | 29 +++++++++-------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 4adbd15..62a4145 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -22,36 +22,44 @@ public class MemoirController { private final MemoirService memoirService; @GetMapping("/memoir-questions") - @Operation(summary = "회고 질문 조회 API",description = "회고 질문 목록을 조회하는 API입니다.") - public ApiResponse> getMemoirQuestion(){ + @Operation(summary = "회고 질문 조회 API", description = "회고 질문 목록을 조회하는 API입니다.") + public ApiResponse> getMemoirQuestion() { List memoirQuestionList = memoirService.getMemoirQuestion(); return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionResultDTOList(memoirQuestionList)); } @PostMapping("/memoirs") - @Operation(summary = "회고 작성 API",description = "새로운 회고를 작성하는 API입니다.") - public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request){ + @Operation(summary = "회고 작성 API", description = "새로운 회고를 작성하는 API입니다.") + public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request) { Memoir memoir = memoirService.writeMemoir(request); return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } @GetMapping("/memoirs/{memoirId}") - @Operation(summary = "회고 조회 API",description = "특정 회고를 조회하는 API입니다.") - public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId){ + @Operation(summary = "회고 조회 API", description = "특정 회고를 조회하는 API입니다.") + public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId) { Memoir memoir = memoirService.getMemoir(memoirId); return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } - @PatchMapping("/memoirs") - @Operation(summary = "회고 수정 API",description = "기존의 회고를 수정하는 API입니다.") - public ApiResponse updateMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirUpdateDTO request){ - Memoir memoir = memoirService.updateMemoir(request); + @PatchMapping("/memoirs/{memoirId}") + @Operation(summary = "회고 내용 수정 API", description = "기존의 회고 내용을 수정하는 API입니다.") + public ApiResponse modifyMemoir(@PathVariable(name = "memoirId") Long memoirId, + @RequestBody @Valid MemoirRequestDTO.MemoirUpdateDTO request) { + Memoir memoir = memoirService.modifyMemoir(memoirId, request); + return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); + } + + @PatchMapping("/memoirs/{memoirId}/bookmark") + @Operation(summary = "회고 북마크 및 해제 API", description = "회고를 북마크하거나 북마크 해제하는 API입니다.") + public ApiResponse bookmarkMemoir(@PathVariable(name = "memoirId") Long memoirId) { + Memoir memoir = memoirService.bookmarkMemoir(memoirId); return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } @DeleteMapping("/memoirs/{memoirId}") - @Operation(summary = "회고 삭제 API",description = "기존의 회고를 삭제하는 API입니다.") - public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId){ + @Operation(summary = "회고 삭제 API", description = "기존의 회고를 삭제하는 API입니다.") + public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId) { return ApiResponse.onSuccess(memoirService.deleteMemoir(memoirId)); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index 82bc182..9ae1e0c 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -29,11 +29,8 @@ public static class MemoirWriteAnswerDTO { @Getter public static class MemoirUpdateDTO { - @NotNull - Long memoirId; @Size(max = 255) String icon; - Boolean isBookmarked; List<@Valid MemoirUpdateAnswerDTO> memoirAnswerList; } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index b55800d..721ff9e 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -15,7 +15,9 @@ public interface MemoirService { Memoir getMemoir(Long memoirId); - Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request); + Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request); + + Memoir bookmarkMemoir(Long memoirId); Long deleteMemoir(Long memoirId); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 647e712..60d8dd6 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -12,12 +12,10 @@ import com.onnoff.onnoff.domain.off.memoir.repository.MemoirQuestionRepository; import com.onnoff.onnoff.domain.off.memoir.repository.MemoirRepository; import com.onnoff.onnoff.domain.user.User; -import com.onnoff.onnoff.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -68,20 +66,13 @@ public Memoir getMemoir(Long memoirId) { @Override @Transactional - public Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request) { - Memoir memoir = memoirRepository.findById(request.getMemoirId()).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); - - if (request.getIcon() != null) { - memoir.setIcon(request.getIcon()); - } - - if (request.getIsBookmarked() != null) { - memoir.setIsBookmarked(request.getIsBookmarked()); - } + public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request) { + Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + memoir.setIcon(request.getIcon()); List requestMemoirAnswerList = request.getMemoirAnswerList() == null ? new ArrayList<>() : request.getMemoirAnswerList(); - for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer: requestMemoirAnswerList) { + for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer : requestMemoirAnswerList) { MemoirAnswer findMemoirAnswer = memoirAnswerRepository.findById(memoirAnswer.getAnswerId()).orElseThrow(() -> new GeneralException(ErrorStatus.ANSWER_NOT_FOUND)); if (findMemoirAnswer.getMemoir() != memoir) { throw new GeneralException(ErrorStatus.ANSWER_BAD_MATCH); @@ -89,7 +80,16 @@ public Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request) { findMemoirAnswer.setAnswer(memoirAnswer.getAnswer()); } - return memoirRepository.save(memoir); + return memoir; + } + + @Override + @Transactional + public Memoir bookmarkMemoir(Long memoirId) { + Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + memoir.setIsBookmarked(memoir.getIsBookmarked().equals(false)); + + return memoir; } @Override @@ -97,6 +97,7 @@ public Memoir updateMemoir(MemoirRequestDTO.MemoirUpdateDTO request) { public Long deleteMemoir(Long memoirId) { Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); memoirRepository.delete(memoir); + return memoir.getId(); } } From afa18eceb4e23d7260011915641b5e60ae57f58c Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 04:15:35 +0900 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20=ED=9A=8C=EA=B3=A0=20=EB=AF=B8?= =?UTF-8?q?=EB=A6=AC=EB=B3=B4=EA=B8=B0=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../off/memoir/controller/MemoirController.java | 7 +++++++ .../off/memoir/converter/MemoirConverter.java | 16 ++++++++++++++++ .../domain/off/memoir/dto/MemoirResponseDTO.java | 13 +++++++++++-- .../domain/off/memoir/service/MemoirService.java | 2 ++ .../off/memoir/service/MemoirServiceImpl.java | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 62a4145..762ec6a 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -35,6 +35,13 @@ public ApiResponse writeMemoir(@RequestBody @ return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } + @GetMapping("/memoirs/preview") + @Operation(summary = "회고 미리보기 조회 API", description = "특정 날짜의 회고 미리보기를 조회하는 API입니다.") + public ApiResponse getMemoirPreview(@RequestParam(name = "date") LocalDate date) { + Memoir memoir = memoirService.getMemoirPreview(date); + return ApiResponse.onSuccess(MemoirConverter.toMemoirPreviewResultDTO(memoir)); + } + @GetMapping("/memoirs/{memoirId}") @Operation(summary = "회고 조회 API", description = "특정 회고를 조회하는 API입니다.") public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId) { diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 0041fe3..a9442c4 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -1,5 +1,6 @@ package com.onnoff.onnoff.domain.off.memoir.converter; +import com.onnoff.onnoff.apiPayload.ApiResponse; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirResponseDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; @@ -29,6 +30,20 @@ public static Memoir toMemoir(MemoirRequestDTO.MemoirWriteDTO request) { .build(); } + public static MemoirResponseDTO.MemoirPreviewResultDTO toMemoirPreviewResultDTO(Memoir memoir) { + if (memoir == null) { + return MemoirResponseDTO.MemoirPreviewResultDTO.builder() + .memoirId(null) + .written(false) + .build(); + } else { + return MemoirResponseDTO.MemoirPreviewResultDTO.builder() + .memoirId(memoir.getId()) + .written(true) + .build(); + } + } + public static MemoirResponseDTO.MemoirResultDTO toMemoirResultDTO(Memoir memoir) { return MemoirResponseDTO.MemoirResultDTO.builder() .memoirId(memoir.getId()) @@ -49,4 +64,5 @@ public static List toMemoirAnswerResult .build()) .collect(Collectors.toList()); } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index 6af2429..5f34cd4 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -14,7 +14,7 @@ public class MemoirResponseDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirQuestionResultDTO{ + public static class MemoirQuestionResultDTO { Long questionId; String question; String summary; @@ -36,11 +36,20 @@ public static class MemoirResultDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirAnswerResultDTO{ + public static class MemoirAnswerResultDTO { Long answerId; String question; String summary; String answer; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class MemoirPreviewResultDTO { + Boolean written; + Long memoirId; + } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 721ff9e..5d8cf28 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -13,6 +13,8 @@ public interface MemoirService { Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request); + Memoir getMemoirPreview(LocalDate date); + Memoir getMemoir(Long memoirId); Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 60d8dd6..5c7bd24 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -58,6 +59,13 @@ public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { return memoirRepository.save(newMemoir); } + @Override + @Transactional(readOnly = true) + public Memoir getMemoirPreview(LocalDate date) { + User user = UserContext.getUser(); + return memoirRepository.findByUserAndDate(user, date).orElse(null); + } + @Override @Transactional(readOnly = true) public Memoir getMemoir(Long memoirId) { From 6f25ef45c7a559d3f51e08e3d9396a62d7e395b1 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 13:37:18 +0900 Subject: [PATCH 07/14] =?UTF-8?q?feat:=20=EB=B6=81=EB=A7=88=ED=81=AC=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../off/memoir/controller/MemoirController.java | 9 ++++++++- .../off/memoir/converter/MemoirConverter.java | 14 ++++++++++++++ .../domain/off/memoir/dto/MemoirResponseDTO.java | 11 +++++++++++ .../off/memoir/repository/MemoirRepository.java | 3 +++ .../domain/off/memoir/service/MemoirService.java | 2 ++ .../off/memoir/service/MemoirServiceImpl.java | 7 +++++++ 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 762ec6a..09afeb2 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -35,7 +35,7 @@ public ApiResponse writeMemoir(@RequestBody @ return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } - @GetMapping("/memoirs/preview") + @GetMapping("/memoirs/previews") @Operation(summary = "회고 미리보기 조회 API", description = "특정 날짜의 회고 미리보기를 조회하는 API입니다.") public ApiResponse getMemoirPreview(@RequestParam(name = "date") LocalDate date) { Memoir memoir = memoirService.getMemoirPreview(date); @@ -49,6 +49,13 @@ public ApiResponse getMemoir(@PathVariable(na return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); } + @GetMapping("/memoirs/bookmarks") + @Operation(summary = "북마크 회고 조회 API", description = "북마크 상태의 회고를 조회하는 API입니다.") + public ApiResponse> getBookmarkedMemoir() { + List memoirList = memoirService.getBookmarkedMemoir(); + return ApiResponse.onSuccess(MemoirConverter.toBookmarkedMemoirResultDTOList(memoirList)); + } + @PatchMapping("/memoirs/{memoirId}") @Operation(summary = "회고 내용 수정 API", description = "기존의 회고 내용을 수정하는 API입니다.") public ApiResponse modifyMemoir(@PathVariable(name = "memoirId") Long memoirId, diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index a9442c4..4383d34 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -8,6 +8,7 @@ import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; public class MemoirConverter { @@ -65,4 +66,17 @@ public static List toMemoirAnswerResult .collect(Collectors.toList()); } + public static List toBookmarkedMemoirResultDTOList(List memoirList) { + AtomicInteger index = new AtomicInteger(); + + return memoirList.stream() + .map(memoir -> MemoirResponseDTO.BookmarkedMemoirResultDTO.builder() + .memoirId(memoir.getId()) + .date(memoir.getDate()) + .icon(memoir.getIcon()) + .remain(index.getAndIncrement() % 2) + .build()) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index 5f34cd4..9a93727 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -52,4 +52,15 @@ public static class MemoirPreviewResultDTO { Long memoirId; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class BookmarkedMemoirResultDTO { + Long memoirId; + LocalDate date; + String icon; + Integer remain; + } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java index 38bbd69..f211a92 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java @@ -5,9 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDate; +import java.util.List; import java.util.Optional; public interface MemoirRepository extends JpaRepository { Optional findByUserAndDate(User user, LocalDate date); + + List findByUserAndIsBookmarkedOrderByDateDesc(User user, Boolean isBookmarked); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 5d8cf28..5ff40e8 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -17,6 +17,8 @@ public interface MemoirService { Memoir getMemoir(Long memoirId); + List getBookmarkedMemoir(); + Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request); Memoir bookmarkMemoir(Long memoirId); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 5c7bd24..d03a305 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -72,6 +72,13 @@ public Memoir getMemoir(Long memoirId) { return memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); } + @Override + @Transactional(readOnly = true) + public List getBookmarkedMemoir() { + User user = UserContext.getUser(); + return memoirRepository.findByUserAndIsBookmarkedOrderByDateDesc(user, true); + } + @Override @Transactional public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request) { From 6137377ca2bedd801729f95323f8366942e64b99 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 19:41:54 +0900 Subject: [PATCH 08/14] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AA=A8=ED=8B=B0?= =?UTF-8?q?=EC=BD=98=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/off/memoir/entity/Emoticon.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Emoticon.java diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Emoticon.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Emoticon.java new file mode 100644 index 0000000..f4de4ec --- /dev/null +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Emoticon.java @@ -0,0 +1,19 @@ +package com.onnoff.onnoff.domain.off.memoir.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Emoticon { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, length = 1024) + private String imageUrl; +} From 0b3046c6f93941abc68f4a93c92c46a758598cba Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 22:37:50 +0900 Subject: [PATCH 09/14] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AA=A8=ED=8B=B0?= =?UTF-8?q?=EC=BD=98=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=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 --- .../onnoff/apiPayload/code/status/ErrorStatus.java | 3 +++ .../off/memoir/converter/MemoirConverter.java | 13 +++---------- .../domain/off/memoir/dto/MemoirRequestDTO.java | 9 +++++---- .../domain/off/memoir/dto/MemoirResponseDTO.java | 4 ++-- .../onnoff/domain/off/memoir/entity/Memoir.java | 8 +++++--- .../off/memoir/repository/EmoticonRepository.java | 7 +++++++ .../off/memoir/service/MemoirServiceImpl.java | 11 +++++++++-- 7 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/EmoticonRepository.java diff --git a/src/main/java/com/onnoff/onnoff/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/onnoff/onnoff/apiPayload/code/status/ErrorStatus.java index 311912c..7da0f93 100644 --- a/src/main/java/com/onnoff/onnoff/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/onnoff/onnoff/apiPayload/code/status/ErrorStatus.java @@ -35,6 +35,9 @@ public enum ErrorStatus implements BaseErrorCode { ANSWER_NOT_FOUND(HttpStatus.BAD_REQUEST, "ANSWER4001", "해당하는 회고 답변이 없습니다."), ANSWER_BAD_MATCH(HttpStatus.BAD_REQUEST, "ANSWER4002", "해당하는 회고에 속하는 회고 답변이 아닙니다."), + // 이모티콘 관련 에러 + EMOTICON_NOT_FOUND(HttpStatus.BAD_REQUEST, "EMOTICON4001", "해당하는 이모티콘이 없습니다."), + // 피드 관련 에러 FEED_NOT_FOUND(HttpStatus.BAD_REQUEST, "FEED4001", "해당하는 워라벨 피드가 없습니다."), FEED_NOT_BLANK(HttpStatus.BAD_REQUEST, "FEED4002", "워라벨 피드 내용은 공백일 수 없습니다."), diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 4383d34..656a934 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -3,6 +3,7 @@ import com.onnoff.onnoff.apiPayload.ApiResponse; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirResponseDTO; +import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirAnswer; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; @@ -23,14 +24,6 @@ public static List toMemoirQuestionRe .collect(Collectors.toList()); } - public static Memoir toMemoir(MemoirRequestDTO.MemoirWriteDTO request) { - return Memoir.builder() - .date(request.getDate()) - .icon(request.getIcon()) - .isBookmarked(false) - .build(); - } - public static MemoirResponseDTO.MemoirPreviewResultDTO toMemoirPreviewResultDTO(Memoir memoir) { if (memoir == null) { return MemoirResponseDTO.MemoirPreviewResultDTO.builder() @@ -49,7 +42,7 @@ public static MemoirResponseDTO.MemoirResultDTO toMemoirResultDTO(Memoir memoir) return MemoirResponseDTO.MemoirResultDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) - .icon(memoir.getIcon()) + .emoticonUrl(memoir.getEmoticon().getImageUrl()) .isBookmarked(memoir.getIsBookmarked()) .memoirAnswerList(toMemoirAnswerResultDTOList(memoir.getMemoirAnswerList())) .build(); @@ -73,7 +66,7 @@ public static List toBookmarkedMemo .map(memoir -> MemoirResponseDTO.BookmarkedMemoirResultDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) - .icon(memoir.getIcon()) + .emoticonUrl(memoir.getEmoticon().getImageUrl()) .remain(index.getAndIncrement() % 2) .build()) .collect(Collectors.toList()); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index 9ae1e0c..15d2b75 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -12,9 +12,10 @@ public class MemoirRequestDTO { @Getter public static class MemoirWriteDTO { @NotNull + @PastOrPresent LocalDate date; - @Size(max = 255) - String icon; + @NotNull + Long emoticonId; @NotEmpty List<@Valid MemoirWriteAnswerDTO> memoirAnswerList; } @@ -29,8 +30,8 @@ public static class MemoirWriteAnswerDTO { @Getter public static class MemoirUpdateDTO { - @Size(max = 255) - String icon; + @NotNull + Long emoticonId; List<@Valid MemoirUpdateAnswerDTO> memoirAnswerList; } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index 9a93727..f7b64fe 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -27,7 +27,7 @@ public static class MemoirQuestionResultDTO { public static class MemoirResultDTO { Long memoirId; LocalDate date; - String icon; + String emoticonUrl; Boolean isBookmarked; List memoirAnswerList; } @@ -59,7 +59,7 @@ public static class MemoirPreviewResultDTO { public static class BookmarkedMemoirResultDTO { Long memoirId; LocalDate date; - String icon; + String emoticonUrl; Integer remain; } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Memoir.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Memoir.java index 37f5383..bb45994 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Memoir.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/entity/Memoir.java @@ -22,7 +22,9 @@ public class Memoir extends BaseEntity { private LocalDate date; - private String icon; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "emoticon_id") + private Emoticon emoticon; @Column(columnDefinition = "boolean default false") private Boolean isBookmarked; @@ -34,8 +36,8 @@ public class Memoir extends BaseEntity { @OneToMany(mappedBy = "memoir", cascade = CascadeType.ALL) private List memoirAnswerList = new ArrayList<>(); - public void setIcon(String icon) { - this.icon = icon; + public void setEmoticon(Emoticon emoticon) { + this.emoticon = emoticon; } public void setIsBookmarked(Boolean isBookmarked) { diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/EmoticonRepository.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/EmoticonRepository.java new file mode 100644 index 0000000..dab6a2c --- /dev/null +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/EmoticonRepository.java @@ -0,0 +1,7 @@ +package com.onnoff.onnoff.domain.off.memoir.repository; + +import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface EmoticonRepository extends JpaRepository { +} diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index d03a305..f789fab 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -7,8 +7,10 @@ import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirAnswer; +import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; import com.onnoff.onnoff.domain.off.memoir.repository.MemoirAnswerRepository; +import com.onnoff.onnoff.domain.off.memoir.repository.EmoticonRepository; import com.onnoff.onnoff.domain.off.memoir.repository.MemoirQuestionRepository; import com.onnoff.onnoff.domain.off.memoir.repository.MemoirRepository; import com.onnoff.onnoff.domain.user.User; @@ -28,6 +30,7 @@ public class MemoirServiceImpl implements MemoirService { private final MemoirRepository memoirRepository; private final MemoirAnswerRepository memoirAnswerRepository; private final MemoirQuestionRepository memoirQuestionRepository; + private final EmoticonRepository emoticonRepository; @Override @Transactional(readOnly = true) @@ -43,7 +46,11 @@ public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { throw new GeneralException(ErrorStatus.MEMOIR_EXIST); } - Memoir newMemoir = MemoirConverter.toMemoir(request); + Memoir newMemoir = Memoir.builder() + .date(request.getDate()) + .emoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new GeneralException(ErrorStatus.EMOTICON_NOT_FOUND))) + .isBookmarked(false) + .build(); List newMemoirAnswerList = request.getMemoirAnswerList().stream() .map(memoirAnswer -> MemoirAnswer.builder() @@ -84,7 +91,7 @@ public List getBookmarkedMemoir() { public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request) { Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); - memoir.setIcon(request.getIcon()); + memoir.setEmoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new GeneralException(ErrorStatus.EMOTICON_NOT_FOUND))); List requestMemoirAnswerList = request.getMemoirAnswerList() == null ? new ArrayList<>() : request.getMemoirAnswerList(); for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer : requestMemoirAnswerList) { From 567ae020f11e0fab53b8eb7ce15ba85f1f1eb0b6 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Thu, 1 Feb 2024 23:10:25 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AA=A8=ED=8B=B0?= =?UTF-8?q?=EC=BD=98=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memoir/controller/MemoirController.java | 24 ++++++++++----- .../off/memoir/converter/MemoirConverter.java | 29 ++++++++++++------- .../off/memoir/dto/MemoirResponseDTO.java | 29 ++++++++++++------- .../off/memoir/service/MemoirService.java | 6 +++- .../off/memoir/service/MemoirServiceImpl.java | 19 +++++++----- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 09afeb2..f9c80f2 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -4,6 +4,7 @@ import com.onnoff.onnoff.domain.off.memoir.converter.MemoirConverter; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirResponseDTO; +import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; import com.onnoff.onnoff.domain.off.memoir.service.MemoirService; @@ -21,13 +22,6 @@ public class MemoirController { private final MemoirService memoirService; - @GetMapping("/memoir-questions") - @Operation(summary = "회고 질문 조회 API", description = "회고 질문 목록을 조회하는 API입니다.") - public ApiResponse> getMemoirQuestion() { - List memoirQuestionList = memoirService.getMemoirQuestion(); - return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionResultDTOList(memoirQuestionList)); - } - @PostMapping("/memoirs") @Operation(summary = "회고 작성 API", description = "새로운 회고를 작성하는 API입니다.") public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request) { @@ -36,7 +30,7 @@ public ApiResponse writeMemoir(@RequestBody @ } @GetMapping("/memoirs/previews") - @Operation(summary = "회고 미리보기 조회 API", description = "특정 날짜의 회고 미리보기를 조회하는 API입니다.") + @Operation(summary = "회고 미리보기 조회 API", description = "특정 날짜의 회고 미리보기를 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") public ApiResponse getMemoirPreview(@RequestParam(name = "date") LocalDate date) { Memoir memoir = memoirService.getMemoirPreview(date); return ApiResponse.onSuccess(MemoirConverter.toMemoirPreviewResultDTO(memoir)); @@ -76,4 +70,18 @@ public ApiResponse bookmarkMemoir(@PathVariab public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId) { return ApiResponse.onSuccess(memoirService.deleteMemoir(memoirId)); } + + @GetMapping("/memoir-questions") + @Operation(summary = "회고 질문 조회 API", description = "회고 질문 목록을 조회하는 API입니다.") + public ApiResponse> getMemoirQuestion() { + List memoirQuestionList = memoirService.getMemoirQuestion(); + return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionResultDTOList(memoirQuestionList)); + } + + @GetMapping("/emoticons") + @Operation(summary = "이모티콘 조회 API", description = "이모티콘 목록을 조회하는 API입니다.") + public ApiResponse> getEmoticon() { + List emoticonList = memoirService.getEmoticon(); + return ApiResponse.onSuccess(MemoirConverter.toEmoticonResultDTOList(emoticonList)); + } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 656a934..341cab0 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -14,16 +14,6 @@ public class MemoirConverter { - public static List toMemoirQuestionResultDTOList(List memoirQuestionList) { - return memoirQuestionList.stream() - .map(x -> MemoirResponseDTO.MemoirQuestionResultDTO.builder() - .questionId(x.getId()) - .question(x.getQuestion()) - .summary(x.getSummary()) - .build()) - .collect(Collectors.toList()); - } - public static MemoirResponseDTO.MemoirPreviewResultDTO toMemoirPreviewResultDTO(Memoir memoir) { if (memoir == null) { return MemoirResponseDTO.MemoirPreviewResultDTO.builder() @@ -72,4 +62,23 @@ public static List toBookmarkedMemo .collect(Collectors.toList()); } + public static List toMemoirQuestionResultDTOList(List memoirQuestionList) { + return memoirQuestionList.stream() + .map(memoirQuestion -> MemoirResponseDTO.MemoirQuestionResultDTO.builder() + .questionId(memoirQuestion.getId()) + .question(memoirQuestion.getQuestion()) + .summary(memoirQuestion.getSummary()) + .build()) + .collect(Collectors.toList()); + } + + public static List toEmoticonResultDTOList(List emoticonList) { + return emoticonList.stream() + .map(emoticon -> MemoirResponseDTO.EmoticonResultDTO.builder() + .emoticonId(emoticon.getId()) + .imageUrl(emoticon.getImageUrl()) + .build()) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index f7b64fe..3325625 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -10,16 +10,6 @@ public class MemoirResponseDTO { - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class MemoirQuestionResultDTO { - Long questionId; - String question; - String summary; - } - @Builder @Getter @NoArgsConstructor @@ -63,4 +53,23 @@ public static class BookmarkedMemoirResultDTO { Integer remain; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class MemoirQuestionResultDTO { + Long questionId; + String question; + String summary; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class EmoticonResultDTO { + Long emoticonId; + String imageUrl; + } + } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index 5ff40e8..f3b83b0 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -1,6 +1,7 @@ package com.onnoff.onnoff.domain.off.memoir.service; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; +import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; import org.springframework.transaction.annotation.Transactional; @@ -9,7 +10,6 @@ import java.util.List; public interface MemoirService { - List getMemoirQuestion(); Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request); @@ -24,4 +24,8 @@ public interface MemoirService { Memoir bookmarkMemoir(Long memoirId); Long deleteMemoir(Long memoirId); + + List getMemoirQuestion(); + + List getEmoticon(); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index f789fab..5d054bf 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -3,7 +3,6 @@ import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; import com.onnoff.onnoff.apiPayload.exception.GeneralException; import com.onnoff.onnoff.auth.UserContext; -import com.onnoff.onnoff.domain.off.memoir.converter.MemoirConverter; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirAnswer; @@ -32,12 +31,6 @@ public class MemoirServiceImpl implements MemoirService { private final MemoirQuestionRepository memoirQuestionRepository; private final EmoticonRepository emoticonRepository; - @Override - @Transactional(readOnly = true) - public List getMemoirQuestion() { - return memoirQuestionRepository.findAll(); - } - @Override @Transactional public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { @@ -122,4 +115,16 @@ public Long deleteMemoir(Long memoirId) { return memoir.getId(); } + + @Override + @Transactional(readOnly = true) + public List getMemoirQuestion() { + return memoirQuestionRepository.findAll(); + } + + @Override + @Transactional(readOnly = true) + public List getEmoticon() { + return emoticonRepository.findAll(); + } } From 8cb451e31cf91e3531e9d6755ff5443251bc78bd Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Fri, 2 Feb 2024 12:11:44 +0900 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20=ED=9A=8C=EA=B3=A0=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=88=98=EC=A0=95=20API=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java | 1 + .../onnoff/domain/off/memoir/service/MemoirServiceImpl.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index 15d2b75..586ba6d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -32,6 +32,7 @@ public static class MemoirWriteAnswerDTO { public static class MemoirUpdateDTO { @NotNull Long emoticonId; + @NotEmpty List<@Valid MemoirUpdateAnswerDTO> memoirAnswerList; } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 5d054bf..9079189 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -85,9 +85,8 @@ public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO reque Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); memoir.setEmoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new GeneralException(ErrorStatus.EMOTICON_NOT_FOUND))); - List requestMemoirAnswerList = request.getMemoirAnswerList() == null ? new ArrayList<>() : request.getMemoirAnswerList(); - for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer : requestMemoirAnswerList) { + for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer : request.getMemoirAnswerList()) { MemoirAnswer findMemoirAnswer = memoirAnswerRepository.findById(memoirAnswer.getAnswerId()).orElseThrow(() -> new GeneralException(ErrorStatus.ANSWER_NOT_FOUND)); if (findMemoirAnswer.getMemoir() != memoir) { throw new GeneralException(ErrorStatus.ANSWER_BAD_MATCH); From 5d54990272d9f5a92f112790137f151818e390f9 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Fri, 2 Feb 2024 12:22:09 +0900 Subject: [PATCH 12/14] =?UTF-8?q?feat:=20=ED=9A=8C=EA=B3=A0=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=88=98=EC=A0=95=20API=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java index 586ba6d..3b414ca 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java @@ -16,7 +16,7 @@ public static class MemoirWriteDTO { LocalDate date; @NotNull Long emoticonId; - @NotEmpty + @NotNull List<@Valid MemoirWriteAnswerDTO> memoirAnswerList; } @@ -32,7 +32,7 @@ public static class MemoirWriteAnswerDTO { public static class MemoirUpdateDTO { @NotNull Long emoticonId; - @NotEmpty + @NotNull List<@Valid MemoirUpdateAnswerDTO> memoirAnswerList; } From 624f4ab3f632f7d4b1c6f6437b6ddecb4c539311 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Fri, 2 Feb 2024 14:32:26 +0900 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20=EB=B6=81=EB=A7=88=ED=81=AC=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20=EC=A1=B0=ED=9A=8C=20API=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memoir/controller/MemoirController.java | 9 +++++---- .../off/memoir/converter/MemoirConverter.java | 19 ++++++++++++++----- .../off/memoir/dto/MemoirResponseDTO.java | 14 ++++++++++++++ .../memoir/repository/MemoirRepository.java | 4 +++- .../off/memoir/service/MemoirService.java | 3 ++- .../off/memoir/service/MemoirServiceImpl.java | 6 ++++-- 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index f9c80f2..574dac5 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.Operation; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import java.time.LocalDate; @@ -44,10 +45,10 @@ public ApiResponse getMemoir(@PathVariable(na } @GetMapping("/memoirs/bookmarks") - @Operation(summary = "북마크 회고 조회 API", description = "북마크 상태의 회고를 조회하는 API입니다.") - public ApiResponse> getBookmarkedMemoir() { - List memoirList = memoirService.getBookmarkedMemoir(); - return ApiResponse.onSuccess(MemoirConverter.toBookmarkedMemoirResultDTOList(memoirList)); + @Operation(summary = "북마크 회고 조회 API", description = "북마크 상태의 회고를 조회하는 API이며, 페이징을 포함합니다. Query String으로 페이지 번호를 입력해 주세요. 0번이 1페이지입니다.") + public ApiResponse getBookmarkedMemoir(@RequestParam(name = "pageNumber") Integer pageNumber) { + Page memoirList = memoirService.getBookmarkedMemoir(pageNumber); + return ApiResponse.onSuccess(MemoirConverter.toBookmarkedMemoirPreviewListDTO(memoirList)); } @PatchMapping("/memoirs/{memoirId}") diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 341cab0..2bbe365 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -1,12 +1,11 @@ package com.onnoff.onnoff.domain.off.memoir.converter; -import com.onnoff.onnoff.apiPayload.ApiResponse; -import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirResponseDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirAnswer; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; +import org.springframework.data.domain.Page; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -49,17 +48,27 @@ public static List toMemoirAnswerResult .collect(Collectors.toList()); } - public static List toBookmarkedMemoirResultDTOList(List memoirList) { + public static MemoirResponseDTO.BookmarkedMemoirResultListDTO toBookmarkedMemoirPreviewListDTO(Page memoirList) { AtomicInteger index = new AtomicInteger(); - return memoirList.stream() + List memoirResultDTOList = memoirList.stream() .map(memoir -> MemoirResponseDTO.BookmarkedMemoirResultDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) .emoticonUrl(memoir.getEmoticon().getImageUrl()) .remain(index.getAndIncrement() % 2) .build()) - .collect(Collectors.toList()); + .toList(); + + return MemoirResponseDTO.BookmarkedMemoirResultListDTO.builder() + .memoirList(memoirResultDTOList) + .pageNumber(memoirList.getNumber()) + .pageSize(memoirList.getSize()) + .totalPages(memoirList.getTotalPages()) + .totalElements(memoirList.getTotalElements()) + .isFirst(memoirList.isFirst()) + .isLast(memoirList.isLast()) + .build(); } public static List toMemoirQuestionResultDTOList(List memoirQuestionList) { diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index 3325625..d16fa39 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -42,6 +42,20 @@ public static class MemoirPreviewResultDTO { Long memoirId; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class BookmarkedMemoirResultListDTO { + List memoirList; + Integer pageNumber; + Integer pageSize; + Integer totalPages; + Long totalElements; + Boolean isFirst; + Boolean isLast; + } + @Builder @Getter @NoArgsConstructor diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java index f211a92..5fe5ab4 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/repository/MemoirRepository.java @@ -2,6 +2,8 @@ import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.user.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDate; @@ -12,5 +14,5 @@ public interface MemoirRepository extends JpaRepository { Optional findByUserAndDate(User user, LocalDate date); - List findByUserAndIsBookmarkedOrderByDateDesc(User user, Boolean isBookmarked); + Page findByUserAndIsBookmarkedOrderByDateDesc(User user, Boolean isBookmarked, PageRequest pageRequest); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java index f3b83b0..2c2d6be 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirService.java @@ -4,6 +4,7 @@ import com.onnoff.onnoff.domain.off.memoir.entity.Emoticon; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; import com.onnoff.onnoff.domain.off.memoir.entity.MemoirQuestion; +import org.springframework.data.domain.Page; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; @@ -17,7 +18,7 @@ public interface MemoirService { Memoir getMemoir(Long memoirId); - List getBookmarkedMemoir(); + Page getBookmarkedMemoir(Integer pageNumber); Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java index 9079189..40c3e1d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/service/MemoirServiceImpl.java @@ -14,6 +14,8 @@ import com.onnoff.onnoff.domain.off.memoir.repository.MemoirRepository; import com.onnoff.onnoff.domain.user.User; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,9 +76,9 @@ public Memoir getMemoir(Long memoirId) { @Override @Transactional(readOnly = true) - public List getBookmarkedMemoir() { + public Page getBookmarkedMemoir(Integer pageNumber) { User user = UserContext.getUser(); - return memoirRepository.findByUserAndIsBookmarkedOrderByDateDesc(user, true); + return memoirRepository.findByUserAndIsBookmarkedOrderByDateDesc(user, true, PageRequest.of(pageNumber, 10)); } @Override From 6f6bd2a27b959a13994092f250a398d2264ab700 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Fri, 2 Feb 2024 14:41:32 +0900 Subject: [PATCH 14/14] =?UTF-8?q?rename:=20DTO=EB=AA=85=20=EA=B0=84?= =?UTF-8?q?=EB=9E=B5=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memoir/controller/MemoirController.java | 30 ++++++++-------- .../off/memoir/converter/MemoirConverter.java | 34 +++++++++---------- .../off/memoir/dto/MemoirResponseDTO.java | 18 +++++----- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java index 574dac5..21bde92 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/controller/MemoirController.java @@ -25,45 +25,45 @@ public class MemoirController { @PostMapping("/memoirs") @Operation(summary = "회고 작성 API", description = "새로운 회고를 작성하는 API입니다.") - public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request) { + public ApiResponse writeMemoir(@RequestBody @Valid MemoirRequestDTO.MemoirWriteDTO request) { Memoir memoir = memoirService.writeMemoir(request); - return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirDTO(memoir)); } @GetMapping("/memoirs/previews") @Operation(summary = "회고 미리보기 조회 API", description = "특정 날짜의 회고 미리보기를 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") - public ApiResponse getMemoirPreview(@RequestParam(name = "date") LocalDate date) { + public ApiResponse getMemoirPreview(@RequestParam(name = "date") LocalDate date) { Memoir memoir = memoirService.getMemoirPreview(date); - return ApiResponse.onSuccess(MemoirConverter.toMemoirPreviewResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirPreviewDTO(memoir)); } @GetMapping("/memoirs/{memoirId}") @Operation(summary = "회고 조회 API", description = "특정 회고를 조회하는 API입니다.") - public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId) { + public ApiResponse getMemoir(@PathVariable(name = "memoirId") Long memoirId) { Memoir memoir = memoirService.getMemoir(memoirId); - return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirDTO(memoir)); } @GetMapping("/memoirs/bookmarks") @Operation(summary = "북마크 회고 조회 API", description = "북마크 상태의 회고를 조회하는 API이며, 페이징을 포함합니다. Query String으로 페이지 번호를 입력해 주세요. 0번이 1페이지입니다.") - public ApiResponse getBookmarkedMemoir(@RequestParam(name = "pageNumber") Integer pageNumber) { + public ApiResponse getBookmarkedMemoir(@RequestParam(name = "pageNumber") Integer pageNumber) { Page memoirList = memoirService.getBookmarkedMemoir(pageNumber); return ApiResponse.onSuccess(MemoirConverter.toBookmarkedMemoirPreviewListDTO(memoirList)); } @PatchMapping("/memoirs/{memoirId}") @Operation(summary = "회고 내용 수정 API", description = "기존의 회고 내용을 수정하는 API입니다.") - public ApiResponse modifyMemoir(@PathVariable(name = "memoirId") Long memoirId, + public ApiResponse modifyMemoir(@PathVariable(name = "memoirId") Long memoirId, @RequestBody @Valid MemoirRequestDTO.MemoirUpdateDTO request) { Memoir memoir = memoirService.modifyMemoir(memoirId, request); - return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirDTO(memoir)); } @PatchMapping("/memoirs/{memoirId}/bookmark") @Operation(summary = "회고 북마크 및 해제 API", description = "회고를 북마크하거나 북마크 해제하는 API입니다.") - public ApiResponse bookmarkMemoir(@PathVariable(name = "memoirId") Long memoirId) { + public ApiResponse bookmarkMemoir(@PathVariable(name = "memoirId") Long memoirId) { Memoir memoir = memoirService.bookmarkMemoir(memoirId); - return ApiResponse.onSuccess(MemoirConverter.toMemoirResultDTO(memoir)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirDTO(memoir)); } @DeleteMapping("/memoirs/{memoirId}") @@ -74,15 +74,15 @@ public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memo @GetMapping("/memoir-questions") @Operation(summary = "회고 질문 조회 API", description = "회고 질문 목록을 조회하는 API입니다.") - public ApiResponse> getMemoirQuestion() { + public ApiResponse> getMemoirQuestion() { List memoirQuestionList = memoirService.getMemoirQuestion(); - return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionResultDTOList(memoirQuestionList)); + return ApiResponse.onSuccess(MemoirConverter.toMemoirQuestionDTOList(memoirQuestionList)); } @GetMapping("/emoticons") @Operation(summary = "이모티콘 조회 API", description = "이모티콘 목록을 조회하는 API입니다.") - public ApiResponse> getEmoticon() { + public ApiResponse> getEmoticon() { List emoticonList = memoirService.getEmoticon(); - return ApiResponse.onSuccess(MemoirConverter.toEmoticonResultDTOList(emoticonList)); + return ApiResponse.onSuccess(MemoirConverter.toEmoticonDTOList(emoticonList)); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java index 2bbe365..c2dc91d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/converter/MemoirConverter.java @@ -13,33 +13,33 @@ public class MemoirConverter { - public static MemoirResponseDTO.MemoirPreviewResultDTO toMemoirPreviewResultDTO(Memoir memoir) { + public static MemoirResponseDTO.MemoirPreviewDTO toMemoirPreviewDTO(Memoir memoir) { if (memoir == null) { - return MemoirResponseDTO.MemoirPreviewResultDTO.builder() + return MemoirResponseDTO.MemoirPreviewDTO.builder() .memoirId(null) .written(false) .build(); } else { - return MemoirResponseDTO.MemoirPreviewResultDTO.builder() + return MemoirResponseDTO.MemoirPreviewDTO.builder() .memoirId(memoir.getId()) .written(true) .build(); } } - public static MemoirResponseDTO.MemoirResultDTO toMemoirResultDTO(Memoir memoir) { - return MemoirResponseDTO.MemoirResultDTO.builder() + public static MemoirResponseDTO.MemoirDTO toMemoirDTO(Memoir memoir) { + return MemoirResponseDTO.MemoirDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) .emoticonUrl(memoir.getEmoticon().getImageUrl()) .isBookmarked(memoir.getIsBookmarked()) - .memoirAnswerList(toMemoirAnswerResultDTOList(memoir.getMemoirAnswerList())) + .memoirAnswerList(toMemoirAnswerDTOList(memoir.getMemoirAnswerList())) .build(); } - public static List toMemoirAnswerResultDTOList(List memoirAnswerList) { + public static List toMemoirAnswerDTOList(List memoirAnswerList) { return memoirAnswerList.stream() - .map(memoirAnswer -> MemoirResponseDTO.MemoirAnswerResultDTO.builder() + .map(memoirAnswer -> MemoirResponseDTO.MemoirAnswerDTO.builder() .answerId(memoirAnswer.getId()) .question(memoirAnswer.getMemoirQuestion().getQuestion()) .summary(memoirAnswer.getMemoirQuestion().getSummary()) @@ -48,11 +48,11 @@ public static List toMemoirAnswerResult .collect(Collectors.toList()); } - public static MemoirResponseDTO.BookmarkedMemoirResultListDTO toBookmarkedMemoirPreviewListDTO(Page memoirList) { + public static MemoirResponseDTO.BookmarkedMemoirListDTO toBookmarkedMemoirPreviewListDTO(Page memoirList) { AtomicInteger index = new AtomicInteger(); - List memoirResultDTOList = memoirList.stream() - .map(memoir -> MemoirResponseDTO.BookmarkedMemoirResultDTO.builder() + List memoirDTOList = memoirList.stream() + .map(memoir -> MemoirResponseDTO.BookmarkedMemoirDTO.builder() .memoirId(memoir.getId()) .date(memoir.getDate()) .emoticonUrl(memoir.getEmoticon().getImageUrl()) @@ -60,8 +60,8 @@ public static MemoirResponseDTO.BookmarkedMemoirResultListDTO toBookmarkedMemoir .build()) .toList(); - return MemoirResponseDTO.BookmarkedMemoirResultListDTO.builder() - .memoirList(memoirResultDTOList) + return MemoirResponseDTO.BookmarkedMemoirListDTO.builder() + .memoirList(memoirDTOList) .pageNumber(memoirList.getNumber()) .pageSize(memoirList.getSize()) .totalPages(memoirList.getTotalPages()) @@ -71,9 +71,9 @@ public static MemoirResponseDTO.BookmarkedMemoirResultListDTO toBookmarkedMemoir .build(); } - public static List toMemoirQuestionResultDTOList(List memoirQuestionList) { + public static List toMemoirQuestionDTOList(List memoirQuestionList) { return memoirQuestionList.stream() - .map(memoirQuestion -> MemoirResponseDTO.MemoirQuestionResultDTO.builder() + .map(memoirQuestion -> MemoirResponseDTO.MemoirQuestionDTO.builder() .questionId(memoirQuestion.getId()) .question(memoirQuestion.getQuestion()) .summary(memoirQuestion.getSummary()) @@ -81,9 +81,9 @@ public static List toMemoirQuestionRe .collect(Collectors.toList()); } - public static List toEmoticonResultDTOList(List emoticonList) { + public static List toEmoticonDTOList(List emoticonList) { return emoticonList.stream() - .map(emoticon -> MemoirResponseDTO.EmoticonResultDTO.builder() + .map(emoticon -> MemoirResponseDTO.EmoticonDTO.builder() .emoticonId(emoticon.getId()) .imageUrl(emoticon.getImageUrl()) .build()) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java index d16fa39..14b6cb0 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/memoir/dto/MemoirResponseDTO.java @@ -14,19 +14,19 @@ public class MemoirResponseDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirResultDTO { + public static class MemoirDTO { Long memoirId; LocalDate date; String emoticonUrl; Boolean isBookmarked; - List memoirAnswerList; + List memoirAnswerList; } @Builder @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirAnswerResultDTO { + public static class MemoirAnswerDTO { Long answerId; String question; String summary; @@ -37,7 +37,7 @@ public static class MemoirAnswerResultDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirPreviewResultDTO { + public static class MemoirPreviewDTO { Boolean written; Long memoirId; } @@ -46,8 +46,8 @@ public static class MemoirPreviewResultDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class BookmarkedMemoirResultListDTO { - List memoirList; + public static class BookmarkedMemoirListDTO { + List memoirList; Integer pageNumber; Integer pageSize; Integer totalPages; @@ -60,7 +60,7 @@ public static class BookmarkedMemoirResultListDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class BookmarkedMemoirResultDTO { + public static class BookmarkedMemoirDTO { Long memoirId; LocalDate date; String emoticonUrl; @@ -71,7 +71,7 @@ public static class BookmarkedMemoirResultDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class MemoirQuestionResultDTO { + public static class MemoirQuestionDTO { Long questionId; String question; String summary; @@ -81,7 +81,7 @@ public static class MemoirQuestionResultDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class EmoticonResultDTO { + public static class EmoticonDTO { Long emoticonId; String imageUrl; }