Skip to content

Commit

Permalink
Merge pull request #38 from Mojacknong/feature_37/팜클럽-생성-가능-여부-api
Browse files Browse the repository at this point in the history
Feature 37/팜클럽 생성 가능 여부 api
  • Loading branch information
MinchoGreenT authored Jul 26, 2024
2 parents 8b47b41 + 260d598 commit 5046bbe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public class FarmClubService {
private final MissionPostRepository missionPostRepository;
private final FarmClubRepository farmClubRepository;

public CreateFarmClubCheckResponseDto checkCreateFarmClub(Long userId) {
List<MyVeggieVo> 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) {
// 몽고에서 이미지, 난이도 가져오기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public List<MyVeggieVo> getMyVeggieInfo(Long userId) {
return myVeggieRepository.findMyVeggieInfoForCreate(userId);
}

public Boolean checkMyVeggie(Long userId) {
return myVeggieRepository.existsById(userId);
}

public void deleteMyVeggie(Long id) {
myVeggieRepository.deleteById(id);
}
Expand Down

0 comments on commit 5046bbe

Please sign in to comment.