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

[BE] 회고 중복 생성 버그 수정 #938

Merged
merged 3 commits into from
Oct 30, 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 @@ -39,15 +39,17 @@ public ResponseEntity<Void> createRetrospect(

@GetMapping("/retrospects")
public ResponseEntity<FindRetrospectsResponse> findRetrospects(
@CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken) {
@CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken
) {
final FindRetrospectsResponse response = retrospectService.findAllRetrospectsByMember(credentialToken);
return ResponseEntity.ok(response);
}

@GetMapping("/retrospects/{accessCode}")
public ResponseEntity<FindRetrospectByIdResponse> getRetrospect(
@CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken,
@PathVariable("accessCode") final String accessCode) {
@PathVariable("accessCode") final String accessCode
) {
final Retrospect retrospect = retrospectService.findRetrospectByAccessCode(credentialToken, accessCode);
final FindRetrospectByIdResponse response = FindRetrospectByIdResponse.from(retrospect);
return ResponseEntity.ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import lombok.extern.slf4j.Slf4j;
import site.coduo.common.controller.response.ApiErrorResponse;
import site.coduo.retrospect.controller.error.RetrospectApiError;
import site.coduo.retrospect.exception.DuplicateRetrospectException;
import site.coduo.retrospect.exception.InvalidRetrospectContentException;
import site.coduo.retrospect.exception.InvalidRetrospectInputValueException;
import site.coduo.retrospect.exception.InvalidRetrospectQuestionTypeException;
import site.coduo.retrospect.exception.NotRetrospectOwnerAccessException;
import site.coduo.retrospect.exception.RetrospectException;
import site.coduo.retrospect.exception.RetrospectNotFoundException;

@Slf4j
Expand Down Expand Up @@ -47,6 +49,14 @@ public ResponseEntity<ApiErrorResponse> handleInvalidRetrospectQuestionTypeExcep
.body(new ApiErrorResponse(RetrospectApiError.INVALID_RETROSPECT_QUESTION_TYPE_ERROR.getMessage()));
}

@ExceptionHandler(DuplicateRetrospectException.class)
public ResponseEntity<ApiErrorResponse> handleDuplicateRetrospectException(final DuplicateRetrospectException e) {
log.warn(e.getMessage());

return ResponseEntity.status(RetrospectApiError.DUPLICATE_RETROSPECT_ERROR.getHttpStatus())
.body(new ApiErrorResponse(RetrospectApiError.DUPLICATE_RETROSPECT_ERROR.getMessage()));
}

@ExceptionHandler(NotRetrospectOwnerAccessException.class)
public ResponseEntity<ApiErrorResponse> handleNotRetrospectOwnerAccessException(
final NotRetrospectOwnerAccessException e) {
Expand All @@ -64,4 +74,12 @@ public ResponseEntity<ApiErrorResponse> handleRetrospectNotFoundException(
return ResponseEntity.status(RetrospectApiError.RETROSPECT_NOT_FOUND_ERROR.getHttpStatus())
.body(new ApiErrorResponse(RetrospectApiError.RETROSPECT_NOT_FOUND_ERROR.getMessage()));
}

@ExceptionHandler(RetrospectException.class)
public ResponseEntity<ApiErrorResponse> handleRetrospectException(final RetrospectException e) {
log.warn(e.getMessage());

return ResponseEntity.status(RetrospectApiError.INVALID_RETROSPECT_REQUEST_ERROR.getHttpStatus())
.body(new ApiErrorResponse(RetrospectApiError.INVALID_RETROSPECT_REQUEST_ERROR.getMessage()));
}
Comment on lines +78 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 인마가 없어서 RetrospectException 상속해도 핸들러에서 안잡혔었군요.... 감샤합니당 수고하셨습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인마가 잘못했네요.

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
@RequiredArgsConstructor
public enum RetrospectApiError {

INVALID_RETROSPECT_REQUEST_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 회고 요청입니다."),
INVALID_RETROSPECT_CONTENT_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 내용입니다."),
INVALID_RETROSPECT_QUESTION_TYPE_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 질문 유형입니다."),
INVALID_RETROSPECT_INPUT_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 입력 값입니다."),
NOT_RETROSPECT_OWNER_ACCESS_ERROR(HttpStatus.FORBIDDEN, "회고 소유자 외 접근할 수 없는 작업입니다."),
RETROSPECT_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 요청의 회고가 존재하지 않습니다."),
MAX_RETROSPECT_LIMIT_REACHED_ERROR(HttpStatus.BAD_REQUEST, "회고는 최대 6개까지 추가할 수 있습니다."),
DUPLICATE_RETROSPECT_ERROR(HttpStatus.BAD_REQUEST, "이미 회고가 작성되었습니다."),
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package site.coduo.retrospect.exception;

public class DuplicateRetrospectException extends RetrospectException {

public DuplicateRetrospectException(final String message) {
super(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import site.coduo.retrospect.domain.Retrospect;
import site.coduo.retrospect.domain.RetrospectContent;
import site.coduo.retrospect.domain.RetrospectContents;
import site.coduo.retrospect.exception.MaxRetrospectLimitException;
import site.coduo.retrospect.exception.DuplicateRetrospectException;
import site.coduo.retrospect.exception.NotRetrospectOwnerAccessException;
import site.coduo.retrospect.repository.RetrospectEntity;
import site.coduo.retrospect.repository.RetrospectRepository;
Expand All @@ -44,7 +44,7 @@ public void createRetrospect(
final Member member = memberService.findMemberByCredential(credentialToken);
final PairRoomMemberEntity pairRoomMember = pairRoomMemberRepository.fetchByPairRoomAndMember(pairRoom, member);
if (retrospectRepository.existsRetrospectEntityByPairRoomMember(pairRoomMember)) {
throw new MaxRetrospectLimitException("회고가 이미 존재합니다.");
throw new DuplicateRetrospectException("해당 페어룸에 대한 사용자의 회고가 이미 존재합니다.");
}
final RetrospectContents retrospectContents = RetrospectContents.from(answers);
final Retrospect retrospect = new Retrospect(retrospectContents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import site.coduo.pairroom.repository.PairRoomRepository;
import site.coduo.referencelink.repository.CategoryRepository;
import site.coduo.retrospect.controller.response.FindRetrospectsResponse;
import site.coduo.retrospect.exception.MaxRetrospectLimitException;
import site.coduo.retrospect.exception.DuplicateRetrospectException;
import site.coduo.retrospect.repository.RetrospectEntity;
import site.coduo.retrospect.repository.RetrospectRepository;
import site.coduo.timer.repository.TimerRepository;
Expand Down Expand Up @@ -134,7 +134,7 @@ void createTwiceRetrospect() {
// When && Then
assertThatThrownBy(
() -> retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), answers))
.isInstanceOf(MaxRetrospectLimitException.class);
.isInstanceOf(DuplicateRetrospectException.class);

}

Expand Down
Loading