Skip to content

Commit

Permalink
feat: 수정 API 세분화
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjm9841 committed Feb 3, 2024
1 parent 22b7441 commit bbd9bee
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "이미 해당 위치에 업로드된 워라벨 피드 사진이 있습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,24 @@ public ApiResponse<List<FeedResponseDTO.FeedResultDTO>> getFeed(@RequestParam(na
return ApiResponse.onSuccess(feedList.stream().map(FeedConverter::toFeedResultDTO).toList());
}

@PatchMapping("/feeds")
@Operation(summary = "워라벨 피드 수정 API", description = "기존의 워라벨 피드를 수정하는 API입니다.")
public ApiResponse<FeedResponseDTO.FeedResultDTO> modifyFeed(@RequestBody @Valid FeedRequestDTO.ModifyFeedDTO request) {
Feed feed = feedService.modifyFeed(request);
@PatchMapping("/feeds/{feedId}")
@Operation(summary = "워라벨 피드 수정 API", description = "워라벨 피드의 내용을 수정하는 API입니다.")
public ApiResponse<FeedResponseDTO.FeedResultDTO> 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<FeedResponseDTO.FeedResultDTO> 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<FeedResponseDTO.FeedResultDTO> checkFeed(@PathVariable(name = "feedId") Long feedId) {
Feed feed = feedService.checkFeed(feedId);
return ApiResponse.onSuccess(FeedConverter.toFeedResultDTO(feed));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
20 changes: 10 additions & 10 deletions src/main/java/com/onnoff/onnoff/domain/off/feed/entity/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public interface FeedService {

List<Feed> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,12 +37,28 @@ public List<Feed> 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;
}

Expand Down

0 comments on commit bbd9bee

Please sign in to comment.