Repository navigation
merge: develop #705
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
merge: develop #705
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
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
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
2 changes: 2 additions & 0 deletions
2
src/main/resources/db/migration/V39__increase_question_v2_content_length.sql
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ALTER TABLE questions_v2 | ||
| ALTER COLUMN content TYPE VARCHAR(2000); |
29 changes: 29 additions & 0 deletions
29
src/main/resources/db/migration/V40__update_ranking_tier_thresholds.sql
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| UPDATE users | ||
| SET current_exp_tier = CASE | ||
| WHEN total_exp >= 50000 THEN 'DIAMOND' | ||
| WHEN total_exp >= 30000 THEN 'GOLD' | ||
| WHEN total_exp >= 10000 THEN 'SILVER' | ||
| WHEN total_exp >= 1000 THEN 'BRONZE' | ||
| ELSE 'UNRANKED' | ||
| END; | ||
|
|
||
| WITH ranked_users AS ( | ||
| SELECT | ||
| id, | ||
| total_exp, | ||
| ROW_NUMBER() OVER (ORDER BY total_exp DESC) AS rank | ||
| FROM users | ||
| WHERE user_status = 'ACTIVE' | ||
| ) | ||
| UPDATE users u | ||
| SET current_rank_tier = CASE | ||
| WHEN ru.rank = 1 AND ru.total_exp >= 150000 THEN 'AURA' | ||
| WHEN ru.rank <= 3 AND ru.total_exp >= 100000 THEN 'MASTER' | ||
| ELSE 'NONE' | ||
| END | ||
| FROM ranked_users ru | ||
| WHERE u.id = ru.id; | ||
|
|
||
| UPDATE users | ||
| SET current_rank_tier = 'NONE' | ||
| WHERE user_status <> 'ACTIVE'; | ||
122 changes: 122 additions & 0 deletions
122
...ocess/clash/adapter/web/roadmap/v2/question/controller/AdminQuestionV2ControllerTest.java
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 |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package com.process.clash.adapter.web.roadmap.v2.question.controller; | ||
|
|
||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.process.clash.adapter.web.common.GlobalExceptionHandler; | ||
| import com.process.clash.adapter.web.security.AuthenticatedActor; | ||
| import com.process.clash.application.common.actor.Actor; | ||
| import com.process.clash.application.roadmap.v2.question.port.in.CreateQuestionV2UseCase; | ||
| import com.process.clash.application.roadmap.v2.question.port.in.DeleteQuestionV2UseCase; | ||
| import com.process.clash.application.roadmap.v2.question.port.in.UpdateQuestionV2UseCase; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.core.MethodParameter; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
| import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; | ||
| import org.springframework.web.bind.support.WebDataBinderFactory; | ||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
| import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class AdminQuestionV2ControllerTest { | ||
|
|
||
| @Mock | ||
| private CreateQuestionV2UseCase createQuestionV2UseCase; | ||
|
|
||
| @Mock | ||
| private UpdateQuestionV2UseCase updateQuestionV2UseCase; | ||
|
|
||
| @Mock | ||
| private DeleteQuestionV2UseCase deleteQuestionV2UseCase; | ||
|
|
||
| private final ObjectMapper objectMapper = new ObjectMapper(); | ||
| private MockMvc mockMvc; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| AdminQuestionV2Controller controller = new AdminQuestionV2Controller( | ||
| createQuestionV2UseCase, | ||
| updateQuestionV2UseCase, | ||
| deleteQuestionV2UseCase | ||
| ); | ||
|
|
||
| LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); | ||
| validator.afterPropertiesSet(); | ||
|
|
||
| mockMvc = MockMvcBuilders.standaloneSetup(controller) | ||
| .setControllerAdvice(new GlobalExceptionHandler()) | ||
| .setCustomArgumentResolvers(authenticatedActorResolver()) | ||
| .setValidator(validator) | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("POST /api/v2/admin/questions 는 content가 2000자를 초과하면 400을 반환한다") | ||
| void createQuestion_whenContentExceeds2000Characters_returnsBadRequest() throws Exception { | ||
| mockMvc.perform(post("/api/v2/admin/questions") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(objectMapper.writeValueAsString(Map.of( | ||
| "chapterId", 1L, | ||
| "content", "a".repeat(2001), | ||
| "explanation", "해설", | ||
| "orderIndex", 0, | ||
| "difficulty", 1 | ||
| )))) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(jsonPath("$.success").value(false)) | ||
| .andExpect(jsonPath("$.error.code").value("INVALID_ARGUMENT")) | ||
| .andExpect(jsonPath("$.error.details.content").value("content는 최대 2000자까지 입력할 수 있습니다.")); | ||
|
|
||
| verifyNoInteractions(createQuestionV2UseCase); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("PATCH /api/v2/admin/questions/{questionId} 는 content가 2000자를 초과하면 400을 반환한다") | ||
| void updateQuestion_whenContentExceeds2000Characters_returnsBadRequest() throws Exception { | ||
| mockMvc.perform(patch("/api/v2/admin/questions/{questionId}", 1L) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(objectMapper.writeValueAsString(Map.of( | ||
| "content", "a".repeat(2001), | ||
| "explanation", "해설", | ||
| "orderIndex", 0, | ||
| "difficulty", 1 | ||
| )))) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(jsonPath("$.success").value(false)) | ||
| .andExpect(jsonPath("$.error.code").value("INVALID_ARGUMENT")) | ||
| .andExpect(jsonPath("$.error.details.content").value("content는 최대 2000자까지 입력할 수 있습니다.")); | ||
|
|
||
| verifyNoInteractions(updateQuestionV2UseCase); | ||
| } | ||
|
|
||
| private HandlerMethodArgumentResolver authenticatedActorResolver() { | ||
| return new HandlerMethodArgumentResolver() { | ||
| @Override | ||
| public boolean supportsParameter(MethodParameter parameter) { | ||
| return parameter.hasParameterAnnotation(AuthenticatedActor.class); | ||
| } | ||
|
|
||
| @Override | ||
| public Object resolveArgument( | ||
| MethodParameter parameter, | ||
| ModelAndViewContainer mavContainer, | ||
| org.springframework.web.context.request.NativeWebRequest webRequest, | ||
| WebDataBinderFactory binderFactory | ||
| ) { | ||
| return new Actor(1L); | ||
| } | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
total_exp가 동일한 사용자가 여러 명 있을 경우,ROW_NUMBER()의 결과가 실행할 때마다 달라질 수 있는 비결정적(non-deterministic)인 문제가 있습니다. 이는 마이그레이션 결과와 향후 서비스 로직(RankingTierUpdateService) 간의 순위 불일치를 초래할 수 있으므로,id와 같은 고유 컬럼을 보조 정렬 키로 추가하여 순위를 고정하는 것이 좋습니다.