Skip to content

Commit

Permalink
Merge pull request #25 from Mojacknong/feature_6/farmclub-기본-api
Browse files Browse the repository at this point in the history
Feature 6/farmclub 기본 api
  • Loading branch information
MinchoGreenT authored Jul 5, 2024
2 parents f8871a8 + 3eee765 commit 5b2cb39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public record GetMyFarmClubResponseDto(
String farmClubName,
String farmClubImage,
Long wholeMemberCount,
Integer currentStep,
List<Step> steps,
String advice,
Long daysSinceStart
Expand All @@ -23,6 +24,7 @@ public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List<Ste
.farmClubName(farmClubInfo.farmClubName())
.farmClubImage(farmClubInfo.farmClubImage())
.wholeMemberCount(farmClubInfo.wholeMemberCount())
.currentStep(farmClubInfo.currentStep())
.steps(steps)
.advice(advice)
.daysSinceStart(farmClubInfo.daySinceStart())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMyFarmClubVo_BaseInfo;
import com.modernfarmer.farmusspring.domain.history.vo.HistoryDetailVo;
import com.modernfarmer.farmusspring.domain.history.vo.QHistoryDetailVo;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down Expand Up @@ -80,11 +81,14 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) {
.where(farmClub.id.eq(farmClubId))
.fetchOne();

Long userFarmClubCount = queryFactory
.select(userFarmClub.count())
List<Tuple> results = queryFactory
.select(userFarmClub.count(), userFarmClub.currentStep)
.from(userFarmClub)
.join(userFarmClub.farmClub, farmClub)
.fetchOne();
.fetch();

Long userFarmClubCount = results.get(0).get(userFarmClub.count());
Integer currentStep = results.get(0).get(userFarmClub.currentStep);

LocalDate userFarmClubCreatedDate = queryFactory
.select(farmClub.startedAt)
Expand All @@ -96,7 +100,7 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) {
log.info("userFarmClubCount: {}", userFarmClubCount);
log.info("userFarmClubCreatedDate: {}", userFarmClubCreatedDate);

return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, userFarmClubCreatedDate);
return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, currentStep, userFarmClubCreatedDate);
}

public HistoryDetailVo getFarmClubDetail(Long userFarmClubId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ public record GetMyFarmClubVo(
String farmClubImage,
String veggieInfoId,
Long wholeMemberCount,
Integer currentStep,
Long daySinceStart
) {
public static GetMyFarmClubVo of(BaseInfo baseInfo, Long wholeMemberCount, LocalDate dayRegister) {
public static GetMyFarmClubVo of(BaseInfo baseInfo, Long wholeMemberCount, Integer currentStep,LocalDate dayRegister) {
return new GetMyFarmClubVo(
baseInfo.farmClubName(),
baseInfo.farmClubImage(),
baseInfo.veggieInfoId(),
wholeMemberCount,
currentStep,
ChronoUnit.DAYS.between(dayRegister, LocalDate.now())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public List<StepVo> getStepList(String veggieInfoId) {

public String getStepName(String veggieInfoId, int step) {
List<StepVo> stepList = getStepList(veggieInfoId);
return stepList.get(step).content();
return stepList.get(step - 1).content();
}
}

0 comments on commit 5b2cb39

Please sign in to comment.