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 7da0f93..71a74fd 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 @@ -40,7 +40,6 @@ public enum ErrorStatus implements BaseErrorCode { // 피드 관련 에러 FEED_NOT_FOUND(HttpStatus.BAD_REQUEST, "FEED4001", "해당하는 워라벨 피드가 없습니다."), - FEED_NOT_BLANK(HttpStatus.BAD_REQUEST, "FEED4002", "워라벨 피드 내용은 공백일 수 없습니다."), // 피드 사진 관련 에러 FEED_IMAGE_EXIST(HttpStatus.BAD_REQUEST, "FEEDIMAGE4001", "이미 해당 위치에 업로드된 워라벨 피드 사진이 있습니다."), 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 c44bf19..9c4769b 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 @@ -34,10 +34,24 @@ public ApiResponse> getFeed(@RequestParam(na return ApiResponse.onSuccess(feedList.stream().map(FeedConverter::toFeedResultDTO).toList()); } - @PatchMapping("/feeds") - @Operation(summary = "워라벨 피드 수정 API", description = "기존의 워라벨 피드를 수정하는 API입니다.") - public ApiResponse modifyFeed(@RequestBody @Valid FeedRequestDTO.ModifyFeedDTO request) { - Feed feed = feedService.modifyFeed(request); + @PatchMapping("/feeds/{feedId}") + @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.toFeedResultDTO(feed)); + } + + @PatchMapping("/feeds/{feedId}/delay") + @Operation(summary = "워라벨 피드 내일로 미루기 API", description = "워라벨 피드의 날짜를 현재 기준 내일로 변경하는 API입니다.") + public ApiResponse delayFeed(@PathVariable(name = "feedId") Long feedId) { + Feed feed = feedService.delayFeed(feedId); + return ApiResponse.onSuccess(FeedConverter.toFeedResultDTO(feed)); + } + + @PatchMapping("/feeds/{feedId}/check") + @Operation(summary = "워라벨 피드 체크 및 해제 API", description = "워라벨 피드를 체크하거나 체크 해제하는 API입니다.") + public ApiResponse checkFeed(@PathVariable(name = "feedId") Long feedId) { + Feed feed = feedService.checkFeed(feedId); return ApiResponse.onSuccess(FeedConverter.toFeedResultDTO(feed)); } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/dto/FeedRequestDTO.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/dto/FeedRequestDTO.java index 3208c32..d626999 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/dto/FeedRequestDTO.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/dto/FeedRequestDTO.java @@ -22,11 +22,8 @@ public static class AddFeedDTO { @Getter public static class ModifyFeedDTO { - @NotNull - Long feedId; - LocalDate date; + @NotBlank @Size(max = 30) String content; - Boolean isChecked; } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java index 6a0fab2..655f9a2 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java @@ -30,15 +30,15 @@ public class Feed extends BaseEntity { @JoinColumn(name = "user_id") private User user; - public void updateFeed(LocalDate date, String content, Boolean isChecked) { - if (date != null) { - this.date = date; - } - if (content != null) { - this.content = content; - } - if (isChecked != null) { - this.isChecked = isChecked; - } + public void setContent(String content) { + this.content = content; + } + + public void setDate(LocalDate date) { + this.date = date; + } + + public void setIsChecked(Boolean isChecked) { + this.isChecked = isChecked; } } diff --git a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedService.java b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedService.java index deabce3..6b33acb 100644 --- a/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedService.java +++ b/src/main/java/com/onnoff/onnoff/domain/off/feed/service/FeedService.java @@ -13,7 +13,11 @@ public interface FeedService { List getFeed(LocalDate date); - Feed modifyFeed(FeedRequestDTO.ModifyFeedDTO request); + Feed modifyFeed(Long feedId, FeedRequestDTO.ModifyFeedDTO request); + + Feed delayFeed(Long feedId); + + Feed checkFeed(Long feedId); Long deleteFeed(Long feedId); } 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 f2a6512..d4f0485 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 @@ -8,7 +8,6 @@ import com.onnoff.onnoff.domain.off.feed.entity.Feed; import com.onnoff.onnoff.domain.off.feed.repository.FeedRepository; 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; @@ -38,12 +37,28 @@ public List getFeed(LocalDate date) { @Override @Transactional - public Feed modifyFeed(FeedRequestDTO.ModifyFeedDTO request) { - Feed feed = feedRepository.findById(request.getFeedId()).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); - if (request.getContent() != null && request.getContent().trim().isEmpty()) { - throw new GeneralException(ErrorStatus.FEED_NOT_BLANK); - } - feed.updateFeed(request.getDate(), request.getContent(), request.getIsChecked()); + public Feed modifyFeed(Long feedId, FeedRequestDTO.ModifyFeedDTO request) { + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + feed.setContent(request.getContent()); + + return feed; + } + + @Override + @Transactional + public Feed delayFeed(Long feedId) { + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + feed.setDate(LocalDate.now().plusDays(1)); + + return feed; + } + + @Override + @Transactional + public Feed checkFeed(Long feedId) { + Feed feed = feedRepository.findById(feedId).orElseThrow(() -> new GeneralException(ErrorStatus.FEED_NOT_FOUND)); + feed.setIsChecked(feed.getIsChecked().equals(false)); + return feed; }