Skip to content

Commit

Permalink
[feat] @hostid 검증 로직 추가 구현
Browse files Browse the repository at this point in the history
[feat] @hostid 검증 로직 추가 구현
  • Loading branch information
bo-ram-bo-ram authored Sep 17, 2024
2 parents 3b396d2 + 3781f27 commit f2a5a08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.moimsubmission.repository.MoimSubmissionRepository;
import com.pickple.server.api.submitter.repository.SubmitterRepository;
import com.pickple.server.global.exception.BadRequestException;
import com.pickple.server.global.response.enums.ErrorCode;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand All @@ -33,8 +31,6 @@ public class HostQueryService {
public HostGetResponse getHost(Long hostId, Long guestId) {
Guest guest = guestRepository.findGuestByIdOrThrow(guestId);

isDuplicatedSubmission(guest);

Host host = hostRepository.findHostByIdOrThrow(hostId);

return HostGetResponse.builder()
Expand Down Expand Up @@ -87,10 +83,4 @@ private int moimCounter(Long hostId) {
return moimRepository.CompletedMoimNumber(hostId);
}

private void isDuplicatedSubmission(Guest guest) {
if (submitterRepository.existsByGuestAndSubmitterState(guest, "pending")) {
throw new BadRequestException(ErrorCode.DUPLICATION_SUBMITTER);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private MoimSubmissionAllResponse mapToMoimSubmissionAllResponse(MoimSubmission

private boolean isApprovable(Moim moim) {
// 모임일
System.out.println(moim.getId());
LocalDate date = moim.getDateList().getDate();

// 마감일: 신청일 + 3일의 자정
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.pickple.server.global.common.annotation.resolver;

import com.pickple.server.api.guest.domain.Guest;
import com.pickple.server.api.guest.repository.GuestRepository;
import com.pickple.server.api.host.domain.Host;
import com.pickple.server.api.host.repository.HostRepository;
import com.pickple.server.api.submitter.repository.SubmitterRepository;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.exception.BadRequestException;
import com.pickple.server.global.exception.CustomException;
import com.pickple.server.global.response.enums.ErrorCode;
import java.security.Principal;
Expand All @@ -19,6 +23,8 @@
public class HostIdResolver implements HandlerMethodArgumentResolver {

private final HostRepository hostRepository;
private final SubmitterRepository submitterRepository;
private final GuestRepository guestRepository;

@Override
public boolean supportsParameter(MethodParameter parameter) {
Expand All @@ -35,10 +41,21 @@ public Object resolveArgument(MethodParameter parameter,
if (principal == null) {
throw new CustomException(ErrorCode.EMPTY_PRINCIPAL);
}

// 대기중인 호스트 신청이 있는지 검증
isDuplicatedSubmission(guestRepository.findGuestByUserId(Long.valueOf(principal.getName())));

Host host = hostRepository.findHostByUserId(Long.valueOf(principal.getName()));
if (host == null) {
throw new CustomException(ErrorCode.HOST_NOT_FOUND);
}
return host.getId();
}

private void isDuplicatedSubmission(Guest guest) {
if (submitterRepository.existsByGuestAndSubmitterState(guest, "pending")) {
throw new BadRequestException(ErrorCode.DUPLICATION_SUBMITTER);
}
}

}

0 comments on commit f2a5a08

Please sign in to comment.