Skip to content

Commit

Permalink
[�merge] 호스트 닉네임 변경 시 호스트 승인신청에 반영
Browse files Browse the repository at this point in the history
[feat] 호스트 닉네임 변경 시 호스트 승인신청에 반영
  • Loading branch information
bo-ram-bo-ram authored Sep 18, 2024
2 parents 6ee5653 + 874b18d commit 0ace969
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,13 +27,17 @@ 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);
}

host.updateHostProfile(hostUpdateRequest.profileUrl(), hostUpdateRequest.nickname(),
hostUpdateRequest.keyword(),
hostUpdateRequest.description(), hostUpdateRequest.socialLink());

submitterRepository.findSubmitterByGuestId(guestRepository.findGuestByUserId(host.getUser().getId()).getId())
.updateSubmitterNickname(hostUpdateRequest.nickname());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public void updateSubmitterState(String submitterState) {
this.submitterState = submitterState;
}

public void updateSubmitterNickname(String hostNickname) {
this.nickname = hostNickname;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ default Submitter findSubmitterByIdOrThrow(Long id) {
}

boolean existsByNicknameAndSubmitterState(String nickname, String submitterState);

Submitter findSubmitterByGuestId(Long guestId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand All @@ -40,7 +42,7 @@ public void createSubmitter(Long guestId, SubmitterCreateRequest request) {
.userKeyword(request.userKeyword())
.submitterState(SubmitterState.PENDING.getSubmitterState())
.build();
isDuplicatedSubmission(submitter);

submitterRepository.save(submitter);
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "필수 파라미터가 누락되었습니다."),
Expand All @@ -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, "액세스 토큰이 만료되었습니다."),
Expand Down Expand Up @@ -58,4 +59,5 @@ public enum ErrorCode {
private final int code;
private final HttpStatus httpStatus;
private final String message;

}

0 comments on commit 0ace969

Please sign in to comment.