Skip to content

Commit

Permalink
[Fix] 챕터 보상 수령 처리 API 요청을 두 번 이상 보낼 수 있는 문제를 해결했습니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
NARUBROWN committed Nov 29, 2024
1 parent 48478ca commit d6c4039
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.codingland.common.exception.chapter;

import com.codingland.common.common.ApplicationResponse;
import com.codingland.common.common.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum HasReceivedRewardErrorCode implements BaseErrorCode {
ALREADY_EXIST(HttpStatus.BAD_REQUEST, "2000", "챕터 보상을 이미 받았습니다.")
;
private final HttpStatus httpStatus;
private final String code;
private final String message;

@Override
public ApplicationResponse<String> getErrorResponse() {
return ApplicationResponse.server(code, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.codingland.common.exception.chapter;

import com.codingland.common.common.BaseErrorCode;
import lombok.Getter;

@Getter
public class HasReceivedRewardException extends RuntimeException {
private final BaseErrorCode errorCode;
private final Throwable cause;

public HasReceivedRewardException(BaseErrorCode errorCode) {
this.errorCode = errorCode;
this.cause = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.codingland.domain.chapter.service;

import com.codingland.common.exception.chapter.ChapterErrorCode;
import com.codingland.common.exception.chapter.ChapterException;
import com.codingland.common.exception.chapter.*;
import com.codingland.common.exception.user.UserErrorCode;
import com.codingland.common.exception.user.UserException;
import com.codingland.domain.chapter.entity.Chapter;
Expand Down Expand Up @@ -34,6 +33,9 @@ public void processChapterReward(Long chapter_id, Long user_id) {
.orElseThrow(() -> new ChapterException(ChapterErrorCode.NOT_FOUND_CHAPTER_ERROR));
User foundUser = userRepository.findById(user_id)
.orElseThrow(() -> new UserException(UserErrorCode.No_USER_INFO));
if (hasReceivedRewardRepository.findByChapterAndUser(foundChapter, foundUser).isPresent()) {
throw new HasReceivedRewardException(HasReceivedRewardErrorCode.ALREADY_EXIST);
}
HasReceivedReward hasReceivedReward = HasReceivedReward.thisRewardHasReceived(foundChapter, foundUser);
hasReceivedRewardRepository.save(hasReceivedReward);
}
Expand Down

0 comments on commit d6c4039

Please sign in to comment.