Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 6/farmclub 기본 api #26

Merged
merged 3 commits into from
Jul 7, 2024
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
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 @@ -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);
Expand All @@ -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.

Loading