Skip to content

Commit

Permalink
Merge pull request #53 from Mojacknong/feature_41/미션목록-api-수정
Browse files Browse the repository at this point in the history
[fix] 미션목록 api 수정
  • Loading branch information
MinchoGreenT authored Jul 31, 2024
2 parents 052da71 + 904e9a1 commit 2419930
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
25 changes: 15 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,25 @@ tasks.named('test') {
useJUnitPlatform()
}

// Querydsl 설정부
def generated = 'src/main/generated'

// querydsl QClass 파일 생성 위치를 지정
tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
test {
useJUnitPlatform()
}

// java source set 에 querydsl QClass 위치 추가
def generatedDir = "src/main/generated"


sourceSets {
main.java.srcDirs += [ generated ]
main {
java {
srcDirs = ['src/main/java']
}
// Mybatis 쿼리 xml 위치때문에 조정
resources{
srcDir "${project.projectDir}/src/main/java"
}
}
}

// gradle clean 시에 QClass 디렉토리 삭제
clean {
delete file(generated)
delete file(generatedDir)
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public BaseResponseDto<?> deleteMissionPostLike(
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}

@GetMapping("/{id}/mission")
@GetMapping("/{farmClubId}/mission")
public BaseResponseDto<?> getMissionPostList(
@PathVariable Long id
@AuthenticationPrincipal CustomUser user,
@PathVariable Long farmClubId
) {
return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(id));
return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(user.getUserId(), farmClubId));
}

@GetMapping("/mission/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode;
import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException;
import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository;
import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo;
import com.modernfarmer.farmusspring.domain.history.vo.MissionPostHistoryVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -26,6 +27,10 @@ public List<MissionPostHistoryVo> getMissionPostHistory(Long userFarmClubId) {
return missionPostRepository.getMissionPostHistory(userFarmClubId);
}

public List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId) {
return missionPostRepository.getMissionPostList(userId, missionPostId);
}

@Transactional
public void deleteMissionPostLike(Long userId, Long missionPostId) {
missionPostRepository.deleteMissionPostLike(userId, missionPostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface MissionPostRepositoryCustom {

List<GetMissionPostListVo> getMissionPostStepNumAndImage(Long farmClubId);
List<MissionPostCommentVo> getMissionPostComment(Long missionPostId);
List<MissionPostVo> getMissionPostList(Long missionPostId);
List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId);
List<MissionPostHistoryVo> getMissionPostHistory(Long missionPostId);
void deleteMissionPostLike(Long userId, Long missionPostId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<MissionPostCommentVo> getMissionPostComment(Long missionPostId) {
}

@Override
public List<MissionPostVo> getMissionPostList(Long farmClubId) {
public List<MissionPostVo> getMissionPostList(Long userId, Long farmClubId) {

return queryFactory
.select(new QMissionPostVo(
Expand All @@ -62,7 +62,13 @@ public List<MissionPostVo> getMissionPostList(Long farmClubId) {
.where(missionPostLike.missionPost.eq(missionPost)),
JPAExpressions.select(missionPostComment.count())
.from(missionPostComment)
.where(missionPostComment.missionPost.eq(missionPost))))
.where(missionPostComment.missionPost.eq(missionPost)),
JPAExpressions.selectOne()
.from(missionPostLike)
.where(missionPostLike.missionPost.eq(missionPost)
.and(missionPostLike.user.id.eq(userId)))
.exists()
))
.from(missionPost)
.join(missionPost.userFarmClub, userFarmClub)
.join(userFarmClub.myVeggie, myVeggie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void deleteMissionPostLike(Long userId, Long missionPostId) {
missionPostHelper.deleteMissionPostLike(userId, missionPostId);
}

public GetMissionPostListResponseDto getMissionPostList(Long farmClubId) {
List<MissionPostVo> missionPosts = missionPostRepository.getMissionPostList(farmClubId);
public GetMissionPostListResponseDto getMissionPostList(Long userId, Long farmClubId) {
List<MissionPostVo> missionPosts = missionPostHelper.getMissionPostList(userId, farmClubId);
return GetMissionPostListResponseDto.of(missionPosts);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public record MissionPostVo(
String image,
String content,
Long likeCount,
Long commentCount
Long commentCount,
Boolean isLiked
) {
@QueryProjection
public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long commentCount)
public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long commentCount, Boolean isLiked)
{
this(
missionPost.getId(),
Expand All @@ -25,7 +26,8 @@ public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long co
missionPost.getImage(),
missionPost.getContent(),
likeCount,
commentCount
commentCount,
isLiked
);
}
}

0 comments on commit 2419930

Please sign in to comment.