From 9fce6474753003ee4304b624748bd375f10f36c7 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sat, 6 Jul 2024 23:45:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20=EC=8A=A4=ED=85=9D=EB=B3=84=20?= =?UTF-8?q?=EB=AF=B8=EC=85=98=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20(?= =?UTF-8?q?=EB=82=B4=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/GetMyFarmClubResponseDto.java | 36 +++++++++---------- .../MissionPostRepositoryCustom.java | 4 +-- .../repository/MissionPostRepositoryImpl.java | 18 ++++------ .../farmclub/service/FarmClubService.java | 6 ++-- .../farmclub/vo/GetMissionPostListVo.java | 12 +++++++ ...sionPostListWithStepCountsAndImagesVo.java | 14 -------- 6 files changed, 42 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListVo.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java index cca52a4f..c00dd246 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java @@ -1,6 +1,6 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.Builder; @@ -31,26 +31,24 @@ public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List createSteps(List stepVoList, List missionList) { + public static List createSteps(List stepVoList, List missionList) { List steps = new ArrayList<>(); - for (int i = 0; i < stepVoList.size(); i++) { - Step step; - if (i >= missionList.size()) { - step = new Step( - new ArrayList<>(), - stepVoList.get(i).num(), - stepVoList.get(i).content(), - 0L - ); - } else { - step = new Step( - missionList.get(i).images(), - stepVoList.get(i).num(), - stepVoList.get(i).content(), - missionList.get(i).count() - ); + for (StepVo step: stepVoList) { + long count = 0L; + List images = new ArrayList<>(); + for (GetMissionPostListVo mission: missionList) { + if (step.num() + 1 == mission.stepNum()) { + images.add(mission.image()); + count++; + } } - steps.add(step); + + steps.add(new Step( + images, + step.num(), + step.content(), + count + )); } return steps; } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java index 460cc090..5883586e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java @@ -1,7 +1,7 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostCommentVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo; import com.modernfarmer.farmusspring.domain.history.vo.MissionPostHistoryVo; @@ -10,7 +10,7 @@ public interface MissionPostRepositoryCustom { - List getMissionPostStepNumAndImage(Long farmClubId); + List getMissionPostStepNumAndImage(Long farmClubId); List getMissionPostComment(Long missionPostId); List getMissionPostList(Long missionPostId); List getMissionPostHistory(Long missionPostId); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java index ca5829e1..23620752 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java @@ -4,11 +4,9 @@ import com.modernfarmer.farmusspring.domain.farmclub.vo.*; import com.modernfarmer.farmusspring.domain.history.vo.MissionPostHistoryVo; import com.modernfarmer.farmusspring.domain.history.vo.QMissionPostHistoryVo; -import com.querydsl.core.group.GroupBy; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import lombok.RequiredArgsConstructor; import java.util.List; @@ -27,20 +25,18 @@ public class MissionPostRepositoryImpl implements MissionPostRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public List getMissionPostStepNumAndImage(Long farmClubId) { + public List getMissionPostStepNumAndImage(Long farmClubId) { return queryFactory + .select(Projections.constructor( + GetMissionPostListVo.class, + missionPost.stepNum, + missionPost.image)) .from(missionPost) .join(missionPost.userFarmClub, userFarmClub) .join(userFarmClub.farmClub, farmClub) .where(farmClub.id.eq(farmClubId)) - .transform( - GroupBy.groupBy(missionPost.stepNum) - .list(new QGetMissionPostListWithStepCountsAndImagesVo( - missionPost.stepNum.count(), - GroupBy.list(missionPost.image) - )) - ); + .fetch(); } @Override diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 6d2246aa..fc7f324f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -8,7 +8,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; import com.modernfarmer.farmusspring.domain.farmclub.repository.UserFarmClubRepository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.MyVeggieHelper; @@ -96,9 +96,11 @@ public GetMyFarmClubResponseDto getMyFarmClub(Long farmClubId, Long userId) { String veggieInfoId = farmClubInfo.veggieInfoId(); List stepList = veggieInfoHelper.getStepList(veggieInfoId); String randomTip = getRandomTip(stepList); - List missionList = + List missionList = missionPostRepository.getMissionPostStepNumAndImage(farmClubId); + log.info("missionList: {}", missionList); + return GetMyFarmClubResponseDto.of(farmClubInfo, GetMyFarmClubResponseDto.createSteps(stepList, missionList), randomTip); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListVo.java new file mode 100644 index 00000000..fb81a2a6 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListVo.java @@ -0,0 +1,12 @@ +package com.modernfarmer.farmusspring.domain.farmclub.vo; + +import com.querydsl.core.annotations.QueryProjection; + +public record GetMissionPostListVo( + Long stepNum, + String image +) { + @QueryProjection + public GetMissionPostListVo { + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java deleted file mode 100644 index ecac9988..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.vo; - -import com.querydsl.core.annotations.QueryProjection; - -import java.util.List; - -public record GetMissionPostListWithStepCountsAndImagesVo( - Long count, - List images -) { - @QueryProjection - public GetMissionPostListWithStepCountsAndImagesVo { - } -} From 4fc0d31e4028e4a08f3a6d85010b11dd2dda7e8d Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 7 Jul 2024 14:30:14 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EC=8A=A4=ED=85=9D=20=EC=88=98=201?= =?UTF-8?q?=EB=B6=80=ED=84=B0=20=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/service/FarmClubService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index fc7f324f..b5604112 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -80,7 +80,7 @@ public RegisterFarmClubResponseDto registerFarmClub(Long farmClubId, Long myVegg MyVeggie myVeggie = myVeggieHelper.getMyVeggieEntity(myVeggieId); FarmClub farmClub = farmClubHelper.getFarmClubEntity(farmClubId); // 채소정보 id로 채소의 첫 스텝명 불러옴 - String stepName = veggieInfoHelper.getStepName(farmClub.getVeggieInfoId(), 0); + String stepName = veggieInfoHelper.getStepName(farmClub.getVeggieInfoId(), 1); UserFarmClub userFarmClub = createUserFarmClubEntity(userId, stepName, farmClub, myVeggie); farmClub.addUserFarmClub(userFarmClub); myVeggie.setUserFarmClub(userFarmClub);