-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: 회원 탈퇴 재가입 처리 개선 및 OAuth/AI 리뷰 에러 해결 #202
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package org.ezcode.codetest.domain.user.model.entity; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
|
|
@@ -171,8 +173,18 @@ public void modifyUserInfo(String nickname, String githubUrl, String blogUrl, St | |
| } | ||
|
|
||
|
|
||
| public void setDeleted() { | ||
| /** | ||
| * 회원 탈퇴 시 호출되는 메서드 | ||
| * - isDeleted 플래그를 true로 설정 | ||
| * - 이메일을 변경하여 동일 이메일 재가입 시 unique key 충돌 방지 | ||
| * (예: [email protected] -> [email protected]__deleted_20231220) | ||
| */ | ||
| public void markAsDeleted() { | ||
| this.isDeleted = true; | ||
| if (this.email != null && !this.email.isBlank()) { | ||
| String deletedDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
| this.email = this.email + "__deleted_" + deletedDate; | ||
| } | ||
| } | ||
|
|
||
| public boolean shouldSkipNotification(User recipient) { | ||
|
|
@@ -188,10 +200,6 @@ public void setVerified(){ | |
| this.verified = true; | ||
| } | ||
|
|
||
| public void setReviewToken(int reviewToken){ | ||
| this.reviewToken = reviewToken; | ||
| } | ||
|
|
||
| public void setGithubUrl(String githubUrl){ | ||
| this.githubUrl = githubUrl; | ||
| } | ||
|
|
@@ -219,4 +227,21 @@ public void modifyUserRole(UserRole userRole) { | |
| public void setLanguage(Language userLanguage) { | ||
| this.language = userLanguage; | ||
| } | ||
|
|
||
| public static final int DEFAULT_REVIEW_TOKEN = 20; | ||
| public static final int FULL_WEEK_REVIEW_TOKEN = 40; | ||
|
|
||
| /** | ||
| * 기본 리뷰 토큰을 설정 이메일 인증 직후, OAuth 가입 시 사용) | ||
| */ | ||
| public void setDefaultReviewToken() { | ||
| this.reviewToken = DEFAULT_REVIEW_TOKEN; | ||
| } | ||
|
|
||
| /** | ||
| * 주간 풀 참여 리뷰 토큰을 설정 (주간 스케줄러에서 사용) | ||
| */ | ||
| public void setFullWeekReviewToken() { | ||
| this.reviewToken = FULL_WEEK_REVIEW_TOKEN; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.ezcode.codetest.domain.submission.exception.code.CodeReviewExceptionCode; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatusCode; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.interceptor.TransactionAspectSupport; | ||
|
|
@@ -30,10 +31,10 @@ | |
| @RequiredArgsConstructor | ||
| public class OpenAIReviewClient implements ReviewClient { | ||
|
|
||
| @Value("${OPEN_API_URL}") | ||
| @Value("${openai.api.url}") | ||
| private String openApiUrl; | ||
|
|
||
| @Value("${OPEN_API_KEY}") | ||
| @Value("${openai.api.key}") | ||
| private String openApiKey; | ||
| private WebClient webClient; | ||
| private final OpenAIMessageBuilder openAiMessageBuilder; | ||
|
|
@@ -77,7 +78,6 @@ public ReviewResult requestReview(ReviewPayload reviewPayload) { | |
| } | ||
|
|
||
| private String callChatApi(Map<String, Object> requestBody) { | ||
|
|
||
| OpenAIResponse response = webClient.post() | ||
| .uri("/v1/chat/completions") | ||
| .bodyValue(requestBody) | ||
|
|
@@ -87,14 +87,29 @@ private String callChatApi(Map<String, Object> requestBody) { | |
| .retryWhen( | ||
| Retry.backoff(3, Duration.ofSeconds(1)) | ||
| .maxBackoff(Duration.ofSeconds(5)) | ||
| .filter(ex -> ex instanceof WebClientResponseException | ||
| || ex instanceof TimeoutException) | ||
| .filter(ex -> { | ||
| if (ex instanceof TimeoutException) { | ||
| return true; | ||
| } | ||
| if (ex instanceof WebClientResponseException) { | ||
| HttpStatusCode statusCode = ((WebClientResponseException) ex).getStatusCode(); | ||
| // 5xx 서버 오류만 재시도 (502, 503 등) | ||
| return statusCode.is5xxServerError(); | ||
| } | ||
| return false; | ||
| }) | ||
| .onRetryExhaustedThrow((spec, signal) -> signal.failure()) | ||
| ) | ||
| .onErrorMap(WebClientResponseException.class, | ||
| ex -> new CodeReviewException(CodeReviewExceptionCode.REVIEW_SERVER_ERROR)) | ||
| .onErrorMap(TimeoutException.class, | ||
| ex -> new CodeReviewException(CodeReviewExceptionCode.REVIEW_TIMEOUT)) | ||
| .onErrorMap(WebClientResponseException.class, ex -> { | ||
| HttpStatusCode statusCode = ex.getStatusCode(); | ||
| String responseBody = ex.getResponseBodyAsString(); | ||
| log.error("OpenAI API 호출 실패 - Status: {}, Response Body: {}", statusCode, responseBody, ex); | ||
| return new CodeReviewException(CodeReviewExceptionCode.REVIEW_SERVER_ERROR); | ||
| }) | ||
| .onErrorMap(TimeoutException.class, ex -> { | ||
| log.error("OpenAI API 호출 타임아웃", ex); | ||
| return new CodeReviewException(CodeReviewExceptionCode.REVIEW_TIMEOUT); | ||
| }) | ||
| .block(); | ||
|
Comment on lines
+103
to
113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네트워크 연결 오류 처리 누락
🤖 Prompt for AI Agents |
||
|
|
||
| return Objects.requireNonNull(response).getReviewContent(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
동일 이메일 재가입 후 같은 날 탈퇴 시 unique constraint 충돌 가능성
날짜 기반 suffix만 사용하면 같은 날 동일 이메일로 재가입 후 탈퇴하는 경우 unique key 충돌이 발생할 수 있습니다:
[email protected]→ 탈퇴 →[email protected]__deleted_20231220[email protected][email protected]__deleted_20231220(충돌!)또한
markAsDeleted()가 중복 호출되면 suffix가 계속 추가됩니다.🔎 UUID 또는 고유 식별자 추가를 권장합니다
public void markAsDeleted() { this.isDeleted = true; - if (this.email != null && !this.email.isBlank()) { + if (this.email != null && !this.email.isBlank() && !this.email.contains("__deleted_")) { String deletedDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); - this.email = this.email + "__deleted_" + deletedDate; + String uniqueSuffix = java.util.UUID.randomUUID().toString().substring(0, 8); + this.email = this.email + "__deleted_" + deletedDate + "_" + uniqueSuffix; } }📝 Committable suggestion
🤖 Prompt for AI Agents