Skip to content

Commit

Permalink
[fix] 스텝별 미션 리스트 쿼리 오류 수정 (내 팜클럽 상세 조회 api)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Jul 6, 2024
1 parent 3eee765 commit 9fce647
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,26 +31,24 @@ public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List<Ste
.build();
}

public static List<Step> createSteps(List<StepVo> stepVoList, List<GetMissionPostListWithStepCountsAndImagesVo> missionList) {
public static List<Step> createSteps(List<StepVo> stepVoList, List<GetMissionPostListVo> missionList) {
List<Step> 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<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +10,7 @@

public interface MissionPostRepositoryCustom {

List<GetMissionPostListWithStepCountsAndImagesVo> getMissionPostStepNumAndImage(Long farmClubId);
List<GetMissionPostListVo> getMissionPostStepNumAndImage(Long farmClubId);
List<MissionPostCommentVo> getMissionPostComment(Long missionPostId);
List<MissionPostVo> getMissionPostList(Long missionPostId);
List<MissionPostHistoryVo> getMissionPostHistory(Long missionPostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,20 +25,18 @@ public class MissionPostRepositoryImpl implements MissionPostRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<GetMissionPostListWithStepCountsAndImagesVo> getMissionPostStepNumAndImage(Long farmClubId) {
public List<GetMissionPostListVo> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,9 +96,11 @@ public GetMyFarmClubResponseDto getMyFarmClub(Long farmClubId, Long userId) {
String veggieInfoId = farmClubInfo.veggieInfoId();
List<StepVo> stepList = veggieInfoHelper.getStepList(veggieInfoId);
String randomTip = getRandomTip(stepList);
List<GetMissionPostListWithStepCountsAndImagesVo> missionList =
List<GetMissionPostListVo> missionList =
missionPostRepository.getMissionPostStepNumAndImage(farmClubId);

log.info("missionList: {}", missionList);

return GetMyFarmClubResponseDto.of(farmClubInfo, GetMyFarmClubResponseDto.createSteps(stepList, missionList), randomTip);
}

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

This file was deleted.

0 comments on commit 9fce647

Please sign in to comment.