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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,6 +25,7 @@
public class DatePreferenceController {

private final DatePreferenceTestCommandService datePreferenceTestCommandService;
private final DatePreferenceTypeRelationQueryService datePreferenceTypeRelationQueryService;
private final DatePreferenceDescriptionQueryService datePreferenceDescriptionQueryService;
private final DatePreferenceQuestionQueryService datePreferenceQuestionQueryService;

Expand Down Expand Up @@ -56,4 +59,21 @@ public DefaultResponse<DatePreferenceResponseDTO.TestResult> 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<DatePreferenceResponseDTO.FindRelationType> findRelationType(@RequestParam("type") PreferenceType type) {
return DefaultResponse.ok(datePreferenceTypeRelationQueryService.findTypeRelations(type));
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,16 @@ public record PartTypeDescription(

}

@Builder
public record FindRelationType(
PreferenceType bestType,
String bestReason,
PreferenceType worstType,
String worstReason,
TypeDescription bestTypeDescription,
TypeDescription worstTypeDescription
) {

}

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.withtime.be.withtimebe.domain.date.preference.entity.enums;

public enum PreferenceRelationType {
BEST, WORST
}
Original file line number Diff line number Diff line change
@@ -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<DatePreferenceTypeRelation, Long> {

Optional<DatePreferenceTypeRelation> findByTargetTypeAndPreferenceRelationType(PreferenceType targetType, PreferenceRelationType preferenceRelationType);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down