From e9de06852103335032d8bc722b74af3f4a793e45 Mon Sep 17 00:00:00 2001 From: rlacksgus97 Date: Mon, 18 Mar 2024 22:05:01 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EB=82=B4=EA=B0=80=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=84=A4=EB=AC=B8=EC=97=90=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20wikiId=20=ED=8F=AC=ED=95=A8(#126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/survey/model/dto/ReceivedSurveyDto.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/ReceivedSurveyDto.java b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/ReceivedSurveyDto.java index b1b62573..48cb63fe 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/ReceivedSurveyDto.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/ReceivedSurveyDto.java @@ -3,9 +3,12 @@ import com.dnd.namuiwiki.domain.survey.model.entity.Survey; import com.dnd.namuiwiki.domain.survey.type.Period; import com.dnd.namuiwiki.domain.survey.type.Relation; +import com.dnd.namuiwiki.domain.user.entity.User; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Optional; + @Getter @AllArgsConstructor public class ReceivedSurveyDto { @@ -14,13 +17,21 @@ public class ReceivedSurveyDto { private Relation relation; private Period period; private String senderName; + private String senderWikiId; public static ReceivedSurveyDto from(Survey survey) { + String senderWikiId = null; + User sender = survey.getSender(); + if (sender != null) { + senderWikiId = sender.getWikiId(); + } + return new ReceivedSurveyDto( survey.getId(), survey.getRelation(), survey.getPeriod(), - survey.getSenderName() + survey.getSenderName(), + senderWikiId ); } From 9e0d5dcf93cf462afd6763cec644d49ecf786623 Mon Sep 17 00:00:00 2001 From: rlacksgus97 Date: Tue, 19 Mar 2024 21:47:39 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=A7=88=EB=AC=B8=EB=B3=84=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20questionName=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80(#129)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dnd/namuiwiki/domain/survey/SurveyService.java | 2 +- .../domain/survey/model/dto/GetAnswersByQuestionResponse.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java b/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java index 10feb6b7..e38e5b05 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/SurveyService.java @@ -147,7 +147,7 @@ public GetAnswersByQuestionResponse getAnswersByQuestion(String wikiId, String q .build(); }); - return new GetAnswersByQuestionResponse(question.getTitle(), PageableDto.create(answers)); + return new GetAnswersByQuestionResponse(question.getTitle(), question.getName(), PageableDto.create(answers)); } private void validateFilter(Period period, Relation relation) { diff --git a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/GetAnswersByQuestionResponse.java b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/GetAnswersByQuestionResponse.java index 44004c81..7d25c89d 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/GetAnswersByQuestionResponse.java +++ b/src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/GetAnswersByQuestionResponse.java @@ -1,6 +1,7 @@ package com.dnd.namuiwiki.domain.survey.model.dto; import com.dnd.namuiwiki.common.dto.PageableDto; +import com.dnd.namuiwiki.domain.question.type.QuestionName; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,5 +11,6 @@ @Getter public class GetAnswersByQuestionResponse { private String questionTitle; + private QuestionName questionName; private PageableDto answers; } From 5d57ab01f3270128f892fc8c3655db31f7bb1b48 Mon Sep 17 00:00:00 2001 From: eun-seong Date: Tue, 19 Mar 2024 22:13:25 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EB=8C=80=EC=8B=9C=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=A7=81=EC=A0=91?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=98=B5=EC=85=98=20=ED=8D=BC=EC=84=BC?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=8F=AC=ED=95=A8(#1?= =?UTF-8?q?28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/BestWorthDashboardComponent.java | 35 +++++++++++++----- .../model/HappyDashboardComponent.java | 36 ++++++++++++++----- .../model/SadDashboardComponent.java | 36 ++++++++++++++----- .../domain/dashboard/model/dto/RatioDto.java | 6 +++- 4 files changed, 85 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/BestWorthDashboardComponent.java b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/BestWorthDashboardComponent.java index bd42b144..918651b3 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/BestWorthDashboardComponent.java +++ b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/BestWorthDashboardComponent.java @@ -2,11 +2,14 @@ import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto; import com.dnd.namuiwiki.domain.dashboard.type.DashboardType; +import com.dnd.namuiwiki.domain.statistic.model.Legend; import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic; import com.dnd.namuiwiki.domain.statistic.model.Statistics; import lombok.Getter; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Getter public class BestWorthDashboardComponent extends DashboardComponent { @@ -25,15 +28,29 @@ public void calculate(Statistics statistics) { RatioStatistic bestWorth = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0); Long totalCount = bestWorth.getTotalCount(); - this.rank = bestWorth.getLegends().stream() - .map(legend -> { - if (totalCount == 0) { - return new RatioDto(legend.getText(), 0); - } - int percentage = (int) (legend.getCount() * 100 / totalCount); - return new RatioDto(legend.getText(), percentage); - }) - .toList(); + List legends = bestWorth.getLegends(); + int optionPercentage = 0; + + this.rank = new ArrayList<>(); + + for (Legend legend : legends) { + if (totalCount == 0) { + rank.add(new RatioDto(legend.getText(), 0)); + } + int percentage = (int) (legend.getCount() * 100 / totalCount); + optionPercentage += percentage; + rank.add(new RatioDto(legend.getText(), percentage)); + } + + // 직접입력인 legend 인거 찾아서 새로 업데이트 + updateManualLegendPercentage(optionPercentage); + } + + private void updateManualLegendPercentage(int optionPercentage) { + Optional manualLegend = this.rank.stream() + .filter(legend -> legend.getLegend().contains("직접 입력")) + .findFirst(); + manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage)); } } diff --git a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/HappyDashboardComponent.java b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/HappyDashboardComponent.java index 041587e3..2663c9c0 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/HappyDashboardComponent.java +++ b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/HappyDashboardComponent.java @@ -2,11 +2,14 @@ import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto; import com.dnd.namuiwiki.domain.dashboard.type.DashboardType; +import com.dnd.namuiwiki.domain.statistic.model.Legend; import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic; import com.dnd.namuiwiki.domain.statistic.model.Statistics; import lombok.Getter; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Getter public class HappyDashboardComponent extends DashboardComponent { @@ -24,15 +27,30 @@ public HappyDashboardComponent(Statistics statistics, String questionId) { public void calculate(Statistics statistics) { RatioStatistic happy = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0); Long totalCount = happy.getTotalCount(); - this.rank = happy.getLegends().stream() - .map(legend -> { - if (totalCount == 0) { - return new RatioDto(legend.getText(), 0); - } - int percentage = (int) (legend.getCount() * 100 / totalCount); - return new RatioDto(legend.getText(), percentage); - }) - .toList(); + + List legends = happy.getLegends(); + int optionPercentage = 0; + + this.rank = new ArrayList<>(); + + for (Legend legend : legends) { + if (totalCount == 0) { + rank.add(new RatioDto(legend.getText(), 0)); + } + int percentage = (int) (legend.getCount() * 100 / totalCount); + optionPercentage += percentage; + rank.add(new RatioDto(legend.getText(), percentage)); + } + + // 직접입력인 legend 인거 찾아서 새로 업데이트 + updateManualLegendPercentage(optionPercentage); + } + + private void updateManualLegendPercentage(int optionPercentage) { + Optional manualLegend = this.rank.stream() + .filter(legend -> legend.getLegend().contains("직접 입력")) + .findFirst(); + manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage)); } } diff --git a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/SadDashboardComponent.java b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/SadDashboardComponent.java index b1a7b08d..18af7fd7 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/SadDashboardComponent.java +++ b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/SadDashboardComponent.java @@ -2,11 +2,14 @@ import com.dnd.namuiwiki.domain.dashboard.model.dto.RatioDto; import com.dnd.namuiwiki.domain.dashboard.type.DashboardType; +import com.dnd.namuiwiki.domain.statistic.model.Legend; import com.dnd.namuiwiki.domain.statistic.model.RatioStatistic; import com.dnd.namuiwiki.domain.statistic.model.Statistics; import lombok.Getter; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Getter public class SadDashboardComponent extends DashboardComponent { @@ -24,15 +27,30 @@ public SadDashboardComponent(Statistics statistics, String questionId) { public void calculate(Statistics statistics) { RatioStatistic sad = (RatioStatistic) statistics.getStatisticsByDashboardType(this.dashboardType).get(0); Long totalCount = sad.getTotalCount(); - this.rank = sad.getLegends().stream() - .map(legend -> { - if (totalCount == 0) { - return new RatioDto(legend.getText(), 0); - } - int percentage = (int) (legend.getCount() * 100 / totalCount); - return new RatioDto(legend.getText(), percentage); - }) - .toList(); + + List legends = sad.getLegends(); + int optionPercentage = 0; + + this.rank = new ArrayList<>(); + + for (Legend legend : legends) { + if (totalCount == 0) { + rank.add(new RatioDto(legend.getText(), 0)); + } + int percentage = (int) (legend.getCount() * 100 / totalCount); + optionPercentage += percentage; + rank.add(new RatioDto(legend.getText(), percentage)); + } + + // 직접입력인 legend 인거 찾아서 새로 업데이트 + updateManualLegendPercentage(optionPercentage); + } + + private void updateManualLegendPercentage(int optionPercentage) { + Optional manualLegend = this.rank.stream() + .filter(legend -> legend.getLegend().contains("직접 입력")) + .findFirst(); + manualLegend.ifPresent(ratioDto -> ratioDto.setPercentage(100 - optionPercentage)); } } diff --git a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/dto/RatioDto.java b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/dto/RatioDto.java index 022bccd5..03282f9e 100644 --- a/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/dto/RatioDto.java +++ b/src/main/java/com/dnd/namuiwiki/domain/dashboard/model/dto/RatioDto.java @@ -7,5 +7,9 @@ @Getter public class RatioDto { private final String legend; - private final int percentage; + private int percentage; + + public void setPercentage(int percentage) { + this.percentage = percentage; + } }