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 4f1089bb..bf32fd2f 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 @@ -147,4 +147,11 @@ public BaseResponseDto withdrawFarmClub( farmClubService.withdrawFarmClub(farmClubId, user.getUserId(), deleteVeggie); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } + + @GetMapping("/check") + public BaseResponseDto createFarmClubCheck( + @AuthenticationPrincipal CustomUser user + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.checkCreateFarmClub(user.getUserId())); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubCheckResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubCheckResponseDto.java new file mode 100644 index 00000000..146aa1d6 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubCheckResponseDto.java @@ -0,0 +1,17 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record CreateFarmClubCheckResponseDto( + Boolean isPossible, + Long reason +) { + public static CreateFarmClubCheckResponseDto of(Boolean isPossible, Long reason) { + return CreateFarmClubCheckResponseDto.builder() + .isPossible(isPossible) + .reason(reason) + .build(); + } +} 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 82a85438..1c66ab4f 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 @@ -41,6 +41,21 @@ public class FarmClubService { private final MissionPostRepository missionPostRepository; private final FarmClubRepository farmClubRepository; + public CreateFarmClubCheckResponseDto checkCreateFarmClub(Long userId) { + List myVeggieList = myVeggieHelper.getMyVeggieInfo(userId); + log.info("myVeggieList: {}", myVeggieList); + if (!myVeggieList.isEmpty()) { + return CreateFarmClubCheckResponseDto.of(true, 0L); + } else { + if (myVeggieHelper.checkMyVeggie(userId)) { + return CreateFarmClubCheckResponseDto.of(false, 1L); + } else { + return CreateFarmClubCheckResponseDto.of(false, 2L); + + } + } + } + @Transactional public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request, Long userId) { // 몽고에서 이미지, 난이도 가져오기 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 7fb38fda..9cdf71a4 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 @@ -31,6 +31,10 @@ public List getMyVeggieInfo(Long userId) { return myVeggieRepository.findMyVeggieInfoForCreate(userId); } + public Boolean checkMyVeggie(Long userId) { + return myVeggieRepository.existsById(userId); + } + public void deleteMyVeggie(Long id) { myVeggieRepository.deleteById(id); }