From 39d4239d09ee43f1040d7c22ec88d09aea82b896 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 01:50:20 +0900 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20answer=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EB=B0=8F=20=EA=B3=B5=EB=B0=B1?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/onnoff/domain/off/memoir/dto/MemoirRequestDTO.java | 2 ++ .../onnoff/domain/off/memoir/service/MemoirServiceImpl.java | 4 ++-- 2 files changed, 4 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 3b414ca..2c2bac6 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 @@ -24,6 +24,7 @@ public static class MemoirWriteDTO { public static class MemoirWriteAnswerDTO { @NotNull Long questionId; + @NotNull @Size(max = 500) String answer; } @@ -40,6 +41,7 @@ public static class MemoirUpdateDTO { public static class MemoirUpdateAnswerDTO { @NotNull Long answerId; + @NotNull @Size(max = 500) String answer; } 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 40c3e1d..ef711a6 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 @@ -49,7 +49,7 @@ public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { List newMemoirAnswerList = request.getMemoirAnswerList().stream() .map(memoirAnswer -> MemoirAnswer.builder() - .answer(memoirAnswer.getAnswer()) + .answer(memoirAnswer.getAnswer().trim()) .memoirQuestion(memoirQuestionRepository.findById(memoirAnswer.getQuestionId()).orElseThrow(() -> new GeneralException(ErrorStatus.QUESTION_NOT_FOUND))) .memoir(newMemoir) .build()) @@ -93,7 +93,7 @@ public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO reque if (findMemoirAnswer.getMemoir() != memoir) { throw new GeneralException(ErrorStatus.ANSWER_BAD_MATCH); } - findMemoirAnswer.setAnswer(memoirAnswer.getAnswer()); + findMemoirAnswer.setAnswer(memoirAnswer.getAnswer().trim()); } return memoir; From 7427bb5b3362ee1fb1193c79f3250d612b577853 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 01:58:28 +0900 Subject: [PATCH 2/6] =?UTF-8?q?rename:=20=EC=9A=94=EC=9D=BC=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20DTO=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/domain/weekday/controller/WeekdayController.java | 6 +++--- .../onnoff/domain/weekday/dto/WeekdayResponseDTO.java | 2 +- .../onnoff/domain/weekday/service/WeekdayService.java | 2 +- .../onnoff/domain/weekday/service/WeekdayServiceImpl.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/weekday/controller/WeekdayController.java b/src/main/java/com/onnoff/onnoff/domain/weekday/controller/WeekdayController.java index d0e90a0..471407e 100644 --- a/src/main/java/com/onnoff/onnoff/domain/weekday/controller/WeekdayController.java +++ b/src/main/java/com/onnoff/onnoff/domain/weekday/controller/WeekdayController.java @@ -19,19 +19,19 @@ public class WeekdayController { @GetMapping("/weekdays/init") @Operation(summary = "초기 요일 조회 API", description = "오늘 날짜를 기준으로 일주일을 조회하는 API입니다.") - public ApiResponse getInitWeekday() { + public ApiResponse getInitWeekday() { return ApiResponse.onSuccess(weekdayService.getWeekday(LocalDate.now())); } @GetMapping("/weekdays/prev") @Operation(summary = "이전 주 요일 조회 API", description = "입력된 날짜를 기준으로 이전 일주일을 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") - public ApiResponse getPrevWeekday(@RequestParam(name = "date") LocalDate date) { + public ApiResponse getPrevWeekday(@RequestParam(name = "date") LocalDate date) { return ApiResponse.onSuccess(weekdayService.getWeekday(date.minusDays(7))); } @GetMapping("/weekdays/next") @Operation(summary = "다음 주 요일 조회 API", description = "입력된 날짜를 기준으로 다음 일주일을 조회하는 API입니다. Query String으로 날짜를 입력해 주세요.") - public ApiResponse getNextWeekday(@RequestParam(name = "date") LocalDate date) { + public ApiResponse getNextWeekday(@RequestParam(name = "date") LocalDate date) { return ApiResponse.onSuccess(weekdayService.getWeekday(date.plusDays(7))); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/weekday/dto/WeekdayResponseDTO.java b/src/main/java/com/onnoff/onnoff/domain/weekday/dto/WeekdayResponseDTO.java index 6a43e83..ba8045b 100644 --- a/src/main/java/com/onnoff/onnoff/domain/weekday/dto/WeekdayResponseDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/weekday/dto/WeekdayResponseDTO.java @@ -13,7 +13,7 @@ public class WeekdayResponseDTO { @Getter @NoArgsConstructor @AllArgsConstructor - public static class WeekdayResultDTO { + public static class WeekdayDTO { LocalDate monday; LocalDate tuesday; LocalDate wednesday; diff --git a/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayService.java b/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayService.java index 86767c5..cbf6d2b 100644 --- a/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayService.java +++ b/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayService.java @@ -6,5 +6,5 @@ public interface WeekdayService { - WeekdayResponseDTO.WeekdayResultDTO getWeekday(LocalDate date); + WeekdayResponseDTO.WeekdayDTO getWeekday(LocalDate date); } diff --git a/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayServiceImpl.java index 703f17b..3484a0d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/weekday/service/WeekdayServiceImpl.java @@ -11,10 +11,10 @@ public class WeekdayServiceImpl implements WeekdayService { @Override - public WeekdayResponseDTO.WeekdayResultDTO getWeekday(LocalDate date) { + public WeekdayResponseDTO.WeekdayDTO getWeekday(LocalDate date) { LocalDate monday = date.minusDays(date.getDayOfWeek().getValue() - 1); - return WeekdayResponseDTO.WeekdayResultDTO.builder() + return WeekdayResponseDTO.WeekdayDTO.builder() .monday(monday) .tuesday(monday.plusDays(1)) .wednesday(monday.plusDays(2)) From af429c9da7ec3734a0aaf77e27d052f167647079 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 02:16:20 +0900 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=ED=94=BC=EB=93=9C=20=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20S3=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/off/feedImage/service/FeedImageServiceImpl.java | 5 ++++- src/main/resources/application-dev.yml | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java index d7259b0..45fb047 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java @@ -32,6 +32,9 @@ public class FeedImageServiceImpl implements FeedImageService { @Value("${cloud.aws.s3.bucket}") private String bucket; + @Value("${cloud.aws.s3.path.feed-image}") + private String path; + private final AmazonS3Client amazonS3Client; private final FeedImageRepository feedImageRepository; @@ -73,7 +76,7 @@ public Long deleteFeedImage(Long feedImageId) { } public String uploadImage(MultipartFile multipartFile) { - String fileName = createFileName(multipartFile.getOriginalFilename()); + String fileName = path + "/" + createFileName(multipartFile.getOriginalFilename()); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(multipartFile.getSize()); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ccd2640..91f85ef 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -22,6 +22,8 @@ cloud: aws: s3: bucket: ${S3_BUCKET} + path: + feed-image: feedImages credentials: access-key: ${S3_ACCESS_KEY} secret-key: ${S3_SECRET_KEY} From 55541308a62cb654e732a54db00fc5771cb49ebb Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 02:51:24 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=84=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/domain/off/feed/controller/FeedController.java | 2 +- .../domain/off/feedImage/controller/FeedImageController.java | 2 +- .../onnoff/domain/off/memoir/controller/MemoirController.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/controller/FeedController.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/controller/FeedController.java index 9b48027..6e9c9b4 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/controller/FeedController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/controller/FeedController.java @@ -35,7 +35,7 @@ public ApiResponse> getFeed(@RequestParam(name = " } @PatchMapping("/feeds/{feedId}") - @Operation(summary = "워라벨 피드 수정 API", description = "워라벨 피드의 내용을 수정하는 API입니다.") + @Operation(summary = "워라벨 피드 내용 수정 API", description = "워라벨 피드의 내용을 수정하는 API입니다.") public ApiResponse modifyFeed(@PathVariable(name = "feedId") Long feedId, @RequestBody @Valid FeedRequestDTO.ModifyFeedDTO request) { Feed feed = feedService.modifyFeed(feedId, request); return ApiResponse.onSuccess(FeedConverter.toFeedDTO(feed)); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/controller/FeedImageController.java b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/controller/FeedImageController.java index 470a022..e828ed3 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/controller/FeedImageController.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/controller/FeedImageController.java @@ -24,7 +24,7 @@ public ApiResponse uploadFeedImage(@RequestPa } @GetMapping("/feed-images") - @Operation(summary = "워라벨 피드 사진 조회 API",description = "워라벨 피드의 사진을 조회하는 API입니다. 생성 날짜 기준 오래된 순으로 정렬된 결과가 반환됩니다.") + @Operation(summary = "워라벨 피드 사진 조회 API",description = "워라벨 피드의 사진을 조회하는 API입니다. 업로드한 지 오래된 순으로 정렬된 결과가 반환됩니다.") public ApiResponse> getFeedImage() { return ApiResponse.onSuccess(feedImageService.getFeedImage()); } 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 21bde92..c549b8e 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 @@ -52,7 +52,7 @@ public ApiResponse getBookmarkedMemoi } @PatchMapping("/memoirs/{memoirId}") - @Operation(summary = "회고 내용 수정 API", description = "기존의 회고 내용을 수정하는 API입니다.") + @Operation(summary = "회고 내용 수정 API", description = "회고의 이모티콘과 답변을 수정하는 API입니다.") public ApiResponse modifyMemoir(@PathVariable(name = "memoirId") Long memoirId, @RequestBody @Valid MemoirRequestDTO.MemoirUpdateDTO request) { Memoir memoir = memoirService.modifyMemoir(memoirId, request); @@ -67,7 +67,7 @@ public ApiResponse bookmarkMemoir(@PathVariable(nam } @DeleteMapping("/memoirs/{memoirId}") - @Operation(summary = "회고 삭제 API", description = "기존의 회고를 삭제하는 API입니다.") + @Operation(summary = "회고 삭제 API", description = "회고를 삭제하는 API입니다.") public ApiResponse deleteMemoir(@PathVariable(name = "memoirId") Long memoirId) { return ApiResponse.onSuccess(memoirService.deleteMemoir(memoirId)); } From 5c2da224e9688c1f0d47b4c7d5bcbe61c22d18f1 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 02:52:36 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=EC=9B=8C=EB=9D=BC=EB=B2=A8=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=20=EB=82=B4=EC=9A=A9=20=EA=B3=B5=EB=B0=B1=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/onnoff/domain/off/feed/converter/FeedConverter.java | 2 +- .../onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/converter/FeedConverter.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/converter/FeedConverter.java index 4108ba2..5e3dfd7 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/converter/FeedConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/converter/FeedConverter.java @@ -10,7 +10,7 @@ public class FeedConverter { public static Feed toFeed(FeedRequestDTO.AddFeedDTO request, User user) { return Feed.builder() .date(request.getDate()) - .content(request.getContent()) + .content(request.getContent().trim()) .isChecked(false) .user(user) .build(); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java index d4f0485..4b1db1c 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java @@ -39,7 +39,7 @@ public List getFeed(LocalDate date) { @Transactional public Feed modifyFeed(Long feedId, FeedRequestDTO.ModifyFeedDTO request) { Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); - feed.setContent(request.getContent()); + feed.setContent(request.getContent().trim()); return feed; } From 3505e5621a0b2514f051dfbd43cbff4eddd3a2f5 Mon Sep 17 00:00:00 2001 From: kimjm9841 Date: Tue, 6 Feb 2024 03:04:03 +0900 Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/handler/FeedHandler.java | 10 +++++++++ .../exception/handler/FeedImageHandler.java | 10 +++++++++ .../exception/handler/MemoirHandler.java | 10 +++++++++ .../off/feed/service/FeedServiceImpl.java | 10 ++++----- .../service/FeedImageServiceImpl.java | 5 +++-- .../off/memoir/service/MemoirServiceImpl.java | 22 +++++++++---------- 6 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedHandler.java create mode 100644 src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedImageHandler.java create mode 100644 src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/MemoirHandler.java diff --git a/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedHandler.java b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedHandler.java new file mode 100644 index 0000000..c88de21 --- /dev/null +++ b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedHandler.java @@ -0,0 +1,10 @@ +package com.onnoff.onnoff.apiPayload.exception.handler; + +import com.onnoff.onnoff.apiPayload.code.BaseErrorCode; +import com.onnoff.onnoff.apiPayload.exception.GeneralException; + +public class FeedHandler extends GeneralException { + public FeedHandler(BaseErrorCode errorCode) { + super(errorCode); + } +} diff --git a/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedImageHandler.java b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedImageHandler.java new file mode 100644 index 0000000..91d4336 --- /dev/null +++ b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/FeedImageHandler.java @@ -0,0 +1,10 @@ +package com.onnoff.onnoff.apiPayload.exception.handler; + +import com.onnoff.onnoff.apiPayload.code.BaseErrorCode; +import com.onnoff.onnoff.apiPayload.exception.GeneralException; + +public class FeedImageHandler extends GeneralException { + public FeedImageHandler(BaseErrorCode errorCode) { + super(errorCode); + } +} diff --git a/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/MemoirHandler.java b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/MemoirHandler.java new file mode 100644 index 0000000..334a607 --- /dev/null +++ b/src/main/java/com/onnoff/onnoff/apiPayload/exception/handler/MemoirHandler.java @@ -0,0 +1,10 @@ +package com.onnoff.onnoff.apiPayload.exception.handler; + +import com.onnoff.onnoff.apiPayload.code.BaseErrorCode; +import com.onnoff.onnoff.apiPayload.exception.GeneralException; + +public class MemoirHandler extends GeneralException { + public MemoirHandler(BaseErrorCode errorCode) { + super(errorCode); + } +} diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java index 4b1db1c..29e8a3c 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedServiceImpl.java @@ -1,7 +1,7 @@ package com.onnoff.onnoff.domain.off.feed.service; import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; -import com.onnoff.onnoff.apiPayload.exception.GeneralException; +import com.onnoff.onnoff.apiPayload.exception.handler.FeedHandler; import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.off.feed.converter.FeedConverter; import com.onnoff.onnoff.domain.off.feed.dto.FeedRequestDTO; @@ -38,7 +38,7 @@ public List getFeed(LocalDate date) { @Override @Transactional public Feed modifyFeed(Long feedId, FeedRequestDTO.ModifyFeedDTO request) { - Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new FeedHandler(ErrorStatus.FEED_NOT_FOUND)); feed.setContent(request.getContent().trim()); return feed; @@ -47,7 +47,7 @@ public Feed modifyFeed(Long feedId, FeedRequestDTO.ModifyFeedDTO request) { @Override @Transactional public Feed delayFeed(Long feedId) { - Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new FeedHandler(ErrorStatus.FEED_NOT_FOUND)); feed.setDate(LocalDate.now().plusDays(1)); return feed; @@ -56,7 +56,7 @@ public Feed delayFeed(Long feedId) { @Override @Transactional public Feed checkFeed(Long feedId) { - Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new FeedHandler(ErrorStatus.FEED_NOT_FOUND)); feed.setIsChecked(feed.getIsChecked().equals(false)); return feed; @@ -65,7 +65,7 @@ public Feed checkFeed(Long feedId) { @Override @Transactional public Long deleteFeed(Long feedId) { - Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new FeedHandler(ErrorStatus.FEED_NOT_FOUND)); feedRepository.delete(feed); return feed.getId(); diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java index 45fb047..94f71d4 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java @@ -7,6 +7,7 @@ import com.amazonaws.services.s3.model.PutObjectRequest; import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; import com.onnoff.onnoff.apiPayload.exception.GeneralException; +import com.onnoff.onnoff.apiPayload.exception.handler.FeedImageHandler; import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.off.feedImage.converter.FeedImageConverter; import com.onnoff.onnoff.domain.off.feedImage.dto.FeedImageResponseDTO; @@ -67,7 +68,7 @@ public List getFeedImage() { @Override @Transactional public Long deleteFeedImage(Long feedImageId) { - FeedImage feedImage = feedImageRepository.findById(feedImageId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_IMAGE_NOT_FOUND)); + FeedImage feedImage = feedImageRepository.findById(feedImageId).orElseThrow(() -> new FeedImageHandler(ErrorStatus.FEED_IMAGE_NOT_FOUND)); deleteImage(feedImage.getImageKey()); feedImageRepository.delete(feedImage); @@ -100,7 +101,7 @@ private String getFileExtension(String fileName) { try { return fileName.substring(fileName.lastIndexOf(".")); } catch (StringIndexOutOfBoundsException e) { - throw new GeneralException(ErrorStatus.FEED_IMAGE_BAD_REQUEST); + throw new FeedImageHandler(ErrorStatus.FEED_IMAGE_BAD_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 ef711a6..39c3e77 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 @@ -1,7 +1,7 @@ package com.onnoff.onnoff.domain.off.memoir.service; import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; -import com.onnoff.onnoff.apiPayload.exception.GeneralException; +import com.onnoff.onnoff.apiPayload.exception.handler.MemoirHandler; import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.off.memoir.dto.MemoirRequestDTO; import com.onnoff.onnoff.domain.off.memoir.entity.Memoir; @@ -38,19 +38,19 @@ public class MemoirServiceImpl implements MemoirService { public Memoir writeMemoir(MemoirRequestDTO.MemoirWriteDTO request) { User user = UserContext.getUser(); if (memoirRepository.findByUserAndDate(user, request.getDate()).isPresent()) { - throw new GeneralException(ErrorStatus.MEMOIR_EXIST); + throw new MemoirHandler(ErrorStatus.MEMOIR_EXIST); } Memoir newMemoir = Memoir.builder() .date(request.getDate()) - .emoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new GeneralException(ErrorStatus.EMOTICON_NOT_FOUND))) + .emoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new MemoirHandler(ErrorStatus.EMOTICON_NOT_FOUND))) .isBookmarked(false) .build(); List newMemoirAnswerList = request.getMemoirAnswerList().stream() .map(memoirAnswer -> MemoirAnswer.builder() .answer(memoirAnswer.getAnswer().trim()) - .memoirQuestion(memoirQuestionRepository.findById(memoirAnswer.getQuestionId()).orElseThrow(() -> new GeneralException(ErrorStatus.QUESTION_NOT_FOUND))) + .memoirQuestion(memoirQuestionRepository.findById(memoirAnswer.getQuestionId()).orElseThrow(() -> new MemoirHandler(ErrorStatus.QUESTION_NOT_FOUND))) .memoir(newMemoir) .build()) .collect(Collectors.toList()); @@ -71,7 +71,7 @@ public Memoir getMemoirPreview(LocalDate date) { @Override @Transactional(readOnly = true) public Memoir getMemoir(Long memoirId) { - return memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + return memoirRepository.findById(memoirId).orElseThrow(() -> new MemoirHandler(ErrorStatus.MEMOIR_NOT_FOUND)); } @Override @@ -84,14 +84,14 @@ public Page getBookmarkedMemoir(Integer pageNumber) { @Override @Transactional public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO request) { - Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new MemoirHandler(ErrorStatus.MEMOIR_NOT_FOUND)); - memoir.setEmoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new GeneralException(ErrorStatus.EMOTICON_NOT_FOUND))); + memoir.setEmoticon(emoticonRepository.findById(request.getEmoticonId()).orElseThrow(() -> new MemoirHandler(ErrorStatus.EMOTICON_NOT_FOUND))); for (MemoirRequestDTO.MemoirUpdateAnswerDTO memoirAnswer : request.getMemoirAnswerList()) { - MemoirAnswer findMemoirAnswer = memoirAnswerRepository.findById(memoirAnswer.getAnswerId()).orElseThrow(() -> new GeneralException(ErrorStatus.ANSWER_NOT_FOUND)); + MemoirAnswer findMemoirAnswer = memoirAnswerRepository.findById(memoirAnswer.getAnswerId()).orElseThrow(() -> new MemoirHandler(ErrorStatus.ANSWER_NOT_FOUND)); if (findMemoirAnswer.getMemoir() != memoir) { - throw new GeneralException(ErrorStatus.ANSWER_BAD_MATCH); + throw new MemoirHandler(ErrorStatus.ANSWER_BAD_MATCH); } findMemoirAnswer.setAnswer(memoirAnswer.getAnswer().trim()); } @@ -102,7 +102,7 @@ public Memoir modifyMemoir(Long memoirId, MemoirRequestDTO.MemoirUpdateDTO reque @Override @Transactional public Memoir bookmarkMemoir(Long memoirId) { - Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new MemoirHandler(ErrorStatus.MEMOIR_NOT_FOUND)); memoir.setIsBookmarked(memoir.getIsBookmarked().equals(false)); return memoir; @@ -111,7 +111,7 @@ public Memoir bookmarkMemoir(Long memoirId) { @Override @Transactional public Long deleteMemoir(Long memoirId) { - Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMOIR_NOT_FOUND)); + Memoir memoir = memoirRepository.findById(memoirId).orElseThrow(() -> new MemoirHandler(ErrorStatus.MEMOIR_NOT_FOUND)); memoirRepository.delete(memoir); return memoir.getId();