From 419ad780e648d60a5df533a947f00608f38196c9 Mon Sep 17 00:00:00 2001 From: hyuk jin Kim Date: Tue, 16 Jul 2024 20:57:51 +0900 Subject: [PATCH] =?UTF-8?q?Bug:=20=EC=B6=A9=EB=8F=8C=20=ED=95=B4=EA=B2=B0?= =?UTF-8?q?=20(#79)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/application/diary/DiaryService.java | 2 ++ .../server/application/reply/ReplyRetriever.java | 5 +++++ .../server/application/reply/ReplyService.java | 8 ++++++++ .../server/presentation/api/DiaryController.java | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java b/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java index f6c2dc0..feb69e0 100644 --- a/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java +++ b/src/main/java/com/donkeys_today/server/application/diary/DiaryService.java @@ -41,6 +41,8 @@ public class DiaryService { private final DiaryRetriever diaryRetriever; private final ReplyService replyService; private final DiaryCreator diaryCreator; + private final DiaryRemover diaryRemover; + public DiaryListGetResponse getDiaryList(int year, int month) { Map> diariesByDate = getDiariesMap(year, month); Map repliesByDate = getRepliesMap(year, month); diff --git a/src/main/java/com/donkeys_today/server/application/reply/ReplyRetriever.java b/src/main/java/com/donkeys_today/server/application/reply/ReplyRetriever.java index b892d30..299678b 100644 --- a/src/main/java/com/donkeys_today/server/application/reply/ReplyRetriever.java +++ b/src/main/java/com/donkeys_today/server/application/reply/ReplyRetriever.java @@ -30,4 +30,9 @@ public List getRepliesByUserAndDateBetween(User user, LocalDate start, Lo return replyRepository.findByUserIdAndDiaryCreatedDateBetween(user.getId(), start, end); } + + public boolean isReplyExist(Long userId, int year, int month, int date) { + LocalDate localDate = LocalDate.of(year, month, date); + return replyRepository.existsByUserIdAndDiaryCreatedDate(userId, localDate); + } } diff --git a/src/main/java/com/donkeys_today/server/application/reply/ReplyService.java b/src/main/java/com/donkeys_today/server/application/reply/ReplyService.java index 771e3f8..1f3daec 100644 --- a/src/main/java/com/donkeys_today/server/application/reply/ReplyService.java +++ b/src/main/java/com/donkeys_today/server/application/reply/ReplyService.java @@ -28,4 +28,12 @@ public List getRepliesByUserAndDateBetween(User user, LocalDate start, Lo return replyRetriever.getRepliesByUserAndDateBetween(user, start, end); } + + public boolean isReplyExist(Long userId, int year, int month, int date) { + return replyRetriever.isReplyExist(userId, year, month, date); + } + + public void removeReply(Long userId, int year, int month, int date) { + replyRemover.removeReplyUserIdAndDate(userId, year, month, date); + } } diff --git a/src/main/java/com/donkeys_today/server/presentation/api/DiaryController.java b/src/main/java/com/donkeys_today/server/presentation/api/DiaryController.java index 49a83ae..cdb5afb 100644 --- a/src/main/java/com/donkeys_today/server/presentation/api/DiaryController.java +++ b/src/main/java/com/donkeys_today/server/presentation/api/DiaryController.java @@ -61,4 +61,12 @@ ResponseEntity> getDiaryCreatedTime( @RequestParam @Parameter(name = "달", description = "조회할 달", required = true) final int month, @RequestParam @Parameter(name = "일", description = "조회할 일", required = true) final int day ); + + @Operation(summary = "일기 삭제 ", description = "년/월/일을 이용하여 일기와 답변까지 삭제합니다. 만약 답변이 요청 중인 상태라면, 답변을 요청하지 않습니다.") + @DeleteMapping("/diary") + ResponseEntity> deleteDiary( + @RequestParam @Parameter(name = "연도", description = "삭제할 연도", required = true) final int year, + @RequestParam @Parameter(name = "달", description = "삭제할 달", required = true) final int month, + @RequestParam @Parameter(name = "일", description = "삭제할 일", required = true) final int day + ); }