Skip to content

Commit

Permalink
Merge pull request #42 from Central-MakeUs/refactor/37
Browse files Browse the repository at this point in the history
Refactor/37: 이벤트 관련 API 리팩토링-3
  • Loading branch information
yxhwxn authored Aug 16, 2024
2 parents 535e487 + 58650d5 commit 94e8308
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 56 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/cmc/suppin/SuppinApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
public class SuppinApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public ResponseEntity<ApiResponse<SurveyResponseDTO.SurveyCreateResponse>> creat

@GetMapping("/view")
@Operation(summary = "설문지 조회 API", description = "생성된 설문지 전체 정보를 조회합니다. surveyId와 uuid, 둘 중 하나로 요청할 수 있습니다.")
public ResponseEntity<ApiResponse<SurveyResponseDTO.SurveyResultDTO>> getSurvey(
public ResponseEntity<ApiResponse<SurveyResponseDTO.SurveyViewDTO>> 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;
SurveyResponseDTO.SurveyViewDTO response;

if (uuid != null) {
response = surveyService.getSurveyByUuid(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static class SurveyAnswerDTO {
@Builder
public static class ParticipantDTO {
private String name;
private String address;
private String fullAddress;
private String extraAddress;
private String email;
private String phoneNumber;
private String instagramId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class SurveyCreateResponse {
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class SurveyResultDTO {
public static class SurveyViewDTO {
private Long eventId;
private String eventTitle;
private String eventDescription;
Expand All @@ -33,13 +33,15 @@ public static class SurveyResultDTO {
private String announcementDate;
private String consentFormHtml;
private List<PersonalInfoOptionDTO> personalInfoOptions;
private Long surveyId;
private List<QuestionDTO> questions;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class QuestionDTO {
private Long questionId;
private QuestionType questionType;
private String questionText;
private List<String> options;
Expand All @@ -50,7 +52,7 @@ public static class QuestionDTO {
@AllArgsConstructor
@Builder
public static class PersonalInfoOptionDTO {
private String optionName;
private String option;
}
}

Expand Down Expand Up @@ -114,7 +116,8 @@ public static class SelectionCriteriaDTO {
public static class WinnerDetailDTO {
private String name;
private String phoneNumber;
private String address;
private String fullAddress;
private String extraAddress;
private String email;
private String instagramId;
private List<AnswerDetailDTO> answers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public static List<PersonalInfoCollectOption> toPersonalInfoCollectOptionEntitie
.collect(Collectors.toList());
}

public static SurveyResponseDTO.SurveyResultDTO toSurveyResultDTO(Survey survey, Event event) {
List<SurveyResponseDTO.SurveyResultDTO.PersonalInfoOptionDTO> personalInfoOptions = survey.getPersonalInfoList().stream()
.map(option -> SurveyResponseDTO.SurveyResultDTO.PersonalInfoOptionDTO.builder()
.optionName(option.getOptionName())
public static SurveyResponseDTO.SurveyViewDTO toSurveyViewResultDTO(Survey survey, Event event) {
List<SurveyResponseDTO.SurveyViewDTO.PersonalInfoOptionDTO> personalInfoOptions = survey.getPersonalInfoList().stream()
.map(option -> SurveyResponseDTO.SurveyViewDTO.PersonalInfoOptionDTO.builder()
.option(option.getOptionName())
.build())
.collect(Collectors.toList());

List<SurveyResponseDTO.SurveyResultDTO.QuestionDTO> questions = survey.getQuestionList().stream()
.map(question -> SurveyResponseDTO.SurveyResultDTO.QuestionDTO.builder()
List<SurveyResponseDTO.SurveyViewDTO.QuestionDTO> questions = survey.getQuestionList().stream()
.map(question -> SurveyResponseDTO.SurveyViewDTO.QuestionDTO.builder()
.questionId(question.getId())
.questionType(question.getQuestionType())
.questionText(question.getQuestionText())
.options(question.getQuestionOptionList().stream()
Expand All @@ -64,7 +65,7 @@ public static SurveyResponseDTO.SurveyResultDTO toSurveyResultDTO(Survey survey,
.build())
.collect(Collectors.toList());

return SurveyResponseDTO.SurveyResultDTO.builder()
return SurveyResponseDTO.SurveyViewDTO.builder()
.eventId(event.getId())
.eventTitle(event.getTitle())
.eventDescription(event.getDescription())
Expand All @@ -73,6 +74,7 @@ public static SurveyResponseDTO.SurveyResultDTO toSurveyResultDTO(Survey survey,
.announcementDate(event.getAnnouncementDate().toString())
.consentFormHtml(survey.getConsentFormHtml())
.personalInfoOptions(personalInfoOptions)
.surveyId(survey.getId())
.questions(questions)
.build();
}
Expand Down Expand Up @@ -102,7 +104,8 @@ public static AnonymousParticipant toAnonymousParticipant(SurveyRequestDTO.Surve
return AnonymousParticipant.builder()
.survey(survey)
.name(dto.getName())
.address(dto.getAddress())
.fullAddress(dto.getFullAddress())
.extraAddress(dto.getExtraAddress())
.email(dto.getEmail())
.phoneNumber(dto.getPhoneNumber())
.isAgreed(dto.getIsAgreed())
Expand Down Expand Up @@ -155,7 +158,8 @@ public static SurveyResponseDTO.WinnerDetailDTO toWinnerDetailDTO(AnonymousParti
return SurveyResponseDTO.WinnerDetailDTO.builder()
.name(participant.getName())
.phoneNumber(participant.getPhoneNumber())
.address(participant.getAddress())
.fullAddress(participant.getFullAddress())
.extraAddress(participant.getExtraAddress())
.email(participant.getEmail())
.instagramId(participant.getInstagramId())
.answers(answers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class AnonymousParticipant extends BaseDateTimeEntity {

private String name;

private String address;
private String fullAddress;

private String extraAddress;

private String email;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ public SurveyResponseDTO.SurveyCreateResponse createSurvey(SurveyRequestDTO.Surv

// 생성된 설문지 조회
@Transactional(readOnly = true)
public SurveyResponseDTO.SurveyResultDTO getSurveyBySurveyId(Long surveyId) {
public SurveyResponseDTO.SurveyViewDTO getSurveyBySurveyId(Long surveyId) {
Survey survey = surveyRepository.findById(surveyId)
.orElseThrow(() -> new IllegalArgumentException("Survey not found"));

Event event = survey.getEvent();
return SurveyConverter.toSurveyResultDTO(survey, event);
return SurveyConverter.toSurveyViewResultDTO(survey, event);
}

@Transactional(readOnly = true)
public SurveyResponseDTO.SurveyResultDTO getSurveyByUuid(String uuid) {
public SurveyResponseDTO.SurveyViewDTO 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);
return SurveyConverter.toSurveyViewResultDTO(survey, event);
}

// 설문 응답 저장
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/com/cmc/suppin/global/config/WebConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ private String[] getAllowOrigins() {
"https://dev.suppin.store",
"https://api.suppin.store",
"https://suppin.store",
"http://192.168.200.120:3000", // 테스트 디바이스 IP 허용
"http://192.168.200.120:3000",
"https://coherent-midge-probably.ngrok-free.app",
"https://suppin-servey.vercel.app/"
"https://suppin-web.vercel.app/",
"https://suppin-survey.vercel.app"
).toArray(String[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private RequestMatcher[] requestHasRoleUser() {
private RequestMatcher[] requestPermitAll() {
List<RequestMatcher> requestMatchers = List.of(
antMatcher("/"),
antMatcher("/health"),
antMatcher("/swagger-ui/**"),
antMatcher("/actuator/**"),
antMatcher("/v3/api-docs/**"),
Expand Down

0 comments on commit 94e8308

Please sign in to comment.