Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 37/팜클럽 생성 가능 여부 api #38

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading