Skip to content

Commit

Permalink
[fix] 팜클럽 유저 리스트 DB 쿼리
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Aug 24, 2024
1 parent f28f9cd commit 52fbe1e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMyFarmClubListResponseDto;
import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetRecommendFarmClubResponseDto;
import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub;
import com.modernfarmer.farmusspring.domain.farmclub.vo.GetFarmClubUserVo;
import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo;
import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto;
import com.modernfarmer.farmusspring.domain.history.vo.HistoryDetailVo;
Expand All @@ -14,6 +15,6 @@ public interface FarmClubRepositoryCustom {
List<GetMyFarmClubListResponseDto> findMyFarmClubList(Long userId);
GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId);
HistoryDetailVo getFarmClubDetail(Long userFarmClubId);

List<GetFarmClubUserVo> findFarmClubUserList(Long farmClubId);
List<FarmClub> getRecommendedFarmClubList(String level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub;
import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode;
import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException;
import com.modernfarmer.farmusspring.domain.farmclub.vo.GetFarmClubUserVo;
import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo;
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.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down Expand Up @@ -107,6 +109,26 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) {
return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, currentStep, userFarmClubCreatedDate);
}

@Override
public List<GetFarmClubUserVo> findFarmClubUserList(Long farmClubId) {
JPAQueryFactory queryFactory = new JPAQueryFactory(em);

return queryFactory
.select(Projections.constructor(
GetFarmClubUserVo.class,
user.nickname,
user.profileImage))
.from(user)
.where(user.id.in(
JPAExpressions
.select(userFarmClub.userId)
.from(userFarmClub)
.join(userFarmClub.farmClub, farmClub)
.where(farmClub.id.eq(farmClubId))
))
.fetch();
}

public HistoryDetailVo getFarmClubDetail(Long userFarmClubId) {
JPAQueryFactory queryFactory = new JPAQueryFactory(em);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.modernfarmer.farmusspring.domain.farmclub.vo;

import lombok.AccessLevel;
import lombok.Builder;

@Builder(access = AccessLevel.PRIVATE)
public record GetFarmClubUserVo(
String nickname,
String profileImage
) {
public static GetFarmClubUserVo of(String nickname, String profileImage) {
return GetFarmClubUserVo.builder()
.nickname(nickname)
.profileImage(profileImage)
.build();
}
}

0 comments on commit 52fbe1e

Please sign in to comment.