diff --git a/src/main/java/com/cmc/suppin/event/crawl/controller/CommentApi.java b/src/main/java/com/cmc/suppin/event/crawl/controller/CommentApi.java index 49a88c5..578071a 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/controller/CommentApi.java +++ b/src/main/java/com/cmc/suppin/event/crawl/controller/CommentApi.java @@ -44,7 +44,7 @@ public ResponseEntity> get } @PostMapping("/draft-winners") - @Operation(summary = "조건별 당첨자 추첨 API(댓글 이벤트)", description = "주어진 조건에 따라 이벤트의 당첨자를 추첨합니다.") + @Operation(summary = "당첨자 랜덤 추첨 결과 리스트 조회 API(댓글 이벤트)", description = "주어진 조건에 따라 이벤트의 당첨자를 추첨합니다.") public ResponseEntity> drawWinners( @RequestBody @Valid CommentRequestDTO.WinnerRequestDTO request, @CurrentAccount Account account) { diff --git a/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CommentResponseDTO.java b/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CommentResponseDTO.java index a8f5fcf..2b3f462 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CommentResponseDTO.java +++ b/src/main/java/com/cmc/suppin/event/crawl/controller/dto/CommentResponseDTO.java @@ -41,4 +41,14 @@ public static class WinnerResponseDTO { private String endDate; private List winners; } + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class CommentEventWinners { + private String author; + private String commentText; + private String commentDate; + } } 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 581a6c2..5cf58be 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 @@ -64,5 +64,13 @@ public static CrawlResponseDTO.CrawlResultDTO toCrawlResultDTO(LocalDateTime cra .totalCommentCount(totalCommentCount) .build(); } + + public static CommentResponseDTO.CommentEventWinners toCommentEventWinners(Comment comment) { + return CommentResponseDTO.CommentEventWinners.builder() + .author(comment.getAuthor()) + .commentText(comment.getCommentText()) + .commentDate(comment.getCommentDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))) + .build(); + } } diff --git a/src/main/java/com/cmc/suppin/event/crawl/domain/Comment.java b/src/main/java/com/cmc/suppin/event/crawl/domain/Comment.java index e47fcb6..0ac7958 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/domain/Comment.java +++ b/src/main/java/com/cmc/suppin/event/crawl/domain/Comment.java @@ -41,8 +41,16 @@ public class Comment extends BaseDateTimeEntity { @Column(nullable = false) private LocalDateTime crawlTime; + @Builder.Default + @Column(nullable = false) + private boolean isWinner = false; + public void setCrawlTime(LocalDateTime crawlTime) { this.crawlTime = crawlTime; } + public void setIsWinner(boolean isWinner) { + this.isWinner = isWinner; + } + } diff --git a/src/main/java/com/cmc/suppin/event/crawl/domain/repository/CommentRepository.java b/src/main/java/com/cmc/suppin/event/crawl/domain/repository/CommentRepository.java index 0896ba0..872a5f1 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/domain/repository/CommentRepository.java +++ b/src/main/java/com/cmc/suppin/event/crawl/domain/repository/CommentRepository.java @@ -24,4 +24,6 @@ public interface CommentRepository extends JpaRepository { List findByEventIdAndCommentDateBetween(Long eventId, LocalDateTime start, LocalDateTime end); List findByEventIdAndCommentTextContaining(Long eventId, String keyword); + + List findByEventIdAndIsWinnerTrue(Long eventId); } diff --git a/src/main/java/com/cmc/suppin/event/crawl/service/CommentService.java b/src/main/java/com/cmc/suppin/event/crawl/service/CommentService.java index 2ad0965..0ca9d05 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/service/CommentService.java +++ b/src/main/java/com/cmc/suppin/event/crawl/service/CommentService.java @@ -54,6 +54,7 @@ public CommentResponseDTO.CrawledCommentListDTO getComments(Long eventId, String } // 당첨자 조건별 랜덤 추첨(댓글 이벤트) + @Transactional public CommentResponseDTO.WinnerResponseDTO drawWinners(CommentRequestDTO.WinnerRequestDTO request, String userId) { Member member = memberRepository.findByUserIdAndStatusNot(userId, UserStatus.DELETED) .orElseThrow(() -> new IllegalArgumentException("Member not found")); @@ -77,6 +78,12 @@ public CommentResponseDTO.WinnerResponseDTO drawWinners(CommentRequestDTO.Winner Collections.shuffle(filteredComments); List winners = filteredComments.stream().limit(request.getWinnerCount()).collect(Collectors.toList()); + // 당첨된 댓글의 isWinner 값을 true로 업데이트 + winners.forEach(winner -> { + winner.setIsWinner(true); + commentRepository.save(winner); // 업데이트된 Comment 엔티티를 저장 + }); + return CommentConverter.toWinnerResponseDTO(winners, request); } @@ -102,4 +109,15 @@ public List filterWinnersByKeyword(List getCommentEventWinners(Long eventId, String userId) { + Member member = memberRepository.findByUserIdAndStatusNot(userId, UserStatus.DELETED) + .orElseThrow(() -> new IllegalArgumentException("Member not found")); + + List winners = commentRepository.findByEventIdAndIsWinnerTrue(eventId); + + return winners.stream() + .map(CommentConverter::toCommentEventWinners) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/cmc/suppin/event/crawl/service/CrawlService.java b/src/main/java/com/cmc/suppin/event/crawl/service/CrawlService.java index 41730c6..6706393 100644 --- a/src/main/java/com/cmc/suppin/event/crawl/service/CrawlService.java +++ b/src/main/java/com/cmc/suppin/event/crawl/service/CrawlService.java @@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -46,8 +47,9 @@ public String checkExistingComments(String url, String userId) { List existingComments = commentRepository.findByUrl(url); if (!existingComments.isEmpty()) { - LocalDateTime firstCommentDate = existingComments.get(0).getCreatedAt(); - return "동일한 URL의 댓글을 " + firstCommentDate.toLocalDate() + " 일자에 수집한 이력이 있습니다."; + LocalDateTime firstCommentDate = existingComments.get(0).getCrawlTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + return "동일한 URL의 댓글을 " + firstCommentDate.format(formatter) + " 일자에 수집한 이력이 있습니다."; } return null; @@ -63,10 +65,14 @@ public CrawlResponseDTO.CrawlResultDTO crawlYoutubeComments(String url, Long eve if (forceUpdate) { // 기존 댓글 삭제 commentRepository.deleteByUrlAndEventId(url, eventId); + + // 삭제 후, 확인을 위한 로그 출력 또는 추가 검증 + List deletedComments = commentRepository.findByUrlAndEventId(url, eventId); + if (!deletedComments.isEmpty()) { + throw new RuntimeException("기존 댓글 삭제에 실패했습니다."); + } } else { // 기존 댓글이 존재하는 경우: 크롤링을 중지하고 예외를 던집니다. - // 기존 댓글이 존재하지 않는 경우: 새로운 댓글을 크롤링하고 이를 DB에 저장합니다. - List existingComments = commentRepository.findByUrlAndEventId(url, eventId); if (!existingComments.isEmpty()) { throw new CrawlException(CrawlErrorCode.DUPLICATE_URL); @@ -110,7 +116,7 @@ public CrawlResponseDTO.CrawlResultDTO crawlYoutubeComments(String url, Long eve while (System.currentTimeMillis() < endTime) { jsExecutor.executeScript("window.scrollTo(0, document.documentElement.scrollHeight);"); - Thread.sleep(1000); // 1초 대기 + Thread.sleep(3000); // 3초 대기 String pageSource = driver.getPageSource(); Document doc = Jsoup.parse(pageSource); @@ -149,5 +155,6 @@ public CrawlResponseDTO.CrawlResultDTO crawlYoutubeComments(String url, Long eve } return CommentConverter.toCrawlResultDTO(LocalDateTime.now(), uniqueComments.size()); } + } diff --git a/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java b/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java index ad5b034..833902f 100644 --- a/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java +++ b/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java @@ -1,10 +1,14 @@ package com.cmc.suppin.event.events.controller; +import com.cmc.suppin.event.crawl.controller.dto.CommentResponseDTO; +import com.cmc.suppin.event.crawl.service.CommentService; import com.cmc.suppin.event.events.controller.dto.EventRequestDTO; import com.cmc.suppin.event.events.controller.dto.EventResponseDTO; import com.cmc.suppin.event.events.converter.EventConverter; import com.cmc.suppin.event.events.domain.Event; import com.cmc.suppin.event.events.service.EventService; +import com.cmc.suppin.event.survey.controller.dto.SurveyResponseDTO; +import com.cmc.suppin.event.survey.service.SurveyService; import com.cmc.suppin.global.response.ApiResponse; import com.cmc.suppin.global.response.ResponseCode; import com.cmc.suppin.global.security.reslover.Account; @@ -29,6 +33,8 @@ public class EventApi { private final EventService eventService; + private final CommentService commentService; + private final SurveyService surveyService; @GetMapping("/all") @Operation(summary = "전체 이벤트 조회 API", description = "사용자의 모든 이벤트와 설문 및 댓글 수를 조회합니다.") @@ -66,4 +72,24 @@ public ResponseEntity> deleteEvent(@PathVariable("eventId") Lo eventService.deleteEvent(eventId, account.userId()); return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS)); } + + @GetMapping("/comment-winners") + @Operation(summary = "댓글 이벤트 당첨자 조회 API", description = "댓글 이벤트의 당첨자 리스트를 조회합니다.") + public ResponseEntity>> getCommentEventWinners( + @RequestParam("eventId") Long eventId, + @CurrentAccount Account account) { + + List winners = commentService.getCommentEventWinners(eventId, account.userId()); + return ResponseEntity.ok(ApiResponse.of(winners)); + } + + @GetMapping("/survey-winners") + @Operation(summary = "설문 이벤트 당첨자 조회 API", description = "설문 이벤트의 당첨자 리스트를 조회합니다.") + public ResponseEntity>> getSurveyEventWinners( + @RequestParam("surveyId") Long surveyId, + @CurrentAccount Account account) { + + List winners = surveyService.getSurveyEventWinners(surveyId, account.userId()); + return ResponseEntity.ok(ApiResponse.of(winners)); + } } 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 a4219cf..81f9b21 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 @@ -47,7 +47,7 @@ public ResponseEntity> getSurvey( if (uuid != null) { response = surveyService.getSurveyByUuid(uuid); } else if (surveyId != null) { - response = surveyService.getSurvey(surveyId); + response = surveyService.getSurveyBySurveyId(surveyId); } else { throw new IllegalArgumentException("Either surveyId or uuid must be provided"); } diff --git a/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyRequestDTO.java b/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyRequestDTO.java index 992e07b..42b8654 100644 --- a/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyRequestDTO.java +++ b/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyRequestDTO.java @@ -4,12 +4,12 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; import java.util.List; public class SurveyRequestDTO { @@ -22,6 +22,7 @@ public class SurveyRequestDTO { public static class SurveyCreateDTO { @NotNull private Long eventId; + private String consentFormHtml; // 개인정보 수집 동의서 HTML 필드 private List personalInfoOptionList; private List questionList; @@ -107,9 +108,11 @@ public static class RandomSelectionRequestDTO { @NotNull private Integer winnerCount; @NotNull - private LocalDateTime startDate; + @Pattern(regexp = "\\d{4}\\. \\d{2}\\. \\d{2} \\d{2}:\\d{2}", message = "날짜 형식은 yyyy. MM. dd HH:mm 이어야 합니다.") + private String startDate; @NotNull - private LocalDateTime endDate; + @Pattern(regexp = "\\d{4}\\. \\d{2}\\. \\d{2} \\d{2}:\\d{2}", message = "날짜 형식은 yyyy. MM. dd HH:mm 이어야 합니다.") + private String endDate; @NotNull private Integer minLength; @NotNull diff --git a/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyResponseDTO.java b/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyResponseDTO.java index a70df15..d31b596 100644 --- a/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyResponseDTO.java +++ b/src/main/java/com/cmc/suppin/event/survey/controller/dto/SurveyResponseDTO.java @@ -31,6 +31,7 @@ public static class SurveyResultDTO { private String startDate; private String endDate; private String announcementDate; + private String consentFormHtml; private List personalInfoOptions; private List questions; @@ -128,4 +129,14 @@ public static class AnswerDetailDTO { private List selectedOptions; // 객관식 질문의 경우 선택된 옵션 리스트 } } + + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class SurveyEventWinners { + private String name; + private List answers; + } } diff --git a/src/main/java/com/cmc/suppin/event/survey/converter/SurveyConverter.java b/src/main/java/com/cmc/suppin/event/survey/converter/SurveyConverter.java index 498f47f..47fdfe0 100644 --- a/src/main/java/com/cmc/suppin/event/survey/converter/SurveyConverter.java +++ b/src/main/java/com/cmc/suppin/event/survey/converter/SurveyConverter.java @@ -6,15 +6,18 @@ import com.cmc.suppin.event.survey.domain.*; import org.springframework.data.domain.Page; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; public class SurveyConverter { - public static Survey toSurveyEntity(Event event, String uuid) { + public static Survey toSurveyEntity(Event event, String uuid, String consentFormHtml) { return Survey.builder() .event(event) .uuid(uuid) + .consentFormHtml(consentFormHtml) .build(); } @@ -68,11 +71,13 @@ public static SurveyResponseDTO.SurveyResultDTO toSurveyResultDTO(Survey survey, .startDate(event.getStartDate().toString()) .endDate(event.getEndDate().toString()) .announcementDate(event.getAnnouncementDate().toString()) + .consentFormHtml(survey.getConsentFormHtml()) .personalInfoOptions(personalInfoOptions) .questions(questions) .build(); } + public static SurveyResponseDTO.SurveyAnswerResultDTO toSurveyAnswerResultDTO(Question question, Page answersPage) { List answers = answersPage.stream() .map(answer -> SurveyResponseDTO.SurveyAnswerResultDTO.AnswerDTO.builder() @@ -120,10 +125,12 @@ public static AnswerOption toAnswerOption(SurveyRequestDTO.SurveyAnswerDTO.Answe } public static SurveyResponseDTO.RandomSelectionResponseDTO.SelectionCriteriaDTO toSelectionCriteriaDTO(SurveyRequestDTO.RandomSelectionRequestDTO request) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy. MM. dd HH:mm"); + return SurveyResponseDTO.RandomSelectionResponseDTO.SelectionCriteriaDTO.builder() .winnerCount(request.getWinnerCount()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) + .startDate(LocalDateTime.parse(request.getStartDate(), formatter)) + .endDate(LocalDateTime.parse(request.getEndDate(), formatter)) .minLength(request.getMinLength()) .keywords(request.getKeywords()) .build(); @@ -154,4 +161,20 @@ public static SurveyResponseDTO.WinnerDetailDTO toWinnerDetailDTO(AnonymousParti .answers(answers) .build(); } + + public static SurveyResponseDTO.SurveyEventWinners toSurveyEventWinners(AnonymousParticipant participant) { + return SurveyResponseDTO.SurveyEventWinners.builder() + .name(participant.getName()) + .answers(participant.getAnswerList().stream() + .map(answer -> SurveyResponseDTO.WinnerDetailDTO.AnswerDetailDTO.builder() + .questionText(answer.getQuestion().getQuestionText()) + .answerText(answer.getAnswerText()) + .selectedOptions(answer.getAnswerOptionList().stream() + .map(answerOption -> answerOption.getQuestionOption().getOptionText()) + .collect(Collectors.toList())) + .build()) + .collect(Collectors.toList())) + .build(); + } + } diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/AnonymousParticipant.java b/src/main/java/com/cmc/suppin/event/survey/domain/AnonymousParticipant.java index 5bdac04..e75d3ea 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/AnonymousParticipant.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/AnonymousParticipant.java @@ -25,6 +25,7 @@ public class AnonymousParticipant extends BaseDateTimeEntity { private Survey survey; @OneToMany(mappedBy = "anonymousParticipant") + @Builder.Default private List answerList = new ArrayList<>(); private String name; @@ -41,11 +42,19 @@ public class AnonymousParticipant extends BaseDateTimeEntity { @Column(nullable = false) private Boolean isAgreed; - private Boolean isWinner; + @Builder.Default + @Column(nullable = false) + private Boolean isWinner = false; - private Boolean isChecked; + @Builder.Default + @Column(nullable = false) + private Boolean isChecked = false; public void setIsWinner(Boolean isWinner) { this.isWinner = isWinner; } + + public void setIsChecked(Boolean isChecked) { + this.isChecked = isChecked; + } } diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/Answer.java b/src/main/java/com/cmc/suppin/event/survey/domain/Answer.java index 4cbd141..073f89e 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/Answer.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/Answer.java @@ -30,6 +30,7 @@ public class Answer extends BaseDateTimeEntity { private AnonymousParticipant anonymousParticipant; @OneToMany(mappedBy = "answer") + @Builder.Default private List answerOptionList = new ArrayList<>(); @Column(columnDefinition = "TEXT") diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/Question.java b/src/main/java/com/cmc/suppin/event/survey/domain/Question.java index 98c86a5..d5b1d92 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/Question.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/Question.java @@ -25,9 +25,11 @@ public class Question { private Survey survey; @OneToMany(mappedBy = "question") + @Builder.Default private List questionOptionList = new ArrayList<>(); @OneToMany(mappedBy = "question") + @Builder.Default private List answerList = new ArrayList<>(); @Enumerated(EnumType.STRING) diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/QuestionOption.java b/src/main/java/com/cmc/suppin/event/survey/domain/QuestionOption.java index d21d337..44fc85a 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/QuestionOption.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/QuestionOption.java @@ -27,6 +27,7 @@ public class QuestionOption { private String optionText; @OneToMany(mappedBy = "questionOption") + @Builder.Default private List answerOptionList = new ArrayList<>(); } diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/Survey.java b/src/main/java/com/cmc/suppin/event/survey/domain/Survey.java index f359fb1..d9d797e 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/Survey.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/Survey.java @@ -26,12 +26,15 @@ public class Survey extends BaseDateTimeEntity { private Event event; @OneToMany(mappedBy = "survey", cascade = CascadeType.ALL, orphanRemoval = true) + @Builder.Default private List personalInfoList = new ArrayList<>(); @OneToMany(mappedBy = "survey") + @Builder.Default private List questionList = new ArrayList<>(); @OneToMany(mappedBy = "survey") + @Builder.Default private List anonymousParticipantList = new ArrayList<>(); @Column(columnDefinition = "TEXT") @@ -39,5 +42,8 @@ public class Survey extends BaseDateTimeEntity { @Column(nullable = false, updatable = false, unique = true) private String uuid; + + @Column(columnDefinition = "TEXT") + private String consentFormHtml; } diff --git a/src/main/java/com/cmc/suppin/event/survey/domain/repository/AnonymousParticipantRepository.java b/src/main/java/com/cmc/suppin/event/survey/domain/repository/AnonymousParticipantRepository.java index 6e94add..9d894dc 100644 --- a/src/main/java/com/cmc/suppin/event/survey/domain/repository/AnonymousParticipantRepository.java +++ b/src/main/java/com/cmc/suppin/event/survey/domain/repository/AnonymousParticipantRepository.java @@ -1,6 +1,7 @@ package com.cmc.suppin.event.survey.domain.repository; import com.cmc.suppin.event.survey.domain.AnonymousParticipant; +import com.cmc.suppin.event.survey.domain.Survey; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -13,4 +14,5 @@ public interface AnonymousParticipantRepository extends JpaRepository findBySurveyIdAndIsWinnerTrue(Long surveyId); + List findBySurveyAndIsWinnerTrue(Survey survey); } 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 85148cf..e1b2d26 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 @@ -20,6 +20,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -54,7 +56,7 @@ public SurveyResponseDTO.SurveyCreateResponse createSurvey(SurveyRequestDTO.Surv // Survey 엔티티 생성 및 저장 String uuid = UUID.randomUUID().toString(); - Survey survey = SurveyConverter.toSurveyEntity(event, uuid); + Survey survey = SurveyConverter.toSurveyEntity(event, uuid, request.getConsentFormHtml()); surveyRepository.save(survey); // 각 개인정보 항목 처리 및 저장 @@ -84,7 +86,7 @@ public SurveyResponseDTO.SurveyCreateResponse createSurvey(SurveyRequestDTO.Surv // 생성된 설문지 조회 @Transactional(readOnly = true) - public SurveyResponseDTO.SurveyResultDTO getSurvey(Long surveyId) { + public SurveyResponseDTO.SurveyResultDTO getSurveyBySurveyId(Long surveyId) { Survey survey = surveyRepository.findById(surveyId) .orElseThrow(() -> new IllegalArgumentException("Survey not found")); @@ -172,8 +174,10 @@ public SurveyResponseDTO.RandomSelectionResponseDTO selectRandomWinners(SurveyRe .collect(Collectors.toList()); // 조건에 맞는 주관식 답변 조회 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy. MM. dd HH:mm"); + List eligibleAnswers = answerCustomRepository.findEligibleAnswers( - request.getQuestionId(), request.getStartDate(), request.getEndDate(), + request.getQuestionId(), LocalDateTime.parse(request.getStartDate(), formatter), LocalDateTime.parse(request.getEndDate(), formatter), request.getMinLength(), request.getKeywords()); // 랜덤 추첨 @@ -227,4 +231,19 @@ public void deleteWinners(Long surveyId) { anonymousParticipantRepository.save(participant); } } + + public List getSurveyEventWinners(Long surveyId, String userId) { + Member member = memberRepository.findByUserIdAndStatusNot(userId, UserStatus.DELETED) + .orElseThrow(() -> new IllegalArgumentException("Member not found")); + + Survey survey = surveyRepository.findById(surveyId) + .orElseThrow(() -> new IllegalArgumentException("Survey not found")); + + List winners = anonymousParticipantRepository.findBySurveyAndIsWinnerTrue(survey); + + return winners.stream() + .map(SurveyConverter::toSurveyEventWinners) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/cmc/suppin/member/domain/Member.java b/src/main/java/com/cmc/suppin/member/domain/Member.java index 8fd23dd..acea8ea 100644 --- a/src/main/java/com/cmc/suppin/member/domain/Member.java +++ b/src/main/java/com/cmc/suppin/member/domain/Member.java @@ -25,6 +25,7 @@ public class Member extends BaseDateTimeEntity { private Long id; @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + @Builder.Default private List eventList = new ArrayList<>(); @Column(columnDefinition = "VARCHAR(30)", nullable = false) @@ -41,7 +42,7 @@ public class Member extends BaseDateTimeEntity { @Column(columnDefinition = "VARCHAR(13)", nullable = false) private String phoneNumber; - + @Enumerated(EnumType.STRING) private UserRole role;