From c86ea84d5c872d917589625eb99b61d93561b367 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Thu, 15 Aug 2024 10:02:51 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Refactor:=20=EC=84=A4=EB=AC=B8=EC=A7=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20URL=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=EC=A0=91=EA=B7=BC=20=ED=97=88=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/survey/controller/SurveyApi.java | 22 +++++++++++++++---- .../domain/repository/SurveyRepository.java | 5 +++-- .../event/survey/service/SurveyService.java | 9 ++++++++ .../security/config/WebSecurityConfig.java | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cmc/suppin/event/survey/controller/SurveyApi.java b/src/main/java/com/cmc/suppin/event/survey/controller/SurveyApi.java index abba461..a4219cf 100644 --- a/src/main/java/com/cmc/suppin/event/survey/controller/SurveyApi.java +++ b/src/main/java/com/cmc/suppin/event/survey/controller/SurveyApi.java @@ -34,10 +34,24 @@ public ResponseEntity> creat return ResponseEntity.ok(ApiResponse.of(response)); } - @GetMapping("/{surveyId}") - @Operation(summary = "설문지 조회 API", description = "생성된 설문지 전체 정보를 조회합니다. 자세한 요청 및 응답 형식은 노션 API 문서를 참고해주세요.") - public ResponseEntity> getSurvey(@PathVariable("surveyId") Long surveyId) { - SurveyResponseDTO.SurveyResultDTO response = surveyService.getSurvey(surveyId); + @GetMapping("/view") + @Operation(summary = "설문지 조회 API", description = "생성된 설문지 전체 정보를 조회합니다. surveyId와 uuid, 둘 중 하나로 요청할 수 있습니다.") + public ResponseEntity> getSurvey( + @Parameter(description = "required = false") + @RequestParam(value = "surveyId", required = false) Long surveyId, + @Parameter(description = "required = false") + @RequestParam(value = "uuid", required = false) String uuid) { + + SurveyResponseDTO.SurveyResultDTO response; + + if (uuid != null) { + response = surveyService.getSurveyByUuid(uuid); + } else if (surveyId != null) { + response = surveyService.getSurvey(surveyId); + } else { + throw new IllegalArgumentException("Either surveyId or uuid must be provided"); + } + return ResponseEntity.ok(ApiResponse.of(response)); } diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/repository/SurveyRepository.java b/src/main/java/com/cmc/suppin/event/survey/domain/repository/SurveyRepository.java index afb0fc2..ba0a5ea 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/repository/SurveyRepository.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/repository/SurveyRepository.java @@ -3,7 +3,8 @@ import com.cmc.suppin.event.survey.domain.Survey; import org.springframework.data.jpa.repository.JpaRepository; -public interface SurveyRepository extends JpaRepository { - +import java.util.Optional; +public interface SurveyRepository extends JpaRepository { + Optional findByUuid(String uuid); } diff --git a/src/main/java/com/cmc/suppin/event/survey/service/SurveyService.java b/src/main/java/com/cmc/suppin/event/survey/service/SurveyService.java index aff87de..85148cf 100644 --- a/src/main/java/com/cmc/suppin/event/survey/service/SurveyService.java +++ b/src/main/java/com/cmc/suppin/event/survey/service/SurveyService.java @@ -92,6 +92,15 @@ public SurveyResponseDTO.SurveyResultDTO getSurvey(Long surveyId) { return SurveyConverter.toSurveyResultDTO(survey, event); } + @Transactional(readOnly = true) + public SurveyResponseDTO.SurveyResultDTO getSurveyByUuid(String uuid) { + Survey survey = surveyRepository.findByUuid(uuid) + .orElseThrow(() -> new IllegalArgumentException("Survey not found for UUID: " + uuid)); + + Event event = survey.getEvent(); + return SurveyConverter.toSurveyResultDTO(survey, event); + } + // 설문 응답 저장 @Transactional public void saveSurveyAnswers(SurveyRequestDTO.SurveyAnswerDTO request) { diff --git a/src/main/java/com/cmc/suppin/global/security/config/WebSecurityConfig.java b/src/main/java/com/cmc/suppin/global/security/config/WebSecurityConfig.java index fcee56a..1c89e02 100644 --- a/src/main/java/com/cmc/suppin/global/security/config/WebSecurityConfig.java +++ b/src/main/java/com/cmc/suppin/global/security/config/WebSecurityConfig.java @@ -122,6 +122,7 @@ private RequestMatcher[] requestPermitAll() { antMatcher("/api/v1/members/join/**"), antMatcher("/api/v1/members/checkUserId"), antMatcher("/api/v1/members/checkEmail"), + antMatcher("/api/v1/survey/view/**"), antMatcher("/api/v1/survey/reply/**") // 설문조사 응답 시 적용 ); return requestMatchers.toArray(RequestMatcher[]::new); From ccfbd57eb17115268b7d45d31110ccd9055232e0 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Thu, 15 Aug 2024 10:19:44 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Refactor:=20=EC=A0=84=EC=B2=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20?= =?UTF-8?q?=EC=84=A4=EB=AC=B8=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20uuid=EA=B0=92=20=EC=9D=91=EB=8B=B5=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/events/controller/dto/EventResponseDTO.java | 3 ++- .../cmc/suppin/event/events/converter/EventConverter.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java b/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java index 2bb0ca8..656409f 100644 --- a/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java +++ b/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java @@ -26,7 +26,8 @@ public static class EventInfoDTO { private Integer surveyCount; private Integer commentCount; private EventStatus status; - + private Long surveyId; + private String uuid; } @Builder diff --git a/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java b/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java index c0e1bfd..330e709 100644 --- a/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java +++ b/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java @@ -3,6 +3,7 @@ import com.cmc.suppin.event.events.controller.dto.EventRequestDTO; import com.cmc.suppin.event.events.controller.dto.EventResponseDTO; import com.cmc.suppin.event.events.domain.Event; +import com.cmc.suppin.event.survey.domain.Survey; import com.cmc.suppin.global.enums.EventType; import com.cmc.suppin.member.domain.Member; @@ -64,6 +65,11 @@ public static EventResponseDTO.EventInfoDTO toEventInfoDTO(Event event) { .mapToInt(survey -> survey.getAnonymousParticipantList().size()) .sum(); + // 이벤트에 설문이 존재하는 경우 surveyId와 uuid 값을 설정 + Survey survey = event.getSurveyList().stream().findFirst().orElse(null); + Long surveyId = (survey != null) ? survey.getId() : null; + String uuid = (survey != null) ? survey.getUuid() : null; + return EventResponseDTO.EventInfoDTO.builder() .eventId(event.getId()) .type(event.getType()) @@ -75,6 +81,8 @@ public static EventResponseDTO.EventInfoDTO toEventInfoDTO(Event event) { .surveyCount(surveyAnswerCount) .commentCount(event.getCommentList().size()) .status(event.getStatus()) + .surveyId(surveyId) + .uuid(uuid) .build(); } From a49819cf991415f78258d92ffe4e0b0179b6ed30 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Thu, 15 Aug 2024 10:37:04 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Refactor:=20API=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EB=A7=88=EB=8B=A4=20crawlTime=20=EA=B0=B1=EC=8B=A0=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/crawl/controller/dto/CrawlResponseDTO.java | 2 +- .../cmc/suppin/event/crawl/converter/CommentConverter.java | 2 +- .../java/com/cmc/suppin/event/crawl/domain/Comment.java | 7 +++++++ .../com/cmc/suppin/event/crawl/service/CommentService.java | 2 +- .../com/cmc/suppin/event/crawl/service/CrawlService.java | 4 +++- 5 files changed, 13 insertions(+), 4 deletions(-) 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 d96971a..33a950a 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,7 +12,7 @@ public class CrawlResponseDTO { @NoArgsConstructor @AllArgsConstructor public static class CrawlResultDTO { - private String crawlingDate; + private String crawlTime; 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 e83d55e..581a6c2 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 @@ -60,7 +60,7 @@ public static CommentResponseDTO.WinnerResponseDTO toWinnerResponseDTO(List Date: Thu, 15 Aug 2024 10:39:34 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Chore:=20CORS=20origin=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cmc/suppin/global/security/config/WebMvcConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cmc/suppin/global/security/config/WebMvcConfig.java b/src/main/java/com/cmc/suppin/global/security/config/WebMvcConfig.java index 73ea984..ea879da 100644 --- a/src/main/java/com/cmc/suppin/global/security/config/WebMvcConfig.java +++ b/src/main/java/com/cmc/suppin/global/security/config/WebMvcConfig.java @@ -39,7 +39,8 @@ private String[] getAllowOrigins() { "https://api.suppin.store", "https://suppin.store", "http://192.168.200.120:3000", // 테스트 디바이스 IP 허용 - "https://coherent-midge-probably.ngrok-free.app" + "https://coherent-midge-probably.ngrok-free.app", + "https://suppin-servey.vercel.app/" ).toArray(String[]::new); } }