Skip to content

Commit

Permalink
�fix: 템플릿 추천 로직 수정 (#217)
Browse files Browse the repository at this point in the history
* feat: 템플릿 추천 로직 구현

* chore: 템플릿 추천 로직 구현으로 인한 서비스 로직 수정
  • Loading branch information
mikekks authored Sep 10, 2024
1 parent 0ce7b37 commit 1a2b1a7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ResponseEntity<RecommendFormResponseDto> getRecommendTemplate(
@Valid @ModelAttribute RecommendFormQueryDto queryDto,
@MemberId Long memberId) {

RecommendFormResponseDto response = formService.getRecommendTemplate(queryDto, memberId);
RecommendFormResponseDto response = formService.getRecommendTemplate(queryDto);
return ResponseEntity.ok().body(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.layer.domain.form.controller.dto.response.QuestionGetResponse;
import org.layer.domain.form.controller.dto.response.RecommendFormResponseDto;
import org.layer.domain.form.entity.Form;
import org.layer.domain.form.entity.FormType;
import org.layer.domain.form.enums.FormTag;
import org.layer.domain.form.exception.FormException;
import org.layer.domain.form.repository.FormRepository;
import org.layer.domain.question.entity.Question;
Expand Down Expand Up @@ -44,9 +46,6 @@ public class FormService {
private final SpaceRepository spaceRepository;
private final TemplateMetadataRepository metadataRepository;

private static final int MIN = 10000;
private static final int MAX = 10005;

/**
* 회고 폼 질문을 조회한다.
*
Expand All @@ -72,13 +71,11 @@ public FormGetResponse getForm(Long formId, Long memberId) {
return FormGetResponse.of(form.getTitle(), form.getFormTag().getTag(), questionResponses);
}

public RecommendFormResponseDto getRecommendTemplate(RecommendFormQueryDto queryDto, Long memberId) {
Random random = new Random();
Long formId = random.nextLong(MAX - MIN + 1) + MIN;
public RecommendFormResponseDto getRecommendTemplate(RecommendFormQueryDto queryDto) {
FormTag recommandFormTag = FormTag.getRecommandFormTag(queryDto.purpose());

Form form = formRepository.findByIdOrThrow(formId);
TemplateMetadata metadata = metadataRepository.findByFormIdOrThrow(formId);
// TODO: 템플릿 이미지 필요
Form form = formRepository.findByFormTagAndFormTypeOrThrow(recommandFormTag, FormType.TEMPLATE);
TemplateMetadata metadata = metadataRepository.findByFormIdOrThrow(form.getId());

return RecommendFormResponseDto.of(form, metadata.getTemplateImageUrl());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
package org.layer.domain.form.enums;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum FormTag {
KPT("KPT"),
FIVE_F("5F"),
MAD_SAD_GLAD("Mad Sad Glad"),
SSC("SSC"),
PMI("PMI"),
UNTITLED("무제"),
CUSTOM("CUSTOM");
KPT("KPT"),
FIVE_F("5F"),
MAD_SAD_GLAD("Mad Sad Glad"),
SSC("SSC"),
PMI("PMI"),
UNTITLED("무제"),
CUSTOM("CUSTOM");

private final String tag;

public static FormTag getRecommandFormTag(List<RetrospectPurpose> retrospectPurposes) {
Map<FormTag, Integer> formTagIntegerMap = EnumSet.allOf(FormTag.class).stream()
.collect(Collectors.toMap(tag -> tag, tag -> 0));

retrospectPurposes.forEach(purpose -> {
formTagIntegerMap.put(KPT, formTagIntegerMap.get(KPT) + purpose.getKtpPoint());
formTagIntegerMap.put(FIVE_F, formTagIntegerMap.get(FIVE_F) + purpose.getFiveFPoint());
formTagIntegerMap.put(MAD_SAD_GLAD, formTagIntegerMap.get(MAD_SAD_GLAD) + purpose.getMadSadGladPoint());
formTagIntegerMap.put(SSC, formTagIntegerMap.get(SSC) +purpose.getSscPoint());
formTagIntegerMap.put(PMI, formTagIntegerMap.get(PMI) +purpose.getPmiPont());
});

private final String tag;
return formTagIntegerMap.entrySet()
.stream()
.max(Map.Entry.comparingByValue())
.map(Map.Entry::getKey)
.orElse(FormTag.UNTITLED);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package org.layer.domain.form.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum RetrospectPurpose {
CHECK_PROGRESS, PERSONAL_GROWTH, TEAM_GROWTH, IMPROVE_COMMUNICATION, SHARE_EXPERIENCE, IMPROVE_PROBLEM, SHARE_EMOTION, STRATEGY_SETTING
CHECK_PROGRESS(1, 0, 0, 1, 0),
PERSONAL_GROWTH(1, 0, 0, 0, 0),
TEAM_GROWTH(1, 0, 1, 1, 1),
IMPROVE_COMMUNICATION(0, 0, 1, 0, 1),
SHARE_EXPERIENCE(0, 1, 0, 0, 1),
IMPROVE_PROBLEM(1, 1, 0, 0, 0),
SHARE_EMOTION(0, 1, 1, 0, 0),
STRATEGY_SETTING(1, 0, 0, 1, 0);

private final int ktpPoint;
private final int fiveFPoint;
private final int madSadGladPoint;
private final int sscPoint;
private final int pmiPont;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.layer.domain.form.entity.Form;
import org.layer.domain.form.entity.FormType;
import org.layer.domain.form.enums.FormTag;
import org.layer.domain.form.exception.FormException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

import static org.layer.common.exception.FormExceptionType.NOT_FOUND_FORM;

Expand All @@ -19,7 +21,12 @@ default Form findByIdOrThrow(Long formId) {

List<Form> findByFormTypeOrderById(FormType formType);

Page<Form> findAllByFormTypeOrderByIdDesc(Pageable pageable, FormType formType);
Page<Form> findAllByFormTypeAndSpaceIdOrderByIdDesc(Pageable pageable, FormType formType, Long spaceId);

Optional<Form> findByFormTagAndFormType(FormTag formTag, FormType formType);

default Form findByFormTagAndFormTypeOrThrow(FormTag formTag, FormType formType) {
return findByFormTagAndFormType(formTag, formType)
.orElseThrow(() -> new FormException(NOT_FOUND_FORM));
}
}

0 comments on commit 1a2b1a7

Please sign in to comment.