Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

@RestController
Expand Down Expand Up @@ -55,12 +54,13 @@ public ApplicationResponse<?> getSurveyQuestions() {
description = "서버 오류")
})
public ApplicationResponse<?> registerSurvey(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "설문조사 응답 데이터",
required = true,
content = @Content(schema = @Schema(implementation = SurveyReq.class)))
@RequestBody SurveyReq request) {
return ApplicationResponse.ok(surveyService.registerSurvey(request));
return ApplicationResponse.ok(surveyService.registerSurvey(principalDetails.getMember(), request));
}

@GetMapping("/list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public record SurveyOptionDto(
String optionId,
String optionText,
int score
String label,
int value // 점수 값
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@
public record SurveyQuestionDto(
String questionId,
String questionText,
String questionType, // MULTIPLE_CHOICE, SCALE, TEXT
String questionType,
List<SurveyOptionDto> options,
boolean required,
int order
) {}
int order,
Integer selectedScore, // 선택된 답변 점수 (nullable)
String selectedOptionText // 선택된 옵션 텍스트 (nullable)
) {
// 질문만 있는 경우 (설문지 조회용)
public SurveyQuestionDto(
String questionId,
String questionText,
String questionType,
List<SurveyOptionDto> options,
boolean required,
int order
) {
this(questionId, questionText, questionType, options, required, order, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import java.util.Map;

public record SurveyReq(
@NotNull(message = "회원 ID는 필수입니다.")
Long memberId,

@NotEmpty(message = "설문 응답은 필수입니다.")
Map<String, Object> answers
) {}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package hongik.triple.commonmodule.dto.survey;

import hongik.triple.commonmodule.enumerate.AcneType;
import hongik.triple.commonmodule.enumerate.SkinType;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public record SurveyRes(
Long surveyId,
Long memberId,
String memberName,
SkinType skinType,
String skinType,
Map<String, Object> body,
LocalDateTime createdAt,
LocalDateTime modifiedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.type.SqlTypes;

import java.util.Map;

@Entity
@Getter
Expand All @@ -26,15 +30,16 @@ public class Survey extends BaseTimeEntity {
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "body", columnDefinition = "json", nullable = false)
private Object body;
private Map<String, Object> body;

@Column(name = "skin_type", nullable = false)
// @Enumerated(EnumType.STRING) 사용 X, String 형식으로 저장 (이유: description도 같이 저장되는 것을 방지하기 위해)
private String skinType;

@Builder
public Survey(Member member, Object body, SkinType skinType) {
public Survey(Member member, Map<String, Object> body, SkinType skinType) {
this.member = member;
this.body = body;
this.skinType = skinType.name();
Expand Down