From db3407ef76f385419705884a6eb96862d5143a37 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Tue, 13 Aug 2024 00:23:50 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EC=9C=A0=ED=8A=9C=EB=B8=8C=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=20=ED=81=AC=EB=A1=A4=EB=A7=81=20API=20respon?= =?UTF-8?q?se=20=EA=B0=92=20=EC=88=98=EC=A0=95(=EC=8B=9C=EA=B0=84,=20?= =?UTF-8?q?=EC=B4=9D=20=EB=8C=93=EA=B8=80=20=EC=88=98=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cmc/suppin/event/crawl/controller/CrawlApi.java | 7 ++++--- .../event/crawl/controller/dto/CrawlResponseDTO.java | 5 ++--- .../suppin/event/crawl/converter/CommentConverter.java | 8 ++++++++ .../com/cmc/suppin/event/crawl/service/CrawlService.java | 4 +++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cmc/suppin/event/crawl/controller/CrawlApi.java b/src/main/java/com/cmc/suppin/event/crawl/controller/CrawlApi.java index d2948e7..a8678ac 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/controller/CrawlApi.java +++ b/src/main/java/com/cmc/suppin/event/crawl/controller/CrawlApi.java @@ -1,5 +1,6 @@ package com.cmc.suppin.event.crawl.controller; +import com.cmc.suppin.event.crawl.controller.dto.CrawlResponseDTO; import com.cmc.suppin.event.crawl.service.CrawlService; import com.cmc.suppin.global.response.ApiResponse; import com.cmc.suppin.global.response.ResponseCode; @@ -51,9 +52,9 @@ public ResponseEntity> checkExistingComments(@RequestParam(" "크롤링하려는 URL이 중복되지 않았을 때의 요청이기 때문에, 새로운 댓글을 크롤링합니다.
" + "- DB에 기존 댓글이 존재하는 경우: 크롤링을 중지하고 예외를 던집니다.
" + "- DB에 기존 댓글이 존재하지 않는 경우: 새로운 댓글을 크롤링하고 이를 DB에 저장합니다.") - public ResponseEntity> crawlYoutubeComments(@RequestParam("url") String url, @RequestParam("eventId") Long eventId, @RequestParam("forceUpdate") boolean forceUpdate, @CurrentAccount Account account) { - crawlService.crawlYoutubeComments(url, eventId, account.userId(), forceUpdate); - return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS, "댓글 수집이 완료되었습니다.")); + public ResponseEntity> crawlYoutubeComments(@RequestParam("url") String url, @RequestParam("eventId") Long eventId, @RequestParam("forceUpdate") boolean forceUpdate, @CurrentAccount Account account) { + CrawlResponseDTO.CrawlResultDTO crawlResultDTO = crawlService.crawlYoutubeComments(url, eventId, account.userId(), forceUpdate); + return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS, crawlResultDTO)); } // @GetMapping("/count") diff --git a/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CrawlResponseDTO.java b/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CrawlResponseDTO.java index 2df078c..d96971a 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CrawlResponseDTO.java +++ b/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CrawlResponseDTO.java @@ -12,8 +12,7 @@ public class CrawlResponseDTO { @NoArgsConstructor @AllArgsConstructor public static class CrawlResultDTO { - private String author; - private String commentText; - private String date; + private String crawlingDate; + private int totalCommentCount; } } diff --git a/src/main/java/com/cmc/suppin/event/crawl/converter/CommentConverter.java b/src/main/java/com/cmc/suppin/event/crawl/converter/CommentConverter.java index 89871b6..e83d55e 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/converter/CommentConverter.java +++ b/src/main/java/com/cmc/suppin/event/crawl/converter/CommentConverter.java @@ -2,6 +2,7 @@ import com.cmc.suppin.event.crawl.controller.dto.CommentRequestDTO; import com.cmc.suppin.event.crawl.controller.dto.CommentResponseDTO; +import com.cmc.suppin.event.crawl.controller.dto.CrawlResponseDTO; import com.cmc.suppin.event.crawl.domain.Comment; import com.cmc.suppin.event.events.domain.Event; @@ -56,5 +57,12 @@ public static CommentResponseDTO.WinnerResponseDTO toWinnerResponseDTO(List new IllegalArgumentException("Member not found")); @@ -144,6 +145,7 @@ public void crawlYoutubeComments(String url, Long eventId, String userId, boolea } finally { driver.quit(); } + return CommentConverter.toCrawlResultDTO(LocalDateTime.now(), uniqueComments.size()); } }