Skip to content

Commit

Permalink
Refactor: 블록 상태 변경 로직 수정 (#244)
Browse files Browse the repository at this point in the history
상태 변경시에 순서도 함께 변경합니다.
  • Loading branch information
giwoong01 authored Dec 19, 2024
1 parent c661864 commit 66d44fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public RspTemplate<BlockInfoResDto> update(@CurrentUserEmail String email,
@PatchMapping("/{blockId}/progress")
public RspTemplate<BlockInfoResDto> progressUpdate(@CurrentUserEmail String email,
@PathVariable(name = "blockId") Long blockId,
@RequestParam(name = "progress") String progress) {
return new RspTemplate<>(HttpStatus.OK, "블록 상태 수정", blockService.progressUpdate(email, blockId, progress));
@RequestParam(name = "progress") String progress,
@RequestBody BlockSequenceUpdateReqDto blockSequenceUpdateReqDto) {
return new RspTemplate<>(HttpStatus.OK,
"블록 상태 수정",
blockService.progressUpdate(email, blockId, progress, blockSequenceUpdateReqDto));
}

@GetMapping("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ public BlockInfoResDto update(String email, Long blockId, BlockUpdateReqDto bloc

// 블록 상태 업데이트 (Progress)
@Transactional
public BlockInfoResDto progressUpdate(String email, Long blockId, String progressString) {
public BlockInfoResDto progressUpdate(String email, Long blockId, String progressString,
BlockSequenceUpdateReqDto blockSequenceUpdateReqDto) {
Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
Block block = blockRepository.findById(blockId).orElseThrow(BlockNotFoundException::new);

Progress progress = parseProgress(progressString);

Dashboard dashboard = dashboardRepository.findById(block.getDashboard().getId())
Dashboard dashboard = dashboardRepository.findById(blockSequenceUpdateReqDto.dashboardId())
.orElseThrow(DashboardNotFoundException::new);

validateDashboardAccess(dashboard, member);
Expand All @@ -117,6 +118,12 @@ public BlockInfoResDto progressUpdate(String email, Long blockId, String progres

updateChallengeCompletedMemberByProgress(block, member, progress);

updateBlockSequence(member, blockSequenceUpdateReqDto.notStartedList(), dashboard.getId(),
Progress.NOT_STARTED);
updateBlockSequence(member, blockSequenceUpdateReqDto.inProgressList(), dashboard.getId(),
Progress.IN_PROGRESS);
updateBlockSequence(member, blockSequenceUpdateReqDto.completedList(), dashboard.getId(), Progress.COMPLETED);

return BlockInfoResDto.from(block, DDayCalculator.calculate(block.getDeadLine()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
String progressString = "IN_PROGRESS";
BlockInfoResDto response = BlockInfoResDto.from(block, DDayCalculator.calculate(block.getDeadLine()));

given(blockService.progressUpdate(anyString(), anyLong(), anyString())).willReturn(response);
given(blockService.progressUpdate(anyString(), anyLong(), anyString(), any())).willReturn(response);

// when & then
mockMvc.perform(patch(String.format("/api/blocks/{blockId}/progress?progress=%s", progressString), blockId)
.header("Authorization", "Bearer valid-token")
.accept(MediaType.APPLICATION_JSON))
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(blockSequenceUpdateReqDto)))
.andDo(print())
.andDo(document("block/progress/update",
preprocessRequest(prettyPrint()),
Expand All @@ -236,6 +237,12 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
parameterWithName("progress")
.description("블록 상태 문자열(NOT_STARTED, IN_PROGRESS, COMPLETED)")
),
requestFields(
fieldWithPath("dashboardId").description("대시보드 ID"),
fieldWithPath("notStartedList").description("시작 전 블록 아이디 리스트"),
fieldWithPath("inProgressList").description("진행 중 블록 아이디 리스트"),
fieldWithPath("completedList").description("완료 블록 아이디 리스트")
),
responseFields(
fieldWithPath("statusCode").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
Expand Down Expand Up @@ -263,13 +270,14 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
Long blockId = 1L;
String progressString = "STATUS_PROGRESS";

given(blockService.progressUpdate(anyString(), anyLong(), anyString())).willThrow(
given(blockService.progressUpdate(anyString(), anyLong(), anyString(), any())).willThrow(
new InvalidProgressException());

// when & then
mockMvc.perform(patch(String.format("/api/blocks/{blockId}/progress?progress=%s", progressString), blockId)
.header("Authorization", "Bearer valid-token")
.accept(MediaType.APPLICATION_JSON))
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(blockSequenceUpdateReqDto)))
.andDo(print())
.andDo(document("block/progress/update/failure",
preprocessRequest(prettyPrint()),
Expand All @@ -280,6 +288,12 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
queryParameters(
parameterWithName("progress")
.description("블록 상태 문자열(NOT_STARTED, IN_PROGRESS, COMPLETED)")
),
requestFields(
fieldWithPath("dashboardId").description("대시보드 ID"),
fieldWithPath("notStartedList").description("시작 전 블록 아이디 리스트"),
fieldWithPath("inProgressList").description("진행 중 블록 아이디 리스트"),
fieldWithPath("completedList").description("완료 블록 아이디 리스트")
)
))
.andExpect(status().isBadRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void setUp() {

blockSequenceUpdateReqDto = new BlockSequenceUpdateReqDto(
dashboard.getId(),
List.of(1L, 2L),
List.of(3L, 4L),
List.of(5L, 6L)
List.of(1L),
List.of(),
List.of()
);

block = Block.builder()
Expand Down Expand Up @@ -190,7 +190,10 @@ void setUp() {
when(dashboardRepository.findById(block.getDashboard().getId())).thenReturn(Optional.of(dashboard));

// when
BlockInfoResDto result = blockService.progressUpdate("email", blockId, "IN_PROGRESS");
BlockInfoResDto result = blockService.progressUpdate("email",
blockId,
"IN_PROGRESS",
blockSequenceUpdateReqDto);

// then
assertAll(() -> {
Expand All @@ -208,7 +211,7 @@ void setUp() {
when(blockRepository.findById(blockId)).thenReturn(Optional.of(block));

// when & then
assertThatThrownBy(() -> blockService.progressUpdate("email", blockId, "String"))
assertThatThrownBy(() -> blockService.progressUpdate("email", blockId, "String", blockSequenceUpdateReqDto))
.isInstanceOf(InvalidProgressException.class);
}

Expand Down Expand Up @@ -277,7 +280,7 @@ void setUp() {
blockService.changeBlocksSequence("email", blockSequenceUpdateReqDto);

// then
verify(blockRepository, times(6)).findById(anyLong()); // 6번 블록 조회가 이루어졌는지 검증
verify(blockRepository, times(1)).findById(anyLong()); // 6번 블록 조회가 이루어졌는지 검증
}

@DisplayName("블록을 영구 삭제 합니다.")
Expand Down

0 comments on commit 66d44fa

Please sign in to comment.