Skip to content

Commit

Permalink
[feat] 호스트 정보 조회 api 에러상황 추가
Browse files Browse the repository at this point in the history
[feat] 호스트 정보 조회 api 에러상황 추가
  • Loading branch information
bo-ram-bo-ram authored Sep 17, 2024
2 parents b1363cb + 1c826fe commit fe83c28
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pickple.server.api.host.dto.response.HostIntroGetResponse;
import com.pickple.server.api.host.service.HostCommandService;
import com.pickple.server.api.host.service.HostQueryService;
import com.pickple.server.global.common.annotation.GuestId;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.response.ApiResponseDto;
import com.pickple.server.global.response.enums.SuccessCode;
Expand All @@ -27,8 +28,8 @@ public class HostController implements HostControllerDocs {
private final HostCommandService hostCommandService;

@GetMapping("/v2/host")
public ApiResponseDto<HostGetResponse> getHost(@HostId Long hostId) {
return ApiResponseDto.success(SuccessCode.HOST_DETAIL_GET_SUCCESS, hostQueryService.getHost(hostId));
public ApiResponseDto<HostGetResponse> getHost(@HostId final Long hostId, @GuestId final Long guestId) {
return ApiResponseDto.success(SuccessCode.HOST_DETAIL_GET_SUCCESS, hostQueryService.getHost(hostId, guestId));
}

@GetMapping("/v2/host/{hostId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pickple.server.api.host.dto.response.HostByMoimResponse;
import com.pickple.server.api.host.dto.response.HostGetResponse;
import com.pickple.server.api.host.dto.response.HostIntroGetResponse;
import com.pickple.server.global.common.annotation.GuestId;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.response.ApiResponseDto;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -23,12 +24,16 @@ public interface HostControllerDocs {
@ApiResponses(
value = {
@ApiResponse(responseCode = "20007", description = "호스트 정보 조회 성공"),
@ApiResponse(responseCode = "40405", description = "존재하지 않는 호스트입니다.")
@ApiResponse(responseCode = "40405", description = "존재하지 않는 호스트입니다."),
@ApiResponse(responseCode = "40408", description = "호스트 승인 신청이 존재하지 않습니다."),
@ApiResponse(responseCode = "40003", description = "대기중인 호스트 승인 신청이 있습니다.")
}
)
ApiResponseDto<HostGetResponse> getHost(
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH)
@HostId Long hostId
@HostId Long hostId,
@Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH)
@GuestId Long guestId
);

@Operation(summary = "모임에 해당하는 호스트 정보 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import com.pickple.server.api.moim.domain.Moim;
import com.pickple.server.api.moim.repository.MoimRepository;
import com.pickple.server.api.moimsubmission.repository.MoimSubmissionRepository;
import com.pickple.server.api.submitter.domain.Submitter;
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 @@ -22,9 +26,14 @@ public class HostQueryService {
private final HostRepository hostRepository;
private final MoimRepository moimRepository;
private final MoimSubmissionRepository moimSubmissionRepository;
private final SubmitterRepository submitterRepository;

public HostGetResponse getHost(Long hostId, Long guestId) {
Submitter submitter = submitterRepository.findSubmitterByGuestIdOrThrow(guestId);
isDuplicatedSubmission(submitter);

public HostGetResponse getHost(Long hostId) {
Host host = hostRepository.findHostByIdOrThrow(hostId);

return HostGetResponse.builder()
.hostId(host.getId())
.hostImageUrl(host.getImageUrl())
Expand Down Expand Up @@ -74,4 +83,11 @@ private int attendeeCounter(Long hostId) {
private int moimCounter(Long hostId) {
return moimRepository.CompletedMoimNumber(hostId);
}

private void isDuplicatedSubmission(Submitter submitter) {
if (submitterRepository.existsByGuestAndSubmitterState(submitter.getGuest(), submitter.getSubmitterState())) {
throw new BadRequestException(ErrorCode.DUPLICATION_SUBMITTER);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ ApiResponseDto getMoimQuestionList(
@Operation(summary = "호스트와 모임상태에 해당하는 모임 조회")
@ApiResponses(
value = {
@ApiResponse(responseCode = "20023", description = "호스트와 모임상태에 해당하는 모임 조회 성공"),
@ApiResponse(responseCode = "40408", description = "호스트와 상태에 해당하는 모임이 없습니다.")
@ApiResponse(responseCode = "20023", description = "호스트와 모임상태에 해당하는 모임 조회 성공")
}
)
ApiResponseDto getMoimListByHostAndMoimState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ApiResponseDto<List<SubmitterListGetResponse>> getSubmitterList(
value = {
@ApiResponse(responseCode = "20025", description = "호스트 신청자 승인 성공"),
@ApiResponse(responseCode = "40104", description = "관리자 계정이 아닙니다."),
@ApiResponse(responseCode = "40409", description = "존재하지 않는 호스트 승인 신청입니다.")
@ApiResponse(responseCode = "40408", description = "호스트 승인 신청이 존재하지 않습니다.")
}
)
ApiResponseDto approveSubmitter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface SubmitterRepository extends JpaRepository<Submitter, Long> {

boolean existsByGuestAndSubmitterState(Guest guest, String submitterState);

Optional<Submitter> findSubmitterById(Long id);
Expand All @@ -18,4 +19,12 @@ default Submitter findSubmitterByIdOrThrow(Long id) {
}

boolean existsByNickname(String nickname);

Optional<Submitter> findSubmitterByGuestId(Long guestId);

default Submitter findSubmitterByGuestIdOrThrow(Long guestId) {
return findSubmitterByGuestId(guestId)
.orElseThrow(() -> new CustomException(ErrorCode.SUBMITTER_NOT_FOUND));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum ErrorCode {
MOIM_NOT_FOUND(40404, HttpStatus.NOT_FOUND, "존재하지 않는 모임입니다."),
HOST_NOT_FOUND(40405, HttpStatus.NOT_FOUND, "존재하지 않는 호스트입니다"),
MOIM_SUBMISSION_NOT_FOUND(40406, HttpStatus.NOT_FOUND, "해당 모임에 신청한 내역이 없습니다."),
SUBMITTER_NOT_FOUND(40408, HttpStatus.NOT_FOUND, "존재하지 않는 호스트 승인 신청입니다."),
SUBMITTER_NOT_FOUND(40408, HttpStatus.NOT_FOUND, "호스트 승인 신청이 존재하지 않습니다."),
NOTICE_NOT_FOUND(40409, HttpStatus.NOT_FOUND, "존재하지 않는 공지사항입니다."),
COMMENT_NOT_FOUND(40410, HttpStatus.NOT_FOUND, "존재하지 않는 댓글입니다."),

Expand Down

0 comments on commit fe83c28

Please sign in to comment.