Skip to content

Commit

Permalink
Merge pull request #100 from Mojacknong/fix_99/팜클럽-버그수정
Browse files Browse the repository at this point in the history
Fix 99/팜클럽 버그수정
  • Loading branch information
Ryeolee authored Aug 21, 2024
2 parents cf22253 + c45deaa commit 86bc5c3
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ public BaseResponseDto<?> getMissionPostList(
return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(user.getUserId(), farmClubId));
}

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

@GetMapping("/my-veggie")
Expand All @@ -149,13 +150,12 @@ public BaseResponseDto<?> getFarmClubHelp(
return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getHelpAll(farmClubId));
}

@DeleteMapping
@DeleteMapping("/{farmClubId}")
public BaseResponseDto<?> withdrawFarmClub(
@RequestParam Long farmClubId,
@RequestParam Boolean deleteVeggie,
@PathVariable Long farmClubId,
@AuthenticationPrincipal CustomUser user
) {
farmClubService.withdrawFarmClub(farmClubId, user.getUserId(), deleteVeggie);
farmClubService.withdrawFarmClub(farmClubId, user.getUserId());
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.res;

import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo;
import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo;
import lombok.AccessLevel;
import lombok.Builder;

Expand All @@ -10,13 +9,15 @@
@Builder(access = AccessLevel.PRIVATE)
public record GetHelpAllResponseDto(
String veggieName,
String veggieImage,
String backgroundColor,
VeggieInfo.Help help,
List<VeggieInfo.Step> steps
) {
public static GetHelpAllResponseDto of(VeggieInfo veggieInfo) {
return builder()
.veggieName(veggieInfo.getName())
.veggieImage(veggieInfo.getVeggieImage())
.backgroundColor(veggieInfo.getBackgroundColor())
.help(veggieInfo.getHelp())
.steps(veggieInfo.getSteps())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

@Builder
public record GetMissionPostCommentResponseDto(
Boolean isMyPost,
List<MissionPostCommentVo> comments
) {
public static GetMissionPostCommentResponseDto of(List<MissionPostCommentVo> comments) {
public static GetMissionPostCommentResponseDto of(Boolean isMyPost, List<MissionPostCommentVo> comments) {
return GetMissionPostCommentResponseDto.builder()
.isMyPost(isMyPost)
.comments(comments)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.modernfarmer.farmusspring.domain.farmclub.helper;

import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMissionPostCommentResponseDto;
import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost;
import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode;
import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException;
Expand Down Expand Up @@ -31,6 +32,10 @@ public List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId) {
return missionPostRepository.getMissionPostList(userId, missionPostId);
}

public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId, Long userId) {
return missionPostRepository.getMissionPostComment(missionPostId, userId);
}

@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 @@ -81,14 +81,18 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) {
.where(farmClub.id.eq(farmClubId))
.fetchOne();

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

Long userFarmClubCount = results.get(0).get(userFarmClub.count());
Integer currentStep = results.get(0).get(userFarmClub.currentStep);
Integer currentStep = queryFactory
.select(userFarmClub.currentStep)
.from(userFarmClub)
.where(userFarmClub.userId.eq(userId).and(userFarmClub.farmClub.id.eq(farmClubId)))
.fetchOne();

LocalDate userFarmClubCreatedDate = queryFactory
.select(farmClub.startedAt)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.modernfarmer.farmusspring.domain.farmclub.repository;


import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMissionPostCommentResponseDto;
import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListVo;
import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostCommentVo;
import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo;
Expand All @@ -11,7 +12,7 @@
public interface MissionPostRepositoryCustom {

List<GetMissionPostListVo> getMissionPostStepNumAndImage(Long farmClubId);
List<MissionPostCommentVo> getMissionPostComment(Long missionPostId);
GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId, Long userId);
List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId);
List<MissionPostHistoryVo> getMissionPostHistory(Long missionPostId);
void deleteMissionPostLike(Long userId, Long missionPostId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.modernfarmer.farmusspring.domain.farmclub.repository;


import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMissionPostCommentResponseDto;
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.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -40,14 +42,21 @@ public List<GetMissionPostListVo> getMissionPostStepNumAndImage(Long farmClubId)
}

@Override
public List<MissionPostCommentVo> getMissionPostComment(Long missionPostId) {

return queryFactory
.select(new QMissionPostCommentVo(missionPostComment, user))
public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId, Long userId) {
List<MissionPostCommentVo> comments = queryFactory
.select(new QMissionPostCommentVo(missionPostComment, user, Expressions.constant(userId)))
.from(missionPostComment)
.join(missionPostComment.missionPost, missionPost)
.where(missionPost.id.eq(missionPostId))
.fetch();

Boolean isMyPost = queryFactory
.select(missionPost.userFarmClub.userId.eq(userId))
.from(missionPost)
.where(missionPost.id.eq(missionPostId))
.fetchOne();

return GetMissionPostCommentResponseDto.of(isMyPost, comments);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,9 @@ public GetHelpAllResponseDto getHelpAll(Long farmClubId) {
}

// 팜클럽 탈퇴
public void withdrawFarmClub(Long farmClubId, Long userId, Boolean deleteVeggie) {
public void withdrawFarmClub(Long farmClubId, Long userId) {
UserFarmClub userFarmClub = userFarmClubHelper.findByUserIdAndFarmClubId(userId, farmClubId);
userFarmClubHelper.deleteUserFarmClub(userFarmClub);
if (deleteVeggie) {
Long myVeggieId = userFarmClub.getMyVeggie().getId();
myVeggieHelper.getMyVeggieEntity(myVeggieId);
myVeggieHelper.deleteMyVeggie(myVeggieId);
}
}

private String getRandomTip(List<StepVo> stepList, int currentStep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public GetMissionPostListResponseDto getMissionPostList(Long userId, Long farmCl
return GetMissionPostListResponseDto.of(missionPosts);
}

public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId) {
List<MissionPostCommentVo> comments = missionPostRepository.getMissionPostComment(missionPostId);
return GetMissionPostCommentResponseDto.of(comments);
public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId, Long userId) {
return missionPostHelper.getMissionPostComment(missionPostId, userId);
}

private MissionPost saveMissionPost(MissionPost missionPost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ public record MissionPostCommentVo(
String nickname,
String profileImage,
String date,
String content
String content,
Boolean isMyComment
) {
@QueryProjection
public MissionPostCommentVo(MissionPostComment missionPostComment, User user)
public MissionPostCommentVo(MissionPostComment missionPostComment, User user, Long myId)
{
this(
missionPostComment.getId(),
user.getNickname(),
user.getProfileImage(),
missionPostComment.getCreatedDate().toString(),
missionPostComment.getComment()
missionPostComment.getComment(),
user.getId().equals(myId)
);
}
}

0 comments on commit 86bc5c3

Please sign in to comment.