diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/controller/DatePreferenceController.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/controller/DatePreferenceController.java index 95e3bc8..fb0a73c 100644 --- a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/controller/DatePreferenceController.java +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/controller/DatePreferenceController.java @@ -10,9 +10,11 @@ import org.withtime.be.withtimebe.domain.date.preference.converter.DatePreferenceConverter; import org.withtime.be.withtimebe.domain.date.preference.dto.DatePreferenceRequestDTO; import org.withtime.be.withtimebe.domain.date.preference.dto.DatePreferenceResponseDTO; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; import org.withtime.be.withtimebe.domain.date.preference.service.command.DatePreferenceTestCommandService; import org.withtime.be.withtimebe.domain.date.preference.service.query.DatePreferenceDescriptionQueryService; import org.withtime.be.withtimebe.domain.date.preference.service.query.DatePreferenceQuestionQueryService; +import org.withtime.be.withtimebe.domain.date.preference.service.query.DatePreferenceTypeRelationQueryService; import org.withtime.be.withtimebe.domain.member.entity.Member; import org.withtime.be.withtimebe.global.security.annotation.AuthenticatedMember; @@ -23,6 +25,7 @@ public class DatePreferenceController { private final DatePreferenceTestCommandService datePreferenceTestCommandService; + private final DatePreferenceTypeRelationQueryService datePreferenceTypeRelationQueryService; private final DatePreferenceDescriptionQueryService datePreferenceDescriptionQueryService; private final DatePreferenceQuestionQueryService datePreferenceQuestionQueryService; @@ -56,4 +59,21 @@ public DefaultResponse test(@Authenticated return DefaultResponse.ok(datePreferenceTestCommandService.test(member, request)); } + @Operation(summary = "잘 맞는 유형, 안 맞는 유형 검색 API by 요시", description = "잘 맞는 유형과 안 맞는 유형을 검색하는 API") + @ApiResponses({ + @ApiResponse(responseCode = "COMMON200", description = "테스트에 성공했습니다."), + @ApiResponse( + responseCode = "404", + description = """ + 다음과 같은 이유로 실패할 수 있습니다: + - DATE_PREFERENCE404_1: 설명을 찾지 못했습니다. + - DATE_PREFERENCE404_2: 잘 맞는 혹은 안 맞는 유형을 찾지 못했습니다. + """ + ), + }) + @GetMapping("/relations") + public DefaultResponse findRelationType(@RequestParam("type") PreferenceType type) { + return DefaultResponse.ok(datePreferenceTypeRelationQueryService.findTypeRelations(type)); + } + } diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/converter/DatePreferenceConverter.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/converter/DatePreferenceConverter.java index 27e87e7..d912a2f 100644 --- a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/converter/DatePreferenceConverter.java +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/converter/DatePreferenceConverter.java @@ -1,10 +1,7 @@ package org.withtime.be.withtimebe.domain.date.preference.converter; import org.withtime.be.withtimebe.domain.date.preference.dto.DatePreferenceResponseDTO; -import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceDescription; -import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferencePartDescription; -import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceQuestion; -import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceTestResult; +import org.withtime.be.withtimebe.domain.date.preference.entity.*; import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; import java.util.List; @@ -92,4 +89,15 @@ public static DatePreferenceResponseDTO.PartTypeDescription toPartTypeDescriptio .description(description.getDescription()) .build(); } + + public static DatePreferenceResponseDTO.FindRelationType toFindRelationType(DatePreferenceTypeRelation best, DatePreferenceTypeRelation worst, DatePreferenceDescription bestDescription, DatePreferenceDescription worstDescription) { + return DatePreferenceResponseDTO.FindRelationType.builder() + .bestType(best.getType()) + .bestReason(best.getReason()) + .worstType(worst.getType()) + .worstReason(worst.getReason()) + .bestTypeDescription(toTypeDescription(bestDescription)) + .worstTypeDescription(toTypeDescription(worstDescription)) + .build(); + } } diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/dto/DatePreferenceResponseDTO.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/dto/DatePreferenceResponseDTO.java index ab12ee4..c4b3f15 100644 --- a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/dto/DatePreferenceResponseDTO.java +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/dto/DatePreferenceResponseDTO.java @@ -83,4 +83,16 @@ public record PartTypeDescription( } + @Builder + public record FindRelationType( + PreferenceType bestType, + String bestReason, + PreferenceType worstType, + String worstReason, + TypeDescription bestTypeDescription, + TypeDescription worstTypeDescription + ) { + + } + } diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/DatePreferenceTypeRelation.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/DatePreferenceTypeRelation.java new file mode 100644 index 0000000..bce4519 --- /dev/null +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/DatePreferenceTypeRelation.java @@ -0,0 +1,37 @@ +package org.withtime.be.withtimebe.domain.date.preference.entity; + +import jakarta.persistence.*; +import lombok.*; +import org.checkerframework.checker.units.qual.C; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceRelationType; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Table(name = "date_preference_type_relation") +public class DatePreferenceTypeRelation { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "date_preference_type_relation_id") + private Long id; + + @Enumerated(EnumType.STRING) + @Column(name = "type") + private PreferenceType type; + + @Enumerated(EnumType.STRING) + @Column(name = "target_type") + private PreferenceType targetType; + + @Column(name = "reason") + private String reason; + + @Enumerated(EnumType.STRING) + @Column(name = "preference_relation_type") + private PreferenceRelationType preferenceRelationType; + +} diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/enums/PreferenceRelationType.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/enums/PreferenceRelationType.java new file mode 100644 index 0000000..dd6101c --- /dev/null +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/entity/enums/PreferenceRelationType.java @@ -0,0 +1,5 @@ +package org.withtime.be.withtimebe.domain.date.preference.entity.enums; + +public enum PreferenceRelationType { + BEST, WORST +} diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/repository/DatePreferenceTypeRelationRepository.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/repository/DatePreferenceTypeRelationRepository.java new file mode 100644 index 0000000..adb3b1f --- /dev/null +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/repository/DatePreferenceTypeRelationRepository.java @@ -0,0 +1,13 @@ +package org.withtime.be.withtimebe.domain.date.preference.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceTypeRelation; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceRelationType; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; + +import java.util.Optional; + +public interface DatePreferenceTypeRelationRepository extends JpaRepository { + + Optional findByTargetTypeAndPreferenceRelationType(PreferenceType targetType, PreferenceRelationType preferenceRelationType); +} diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryService.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryService.java new file mode 100644 index 0000000..14103f5 --- /dev/null +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryService.java @@ -0,0 +1,12 @@ +package org.withtime.be.withtimebe.domain.date.preference.service.query; + +import org.withtime.be.withtimebe.domain.date.preference.dto.DatePreferenceResponseDTO; +import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceTypeRelation; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceRelationType; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; + +public interface DatePreferenceTypeRelationQueryService { + + DatePreferenceResponseDTO.FindRelationType findTypeRelations(PreferenceType preferenceType); + DatePreferenceTypeRelation findTypeRelation(PreferenceType preferenceType, PreferenceRelationType preferenceRelationType); +} diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryServiceImpl.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryServiceImpl.java new file mode 100644 index 0000000..dd72d69 --- /dev/null +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/service/query/DatePreferenceTypeRelationQueryServiceImpl.java @@ -0,0 +1,43 @@ +package org.withtime.be.withtimebe.domain.date.preference.service.query; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.withtime.be.withtimebe.domain.date.preference.converter.DatePreferenceConverter; +import org.withtime.be.withtimebe.domain.date.preference.dto.DatePreferenceResponseDTO; +import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceDescription; +import org.withtime.be.withtimebe.domain.date.preference.entity.DatePreferenceTypeRelation; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceRelationType; +import org.withtime.be.withtimebe.domain.date.preference.entity.enums.PreferenceType; +import org.withtime.be.withtimebe.domain.date.preference.repository.DatePreferenceDescriptionRepository; +import org.withtime.be.withtimebe.domain.date.preference.repository.DatePreferenceTypeRelationRepository; +import org.withtime.be.withtimebe.global.error.code.DatePreferenceErrorCode; +import org.withtime.be.withtimebe.global.error.exception.DatePreferenceException; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class DatePreferenceTypeRelationQueryServiceImpl implements DatePreferenceTypeRelationQueryService { + + private final DatePreferenceTypeRelationRepository datePreferenceTypeRelationRepository; + private final DatePreferenceDescriptionRepository datePreferenceDescriptionRepository; + + @Override + public DatePreferenceResponseDTO.FindRelationType findTypeRelations(PreferenceType preferenceType) { + DatePreferenceTypeRelation best = findTypeRelation(preferenceType, PreferenceRelationType.BEST); + DatePreferenceTypeRelation worst = findTypeRelation(preferenceType, PreferenceRelationType.WORST); + + return DatePreferenceConverter.toFindRelationType( + best, + worst, + datePreferenceDescriptionRepository.findByPreferenceType(best.getType()).orElseThrow(() -> new DatePreferenceException(DatePreferenceErrorCode.NOT_FOUND_DESCRIPTION)), + datePreferenceDescriptionRepository.findByPreferenceType(worst.getType()).orElseThrow(() -> new DatePreferenceException(DatePreferenceErrorCode.NOT_FOUND_DESCRIPTION)) + ); + } + + @Override + public DatePreferenceTypeRelation findTypeRelation(PreferenceType preferenceType, PreferenceRelationType preferenceRelationType) { + return datePreferenceTypeRelationRepository.findByTargetTypeAndPreferenceRelationType(preferenceType, preferenceRelationType) + .orElseThrow(() -> new DatePreferenceException(DatePreferenceErrorCode.NOT_FOUND_RELATION)); + } +} diff --git a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/util/WeightBaseTestScoreCalculator.java b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/util/WeightBaseTestScoreCalculator.java index 9719364..4b3b3d9 100644 --- a/src/main/java/org/withtime/be/withtimebe/domain/date/preference/util/WeightBaseTestScoreCalculator.java +++ b/src/main/java/org/withtime/be/withtimebe/domain/date/preference/util/WeightBaseTestScoreCalculator.java @@ -20,10 +20,10 @@ public class WeightBaseTestScoreCalculator implements DatePreferenceTestScoreCal }; private static final double[] weights = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1.1, 1, 1.1, 1, 1.1, 1, + 1, 1.1, 1.1, 1, 1, 1, 1.1, 1, 1, 1, + 1.1, 1, 1, 1, 1.1, 1, 1, 1, 1.1, 1, + 1.1, 1, 1, 1.1, 1, 1, 1, 1, 1.1, 1 }; @Override diff --git a/src/main/java/org/withtime/be/withtimebe/global/error/code/DatePreferenceErrorCode.java b/src/main/java/org/withtime/be/withtimebe/global/error/code/DatePreferenceErrorCode.java index a3209a7..3427900 100644 --- a/src/main/java/org/withtime/be/withtimebe/global/error/code/DatePreferenceErrorCode.java +++ b/src/main/java/org/withtime/be/withtimebe/global/error/code/DatePreferenceErrorCode.java @@ -8,7 +8,9 @@ @AllArgsConstructor public enum DatePreferenceErrorCode implements BaseErrorCode { - INVALID_ANSWERS(HttpStatus.BAD_REQUEST, "DATE_PREFERENCE400_1", "질문에 대한 응답의 형식이 잘못되었습니다.") + INVALID_ANSWERS(HttpStatus.BAD_REQUEST, "DATE_PREFERENCE400_1", "질문에 대한 응답의 형식이 잘못되었습니다."), + NOT_FOUND_DESCRIPTION(HttpStatus.BAD_REQUEST, "DATE_PREFERENCT404_1", "데이트 유형에 대한 설명을 찾지 못했습니다."), + NOT_FOUND_RELATION(HttpStatus.NOT_FOUND, "DATE_PREFERENCE404_2", "잘 맞는 혹은 안 맞는 유형 정보가 없습니다.") ; private final HttpStatus httpStatus; private final String code;