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
241 changes: 117 additions & 124 deletions src/main/java/com/avab/avab/converter/FlowConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.avab.avab.domain.CustomRecreation;
import com.avab.avab.domain.Flow;
import com.avab.avab.domain.Flow.FlowBuilder;
import com.avab.avab.domain.FlowAge;
import com.avab.avab.domain.FlowGender;
import com.avab.avab.domain.Recreation;
Expand Down Expand Up @@ -86,74 +87,15 @@ public static Flow toFlow(
List<RecreationKeyword> recreationKeywordList,
List<RecreationPurpose> recreationPurposeList) {

Flow flow =
Flow.builder()
.participants(request.getParticipants())
.totalPlayTime(request.getTotalPlayTime())
.title(request.getTitle())
.imageUrl(imageUrl)
.author(user)
.build();
Flow flow = buildFlow(null, request, user, imageUrl);

List<FlowRecreation> flowRecreationList =
request.getRecreationSpecList().stream()
.map(
spec -> {
// Recreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
if (recreationMap.containsKey(spec.getSeq())) {
return FlowRecreation.builder()
.flow(flow)
.recreation(recreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
}
// CustomRecreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
return FlowRecreation.builder()
.flow(flow)
.customRecreation(
customRecreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
})
.toList();

List<FlowRecreationKeyword> flowRecreationKeywordList =
recreationKeywordList.stream()
.map(
recreationKeyword ->
FlowRecreationKeyword.builder()
.flow(flow)
.keyword(recreationKeyword)
.build())
.toList();

List<FlowRecreationPurpose> flowRecreationPurposeList =
recreationPurposeList.stream()
.map(
recreationPurpose ->
FlowRecreationPurpose.builder()
.flow(flow)
.purpose(recreationPurpose)
.build())
.toList();

List<FlowAge> flowAgeList =
request.getAgeList().stream()
.map(age -> FlowAge.builder().age(age).flow(flow).build())
.toList();

List<FlowGender> flowGenderList =
request.getGenderList().stream()
.map(gender -> FlowGender.builder().flow(flow).gender(gender).build())
.toList();

flow.getFlowRecreationList().addAll(flowRecreationList);
flow.getFlowRecreationKeywordList().addAll(flowRecreationKeywordList);
flow.getFlowRecreationPurposeList().addAll(flowRecreationPurposeList);
flow.getAgeList().addAll(flowAgeList);
flow.getGenderList().addAll(flowGenderList);
populateFlowDetails(
request,
recreationMap,
customRecreationMap,
recreationKeywordList,
recreationPurposeList,
flow);

return flow;
}
Expand Down Expand Up @@ -284,76 +226,127 @@ public static Flow toUpdateFlow(
Map<Integer, CustomRecreation> customRecreationMap,
List<RecreationKeyword> recreationKeywordList,
List<RecreationPurpose> recreationPurposeList) {
Flow flow =
Flow flow = buildFlow(flowId, request, user, imageUrl);

populateFlowDetails(
request,
recreationMap,
customRecreationMap,
recreationKeywordList,
recreationPurposeList,
flow);

return flow;
}

private static Flow buildFlow(Long flowId, PostFlowDTO request, User user, String imageUrl) {
FlowBuilder builder =
Flow.builder()
.id(flowId)
.participants(request.getParticipants())
.totalPlayTime(request.getTotalPlayTime())
.imageUrl(imageUrl)
.title(request.getTitle())
.author(user)
.build();

List<FlowRecreation> flowRecreationList =
request.getRecreationSpecList().stream()
.map(
spec -> {
// Recreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
if (recreationMap.containsKey(spec.getSeq())) {
return FlowRecreation.builder()
.flow(flow)
.recreation(recreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
}
// CustomRecreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
return FlowRecreation.builder()
.flow(flow)
.customRecreation(
customRecreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
})
.toList();

List<FlowRecreationKeyword> flowRecreationKeywordList =
recreationKeywordList.stream()
.map(
recreationKeyword ->
FlowRecreationKeyword.builder()
.flow(flow)
.keyword(recreationKeyword)
.build())
.toList();
.imageUrl(imageUrl)
.author(user);

List<FlowRecreationPurpose> flowRecreationPurposeList =
recreationPurposeList.stream()
.map(
recreationPurpose ->
FlowRecreationPurpose.builder()
.flow(flow)
.purpose(recreationPurpose)
.build())
.toList();
if (flowId != null) {
builder.id(flowId);
}

List<FlowAge> flowAgeList =
request.getAgeList().stream()
.map(age -> FlowAge.builder().age(age).flow(flow).build())
.toList();
return builder.build();
}

List<FlowGender> flowGenderList =
request.getGenderList().stream()
.map(gender -> FlowGender.builder().flow(flow).gender(gender).build())
.toList();
private static void populateFlowDetails(
PostFlowDTO request,
Map<Integer, Recreation> recreationMap,
Map<Integer, CustomRecreation> customRecreationMap,
List<RecreationKeyword> recreationKeywordList,
List<RecreationPurpose> recreationPurposeList,
Flow flow) {
List<FlowRecreation> recreations =
getFlowRecreations(request, recreationMap, customRecreationMap, flow);
List<FlowRecreationKeyword> keywords =
getFlowRecreationKeywords(recreationKeywordList, flow);
List<FlowRecreationPurpose> purposes =
getFlowRecreationPurposes(recreationPurposeList, flow);
List<FlowAge> ages = getFlowAges(request.getAgeList(), flow);
List<FlowGender> genders = getFlowGenders(request.getGenderList(), flow);

attachFlowDetails(flow, recreations, keywords, purposes, ages, genders);
}

private static void attachFlowDetails(
Flow flow,
List<FlowRecreation> flowRecreationList,
List<FlowRecreationKeyword> flowRecreationKeywordList,
List<FlowRecreationPurpose> flowRecreationPurposeList,
List<FlowAge> flowAgeList,
List<FlowGender> flowGenderList) {
flow.getFlowRecreationList().addAll(flowRecreationList);
flow.getFlowRecreationKeywordList().addAll(flowRecreationKeywordList);
flow.getFlowRecreationPurposeList().addAll(flowRecreationPurposeList);
flow.getAgeList().addAll(flowAgeList);
flow.getGenderList().addAll(flowGenderList);
}

return flow;
private static List<FlowRecreation> getFlowRecreations(
PostFlowDTO request,
Map<Integer, Recreation> recreationMap,
Map<Integer, CustomRecreation> customRecreationMap,
Flow flow) {
return request.getRecreationSpecList().stream()
.map(
spec -> {
// Recreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
if (recreationMap.containsKey(spec.getSeq())) {
return FlowRecreation.builder()
.flow(flow)
.recreation(recreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
}
// CustomRecreation์— ๋Œ€ํ•œ FlowRecreation ์ƒ์„ฑ
return FlowRecreation.builder()
.flow(flow)
.customRecreation(customRecreationMap.get(spec.getSeq()))
.customPlayTime(spec.getCustomPlayTime())
.seq(spec.getSeq())
.build();
})
.toList();
}

private static List<FlowRecreationKeyword> getFlowRecreationKeywords(
List<RecreationKeyword> recreationKeywordList, Flow flow) {
return recreationKeywordList.stream()
.map(
recreationKeyword ->
FlowRecreationKeyword.builder()
.flow(flow)
.keyword(recreationKeyword)
.build())
.toList();
}

private static List<FlowRecreationPurpose> getFlowRecreationPurposes(
List<RecreationPurpose> recreationPurposeList, Flow flow) {
return recreationPurposeList.stream()
.map(
recreationPurpose ->
FlowRecreationPurpose.builder()
.flow(flow)
.purpose(recreationPurpose)
.build())
.toList();
}

private static List<FlowAge> getFlowAges(List<Age> ages, Flow flow) {
return ages.stream().map(age -> FlowAge.builder().age(age).flow(flow).build()).toList();
}

private static List<FlowGender> getFlowGenders(List<Gender> genders, Flow flow) {
return genders.stream()
.map(gender -> FlowGender.builder().flow(flow).gender(gender).build())
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public List<Flow> recommendFlows(
purposesForComparison.stream().filter(purpose::contains).count();

// ์‹œ๊ฐ„(ํ•„์ˆ˜) ๋น„๊ต
Integer nowTotalPlayTime = nowFlow.getTotalPlayTime();
long loePlayTime =
nowFlow.getTotalPlayTime() <= totalPlayTime
? -Math.abs(nowFlow.getTotalPlayTime() - totalPlayTime)
(nowTotalPlayTime != null && nowTotalPlayTime <= totalPlayTime)
? -Math.abs(nowTotalPlayTime - totalPlayTime)
: -10000;

// ๊ฒน์น˜๋Š” ํ‚ค์›Œ๋“œ ์ฒดํฌ
Expand All @@ -84,9 +85,12 @@ public List<Flow> recommendFlows(
: 0L;

// ์ธ์›
Integer nowParticipants = nowFlow.getParticipants();
int participantsMatch =
participant != null && participant > nowFlow.getParticipants()
? participant - nowFlow.getParticipants()
(participant != null
&& nowParticipants != null
&& participant > nowParticipants)
? participant - nowParticipants
: 0;

// ์—ฐ๋ น๋Œ€ ๊ฒน์น˜๋Š” ๊ฐœ์ˆ˜ ํ™•์ธ
Expand Down
Loading