diff --git a/.gitignore b/.gitignore index b48c65e5..80969aba 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ out/ !**/src/test/**/out/ src/**/application-prod.yml -src/docs/* +src/docs ### NetBeans ### /nbproject/private/ diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java index b7db87bd..55a0488c 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockController.java @@ -44,8 +44,11 @@ public RspTemplate update(@CurrentUserEmail String email, @PatchMapping("/{blockId}/progress") public RspTemplate 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("") diff --git a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java index c1f79a91..937289d5 100644 --- a/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java +++ b/src/main/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockService.java @@ -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); @@ -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())); } diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/auth/api/AuthControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/auth/api/AuthControllerTest.java index cacafa18..fd6551ab 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/auth/api/AuthControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/auth/api/AuthControllerTest.java @@ -1,25 +1,14 @@ package shop.kkeujeok.kkeujeokbackend.auth.api; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.requestFields; -import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.responseFields; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.RefreshTokenReqDto; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.TokenReqDto; import shop.kkeujeok.kkeujeokbackend.auth.api.dto.response.MemberLoginResDto; @@ -29,6 +18,22 @@ import shop.kkeujeok.kkeujeokbackend.member.domain.Member; import shop.kkeujeok.kkeujeokbackend.member.domain.SocialType; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.requestFields; +import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.responseFields; + public class AuthControllerTest extends ControllerTest { private Member member; diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java index d6fa0da1..1a97c2e9 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/api/BlockControllerTest.java @@ -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()), @@ -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("응답 메시지"), @@ -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()), @@ -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()); diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java index 31c60bdd..a4503fe4 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/block/application/BlockServiceTest.java @@ -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() @@ -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(() -> { @@ -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); } @@ -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("블록을 영구 삭제 합니다.") @@ -311,4 +314,4 @@ void setUp() { verify(blockRepository).deleteAll(deletedBlocks); } -} +} \ No newline at end of file diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java index 395db7ec..5e4f6b7d 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/api/TeamDashboardControllerTest.java @@ -18,13 +18,13 @@ import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.requestFields; +import static shop.kkeujeok.kkeujeokbackend.global.restdocs.RestDocsHandler.responseFields; import java.util.Collections; import java.util.List; diff --git a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/application/TeamDashboardServiceTest.java b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/application/TeamDashboardServiceTest.java index 38473145..17364243 100644 --- a/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/application/TeamDashboardServiceTest.java +++ b/src/test/java/shop/kkeujeok/kkeujeokbackend/dashboard/team/application/TeamDashboardServiceTest.java @@ -307,4 +307,4 @@ void setUp() { }); } -} +} \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 81e27e37..03c30d37 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -1,53 +1,3 @@ spring: profiles: - active: prod - - data: - redis: - host: ${spring.data.redis.host} - port: ${spring.data.redis.port} - - datasource: - url: ${spring.datasource.url} - username: ${spring.datasource.username} - password: ${spring.datasource.password} - driver-class-name: ${spring.datasource.driver-class-name} - - jpa: - hibernate: - ddl-auto: update - properties: - hibernate: - show_sql: true - format_sql: true - open-in-view: false - -logging: - level: - org.hibernate.sql: debug - org.hibernate.type: trace - - discord: - webhook-uri: ${logging.discord.webhook-uri} - config: ${logging.config} - -jwt: - secret: ${jwt.secret} -token: - expire: - time: - access: ${token.expire.time.access} - refresh: ${token.expire.time.refresh} - -google: - client: - id: ${google.client.id} - - secret: ${google.client.secret} - redirect: - uri: ${google.redirect.uri} - -oauth: - kakao: - rest-api-key: ${oauth.kakao.rest-api-key} - redirect-url: ${oauth.kakao.redirect-url} + active: test