diff --git a/src/main/java/com/pickple/server/api/host/service/HostCommandService.java b/src/main/java/com/pickple/server/api/host/service/HostCommandService.java index 138e51a..3d22b24 100644 --- a/src/main/java/com/pickple/server/api/host/service/HostCommandService.java +++ b/src/main/java/com/pickple/server/api/host/service/HostCommandService.java @@ -5,6 +5,7 @@ import com.pickple.server.api.host.domain.Host; import com.pickple.server.api.host.dto.request.HostUpdateRequest; import com.pickple.server.api.host.repository.HostRepository; +import com.pickple.server.api.submitter.domain.SubmitterState; import com.pickple.server.api.submitter.repository.SubmitterRepository; import com.pickple.server.global.exception.CustomException; import com.pickple.server.global.response.enums.ErrorCode; @@ -26,7 +27,8 @@ public void updateHostProfile(Long hostId, HostUpdateRequest hostUpdateRequest) if (!host.getNickname().equals(hostUpdateRequest.nickname()) && (hostRepository.existsByNickname(hostUpdateRequest.nickname()) || guestRepository.existsByNickname(hostUpdateRequest.nickname()) - || submitterRepository.existsByNicknameAndSubmitterState(hostUpdateRequest.nickname(), "pending"))) { + || submitterRepository.existsByNicknameAndSubmitterState(hostUpdateRequest.nickname(), + SubmitterState.PENDING.getSubmitterState()))) { throw new CustomException(ErrorCode.DUPLICATION_NICKNAME); } @@ -34,5 +36,8 @@ public void updateHostProfile(Long hostId, HostUpdateRequest hostUpdateRequest) hostUpdateRequest.keyword(), hostUpdateRequest.description(), hostUpdateRequest.socialLink()); + submitterRepository.findSubmitterByGuestId(guestRepository.findGuestByUserId(host.getUser().getId()).getId()) + .updateSubmitterNickname(hostUpdateRequest.nickname()); + } } diff --git a/src/main/java/com/pickple/server/api/submitter/controller/SubmitterController.java b/src/main/java/com/pickple/server/api/submitter/controller/SubmitterController.java index 7665a08..16229d6 100644 --- a/src/main/java/com/pickple/server/api/submitter/controller/SubmitterController.java +++ b/src/main/java/com/pickple/server/api/submitter/controller/SubmitterController.java @@ -28,8 +28,8 @@ public class SubmitterController implements SubmitterControllerDocs { private final SubmitterQueryService submitterQueryService; @PostMapping("/v2/submitter") - public ApiResponseDto postSubmitter(@GuestId final Long guestId, - @RequestBody @Valid SubmitterCreateRequest submitterCreateRequest) { + public ApiResponseDto createSubmitter(@GuestId final Long guestId, + @RequestBody @Valid SubmitterCreateRequest submitterCreateRequest) { submitterCommandService.createSubmitter(guestId, submitterCreateRequest); return ApiResponseDto.success(SuccessCode.SUBMITTER_POST_SUCCESS); } diff --git a/src/main/java/com/pickple/server/api/submitter/controller/SubmitterControllerDocs.java b/src/main/java/com/pickple/server/api/submitter/controller/SubmitterControllerDocs.java index 821b607..8d3fd1e 100644 --- a/src/main/java/com/pickple/server/api/submitter/controller/SubmitterControllerDocs.java +++ b/src/main/java/com/pickple/server/api/submitter/controller/SubmitterControllerDocs.java @@ -23,10 +23,11 @@ public interface SubmitterControllerDocs { value = { @ApiResponse(responseCode = "20005", description = "호스트 승인 신청 성공"), @ApiResponse(responseCode = "40003", description = "대기중인 호스트 승인 신청이 있습니다."), - @ApiResponse(responseCode = "40403", description = "존재하지 않는 게스트입니다.") + @ApiResponse(responseCode = "40403", description = "존재하지 않는 게스트입니다."), + @ApiResponse(responseCode = "40013", description = "이미 호스트 입니다.") } ) - ApiResponseDto postSubmitter( + ApiResponseDto createSubmitter( @Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) @GuestId final Long guestId, @RequestBody SubmitterCreateRequest submitterCreateRequest diff --git a/src/main/java/com/pickple/server/api/submitter/domain/Submitter.java b/src/main/java/com/pickple/server/api/submitter/domain/Submitter.java index 402a38d..6b6febb 100644 --- a/src/main/java/com/pickple/server/api/submitter/domain/Submitter.java +++ b/src/main/java/com/pickple/server/api/submitter/domain/Submitter.java @@ -57,4 +57,8 @@ public void updateSubmitterState(String submitterState) { this.submitterState = submitterState; } + public void updateSubmitterNickname(String hostNickname) { + this.nickname = hostNickname; + } + } diff --git a/src/main/java/com/pickple/server/api/submitter/domain/SubmitterCategoryInfo.java b/src/main/java/com/pickple/server/api/submitter/domain/SubmitterCategoryInfo.java deleted file mode 100644 index 279bc64..0000000 --- a/src/main/java/com/pickple/server/api/submitter/domain/SubmitterCategoryInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.pickple.server.api.submitter.domain; - -import jakarta.validation.constraints.NotBlank; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -@Builder -public class SubmitterCategoryInfo { - - @NotBlank(message = "카테고리가 비었습니다.") - private final String category1; - - private final String category2; - - private final String category3; - -} diff --git a/src/main/java/com/pickple/server/api/submitter/repository/SubmitterRepository.java b/src/main/java/com/pickple/server/api/submitter/repository/SubmitterRepository.java index c2d0948..6cd7a55 100644 --- a/src/main/java/com/pickple/server/api/submitter/repository/SubmitterRepository.java +++ b/src/main/java/com/pickple/server/api/submitter/repository/SubmitterRepository.java @@ -19,4 +19,6 @@ default Submitter findSubmitterByIdOrThrow(Long id) { } boolean existsByNicknameAndSubmitterState(String nickname, String submitterState); + + Submitter findSubmitterByGuestId(Long guestId); } \ No newline at end of file diff --git a/src/main/java/com/pickple/server/api/submitter/service/SubmitterCommandService.java b/src/main/java/com/pickple/server/api/submitter/service/SubmitterCommandService.java index 82450d5..a819c0a 100644 --- a/src/main/java/com/pickple/server/api/submitter/service/SubmitterCommandService.java +++ b/src/main/java/com/pickple/server/api/submitter/service/SubmitterCommandService.java @@ -10,7 +10,6 @@ import com.pickple.server.api.submitter.dto.request.SubmitterCreateRequest; import com.pickple.server.api.submitter.repository.SubmitterRepository; import com.pickple.server.api.user.domain.Role; -import com.pickple.server.global.exception.BadRequestException; import com.pickple.server.global.exception.CustomException; import com.pickple.server.global.response.enums.ErrorCode; import jakarta.transaction.Transactional; @@ -28,7 +27,10 @@ public class SubmitterCommandService { public void createSubmitter(Long guestId, SubmitterCreateRequest request) { Guest guest = guestRepository.findGuestByIdOrThrow(guestId); + + isDuplicatedSubmission(guest); isDuplicatedNickname(request.nickname()); + Submitter submitter = Submitter.builder() .guest(guest) .intro(request.intro()) @@ -40,7 +42,7 @@ public void createSubmitter(Long guestId, SubmitterCreateRequest request) { .userKeyword(request.userKeyword()) .submitterState(SubmitterState.PENDING.getSubmitterState()) .build(); - isDuplicatedSubmission(submitter); + submitterRepository.save(submitter); } @@ -64,9 +66,12 @@ public void approveSubmitter(Long submitterId) { hostRepository.save(host); } - private void isDuplicatedSubmission(Submitter submitter) { - if (submitterRepository.existsByGuestAndSubmitterState(submitter.getGuest(), submitter.getSubmitterState())) { - throw new BadRequestException(ErrorCode.DUPLICATION_SUBMITTER); + private void isDuplicatedSubmission(Guest guest) { + if (submitterRepository.existsByGuestAndSubmitterState(guest, SubmitterState.APPROVE.getSubmitterState())) { + throw new CustomException(ErrorCode.DUPLICATION_APPROVE_SUBMITTER); + } else if (submitterRepository.existsByGuestAndSubmitterState(guest, + SubmitterState.PENDING.getSubmitterState())) { + throw new CustomException(ErrorCode.DUPLICATION_PENDING_SUBMITTER); } } diff --git a/src/main/java/com/pickple/server/global/common/annotation/resolver/HostIdResolver.java b/src/main/java/com/pickple/server/global/common/annotation/resolver/HostIdResolver.java index ec5c5c5..3455d8b 100644 --- a/src/main/java/com/pickple/server/global/common/annotation/resolver/HostIdResolver.java +++ b/src/main/java/com/pickple/server/global/common/annotation/resolver/HostIdResolver.java @@ -4,6 +4,7 @@ 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.domain.SubmitterState; import com.pickple.server.api.submitter.repository.SubmitterRepository; import com.pickple.server.global.common.annotation.HostId; import com.pickple.server.global.exception.BadRequestException; @@ -53,8 +54,8 @@ public Object resolveArgument(MethodParameter parameter, } private void isDuplicatedSubmission(Guest guest) { - if (submitterRepository.existsByGuestAndSubmitterState(guest, "pending")) { - throw new BadRequestException(ErrorCode.DUPLICATION_SUBMITTER); + if (submitterRepository.existsByGuestAndSubmitterState(guest, SubmitterState.PENDING.getSubmitterState())) { + throw new BadRequestException(ErrorCode.DUPLICATION_PENDING_SUBMITTER); } } diff --git a/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java b/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java index 326c902..a33386c 100644 --- a/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java +++ b/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java @@ -12,7 +12,7 @@ public enum ErrorCode { ENUM_VALUE_BAD_REQUEST(40000, HttpStatus.BAD_REQUEST, "요청한 값이 유효하지 않습니다."), AUTHENTICATION_CODE_EXPIRED(40001, HttpStatus.BAD_REQUEST, "인가 코드가 만료되었습니다."), SOCIAL_TYPE_BAD_REQUEST(40002, HttpStatus.BAD_REQUEST, "로그인 요청이 유효하지 않습니다."), - DUPLICATION_SUBMITTER(40003, HttpStatus.BAD_REQUEST, "대기중인 호스트 승인 신청이 있습니다."), + DUPLICATION_PENDING_SUBMITTER(40003, HttpStatus.BAD_REQUEST, "대기중인 호스트 승인 신청이 있습니다."), BAD_REQUEST(40004, HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), MISSING_REQUIRED_HEADER(40005, HttpStatus.BAD_REQUEST, "필수 헤더가 누락되었습니다."), MISSING_REQUIRED_PARAMETER(40006, HttpStatus.BAD_REQUEST, "필수 파라미터가 누락되었습니다."), @@ -22,6 +22,7 @@ public enum ErrorCode { DUPLICATION_REVIEW(40010, HttpStatus.BAD_REQUEST, "해당 사용자가 이미 작성한 리뷰가 존재합니다"), NO_SUBMISSION_FOUND_FOR_REVIEW(40011, HttpStatus.BAD_REQUEST, "리뷰를 작성할 수 있는 신청이 없습니다"), NOT_AUTHOR(40012, HttpStatus.BAD_REQUEST, "해당 댓글의 작성자가 아닙니다."), + DUPLICATION_APPROVE_SUBMITTER(40013, HttpStatus.BAD_REQUEST, "이미 호스트입니다."), // 401 Unauthorized ACCESS_TOKEN_EXPIRED(40100, HttpStatus.UNAUTHORIZED, "액세스 토큰이 만료되었습니다."), @@ -58,4 +59,5 @@ public enum ErrorCode { private final int code; private final HttpStatus httpStatus; private final String message; + }