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/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/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..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,8 +38,8 @@ 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.setContent(request.getContent()); + 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/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/feedImage/service/FeedImageServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/off/feedImage/service/FeedImageServiceImpl.java index d7259b0..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; @@ -32,6 +33,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; @@ -64,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); @@ -73,7 +77,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()); @@ -97,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/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)); } 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..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()) - .memoirQuestion(memoirQuestionRepository.findById(memoirAnswer.getQuestionId()).orElseThrow(() -> new GeneralException(ErrorStatus.QUESTION_NOT_FOUND))) + .answer(memoirAnswer.getAnswer().trim()) + .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,16 +84,16 @@ 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()); + findMemoirAnswer.setAnswer(memoirAnswer.getAnswer().trim()); } return memoir; @@ -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(); 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)) 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}