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 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(); } 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/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); } } 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);