From 9d028925ea85f43ad5d0d3a4ee86972a968b3fe4 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 21 Jul 2024 13:45:00 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A4=EC=97=90=20=EC=82=AC=EC=9A=A9=ED=95=A0=20?= =?UTF-8?q?=EC=B1=84=EC=86=8C=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/helper/MyVeggieHelper.java | 8 ++++++-- .../myveggiegarden/repository/MyVeggieRepository.java | 5 ++++- .../farmusspring/domain/myveggiegarden/vo/MyVeggieVo.java | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java index 0815b9be..7fb38fda 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java @@ -7,9 +7,10 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.vo.MyVeggieVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Component; +import java.util.List; + @Component @Slf4j @RequiredArgsConstructor @@ -23,8 +24,11 @@ public MyVeggie getMyVeggieEntity(Long id) { } public MyVeggieVo getMyVeggieInfo(Long userId, String veggieInfoId) { - return myVeggieRepository.findMyVeggieInfo(userId, veggieInfoId).orElse(MyVeggieVo.of(0L, "")); + return myVeggieRepository.findMyVeggieInfo(userId, veggieInfoId).orElse(MyVeggieVo.of(0L, "", "")); + } + public List getMyVeggieInfo(Long userId) { + return myVeggieRepository.findMyVeggieInfoForCreate(userId); } public void deleteMyVeggie(Long id) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java index 09fc3fd1..14dbc1e9 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java @@ -57,9 +57,12 @@ void updateMyVeggie(@Param("myVeggieId") Long myVeggieId, @Query("SELECT dc FROM diary_comment AS dc WHERE dc.id = :diaryCommentId AND dc.user = :user") Optional findDiaryCommentByIdAndUserId(@Param("diaryCommentId") Long diaryCommentId, @Param("user") User user); - @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.vo.MyVeggieVo(mv.id, mv.nickname) FROM my_veggie mv WHERE mv.user.id = :userId AND mv.veggieInfoId = :veggieInfoId") + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.vo.MyVeggieVo(mv.id, mv.veggieInfoId, mv.nickname) FROM my_veggie mv WHERE mv.user.id = :userId AND mv.veggieInfoId = :veggieInfoId") Optional findMyVeggieInfo(Long userId, String veggieInfoId); + @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.vo.MyVeggieVo(mv.id, mv.veggieInfoId, mv.nickname) FROM my_veggie mv WHERE mv.user.id = :userId AND mv.userFarmClub IS NULL") + List findMyVeggieInfoForCreate(Long userId); + @Modifying @Query("DELETE FROM diary_comment AS dc WHERE dc.id = :diaryCommentId AND dc.user = :user") void deleteDiaryCommentByIdAndUserId(@Param("diaryCommentId") Long diaryCommentId, @Param("user") User user); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/vo/MyVeggieVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/vo/MyVeggieVo.java index 4b662ca0..fa1391ff 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/vo/MyVeggieVo.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/vo/MyVeggieVo.java @@ -6,13 +6,14 @@ @Builder public record MyVeggieVo( Long myVeggieId, + String veggieInfoId, String nickname ) { @QueryProjection public MyVeggieVo {} - public static MyVeggieVo of(Long myVeggieId, String nickname) { - return new MyVeggieVo(myVeggieId, nickname); + public static MyVeggieVo of(Long myVeggieId, String veggieInfoId, String nickname) { + return new MyVeggieVo(myVeggieId, veggieInfoId, nickname); } } From 1f667cf0559772853416788a7b9272acb6e93d72 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 21 Jul 2024 13:45:11 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A4=EC=9A=A9=20=EC=B1=84=EC=86=8C=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=EA=B8=B0=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/controller/FarmClubController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 33da645f..4f1089bb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -2,7 +2,6 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.*; -import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; import com.modernfarmer.farmusspring.domain.farmclub.service.MissionPostService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -44,9 +43,10 @@ public BaseResponseDto registerFarmClub( @GetMapping("/search") public BaseResponseDto searchFarmClub( @RequestParam(required = false) List difficulties, - @RequestParam(required = false) String keyword + @RequestParam(required = false) String keyword, + @AuthenticationPrincipal CustomUser user ) { - return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword)); + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword, user.getUserId())); } @GetMapping("/{id}") @@ -121,7 +121,14 @@ public BaseResponseDto getMyVeggieForRegister( @AuthenticationPrincipal CustomUser user, @RequestParam String veggieInfoId ) { - return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyVeggie(user.getUserId(), veggieInfoId)); + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyVeggieForRegister(user.getUserId(), veggieInfoId)); + } + + @GetMapping("/my-veggie/create") + public BaseResponseDto getMyVeggieForCreate( + @AuthenticationPrincipal CustomUser user + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyVeggieForCreate(user.getUserId())); } @GetMapping("/{farmClubId}/help") From c75fb53e3376191f84235ae5b6bdbf12f0830a03 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 21 Jul 2024 13:45:40 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[fix]=20=EC=9D=B4=EB=AF=B8=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85=ED=95=9C=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20=ED=95=84?= =?UTF-8?q?=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/helper/FarmClubHelper.java | 6 ++++++ .../repository/UserFarmClubRepositoryCustom.java | 4 ++++ .../repository/UserFarmClubRepositoryImpl.java | 11 +++++++++++ .../domain/farmclub/service/FarmClubService.java | 14 +++++++++++--- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java index 4aa7219a..2474d20b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java @@ -6,6 +6,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.FarmClubRepository; +import com.modernfarmer.farmusspring.domain.farmclub.repository.UserFarmClubRepository; import com.modernfarmer.farmusspring.domain.history.vo.HistoryDetailVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,6 +20,7 @@ public class FarmClubHelper { private final FarmClubRepository farmClubRepository; + private final UserFarmClubRepository userFarmClubRepository; public FarmClub getFarmClubEntity(Long id) { return farmClubRepository.findById(id).orElseThrow(() -> @@ -32,4 +34,8 @@ public HistoryDetailVo getFarmClubDetail(Long userFarmClubId) { public List getRecommendedFarmClubList(String level) { return farmClubRepository.getRecommendedFarmClubList(level); } + + public List findFarmClubIdsByUserId(Long userId) { + return userFarmClubRepository.findFarmClubIdsByUserId(userId); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java index c7ec6c1e..457f665d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java @@ -2,7 +2,11 @@ import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import java.util.List; + public interface UserFarmClubRepositoryCustom { UserFarmClub findByUserIdAndFarmClubId(Long userId, Long farmClubId); + + List findFarmClubIdsByUserId(Long userId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java index 1c80756c..4f974678 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java @@ -4,6 +4,8 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import java.util.List; + import static com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub.userFarmClub; @RequiredArgsConstructor @@ -20,4 +22,13 @@ public UserFarmClub findByUserIdAndFarmClubId(Long userId, Long farmClubId) { .and(userFarmClub.farmClub.id.eq(farmClubId))) .fetchOne(); } + + @Override + public List findFarmClubIdsByUserId(Long userId) { + return queryFactory + .select(userFarmClub.farmClub.id) + .from(userFarmClub) + .where(userFarmClub.userId.eq(userId)) + .fetch(); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 0f2b88bf..5e45bcf6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -70,8 +70,12 @@ public GetRecommendFarmClubResponseDto getRecommendedFarmClubList(Long userId) { ); } - public List searchFarmClub(List difficulties, String keyword) { - return farmClubRepository.findByConditions(difficulties, keyword); + public List searchFarmClub(List difficulties, String keyword, Long userId) { + List farmClubIds = farmClubHelper.findFarmClubIdsByUserId(userId); + List farmClubs = farmClubRepository.findByConditions(difficulties, keyword); + return farmClubs.stream() + .filter(farmClub -> !farmClubIds.contains(farmClub.id())) + .toList(); } @Transactional @@ -108,11 +112,15 @@ public List getMyFarmClubList(Long userId) { return farmClubRepository.findMyFarmClubList(userId); } - public GetMyVeggieResponseDto getMyVeggie(Long userId, String veggieInfoId) { + public GetMyVeggieResponseDto getMyVeggieForRegister(Long userId, String veggieInfoId) { MyVeggieVo myVeggie = myVeggieHelper.getMyVeggieInfo(userId, veggieInfoId); return GetMyVeggieResponseDto.of(myVeggie.myVeggieId(), myVeggie.nickname()); } + public List getMyVeggieForCreate(Long userId) { + return myVeggieHelper.getMyVeggieInfo(userId); + } + public GetHelpAllResponseDto getHelpAll(Long farmClubId) { String veggieInfoId = farmClubHelper.getFarmClubEntity(farmClubId).getVeggieInfoId(); VeggieInfo veggieInfoEntity = veggieInfoHelper.getVeggieInfoEntity(veggieInfoId); From 433032a7ee03f77ebdbd0e2908f39162fdb355fb Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 21 Jul 2024 13:53:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20=EC=B5=9C=EB=8C=80=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=EC=9D=B8=20=ED=8C=9C=ED=81=B4=EB=9F=BD,=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EC=8B=9C=EC=9E=91=ED=95=9C=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=ED=95=84=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/service/FarmClubService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 5e45bcf6..82a85438 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -75,6 +75,8 @@ public List searchFarmClub(List difficulties, List farmClubs = farmClubRepository.findByConditions(difficulties, keyword); return farmClubs.stream() .filter(farmClub -> !farmClubIds.contains(farmClub.id())) + .filter(farmClub -> farmClub.maxUser() > farmClub.curUser()) + .filter(farmClub -> farmClub.startedAt().compareTo(LocalDate.now().toString()) >= 0) .toList(); }