From b8991ed67fea9508590d8b10cc8cc95ba627c359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=EC=98=81=ED=83=9C?= <56019823+dudxo@users.noreply.github.com> Date: Wed, 1 Jan 2025 19:44:08 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#177]=20=EC=A7=88=EB=AC=B8=20=EA=B8=80?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EC=9D=91=EB=8B=B5=20DTO=20=EC=9E=94?= =?UTF-8?q?=EC=97=AC=20=ED=81=AC=EB=A0=88=EB=94=A7=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat #177] 질문 글 작성 응답 DTO 잔여 크레딧 추가 * [test #177] 질문 글 작성 단위 테스트 잔여 크레딧 검증 * [test #177] 질문 글 작성 통합 테스트 잔여 크레딧 검증 --- .../dnd/gongmuin/question_post/dto/QuestionPostMapper.java | 4 ++-- .../dto/response/RegisterQuestionPostResponse.java | 1 + .../question_post/service/QuestionPostService.java | 3 ++- .../controller/QuestionPostControllerTest.java | 7 +++++-- .../question_post/service/QuestionPostServiceTest.java | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java b/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java index 7d0d9b37..a2234eb1 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java +++ b/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java @@ -57,9 +57,8 @@ public static QuestionPostDetailResponse toQuestionPostDetailResponse( } public static RegisterQuestionPostResponse toRegisterQuestionPostResponse( - QuestionPost questionPost + QuestionPost questionPost, Member member ) { - Member member = questionPost.getMember(); return new RegisterQuestionPostResponse( questionPost.getId(), questionPost.getTitle(), @@ -74,6 +73,7 @@ public static RegisterQuestionPostResponse toRegisterQuestionPostResponse( member.getJobGroup().getLabel(), member.getProfileImageNo() ), + member.getCredit(), questionPost.getCreatedAt().toString() ); } diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java b/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java index e23484e8..f9b9bd96 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java +++ b/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java @@ -13,6 +13,7 @@ public record RegisterQuestionPostResponse( String targetJobGroup, String status, MemberInfo memberInfo, + int remainingCredit, String createdAt ) { } \ No newline at end of file diff --git a/src/main/java/com/dnd/gongmuin/question_post/service/QuestionPostService.java b/src/main/java/com/dnd/gongmuin/question_post/service/QuestionPostService.java index 229243ab..f284c0e0 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/service/QuestionPostService.java +++ b/src/main/java/com/dnd/gongmuin/question_post/service/QuestionPostService.java @@ -66,7 +66,8 @@ public RegisterQuestionPostResponse registerQuestionPost( QuestionPost questionPost = QuestionPostMapper.toQuestionPost(request, member); return QuestionPostMapper.toRegisterQuestionPostResponse( - questionPostRepository.save(questionPost) + questionPostRepository.save(questionPost), + member ); } diff --git a/src/test/java/com/dnd/gongmuin/question_post/controller/QuestionPostControllerTest.java b/src/test/java/com/dnd/gongmuin/question_post/controller/QuestionPostControllerTest.java index 6da8a238..208cfe9b 100644 --- a/src/test/java/com/dnd/gongmuin/question_post/controller/QuestionPostControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/question_post/controller/QuestionPostControllerTest.java @@ -65,11 +65,13 @@ void teardown() { @DisplayName("[질문글을 등록할 수 있다.]") @Test void registerQuestionPost() throws Exception { + final int reward = 2_000; + RegisterQuestionPostRequest request = new RegisterQuestionPostRequest( "제목", "정정기간에 여석이 있을까요?", List.of("image1.jpg", "image2.jpg"), - 2000, + reward, "공업" ); @@ -86,7 +88,8 @@ void registerQuestionPost() throws Exception { .andExpect(jsonPath("$.targetJobGroup").value(request.targetJobGroup())) .andExpect(jsonPath("$.memberInfo.memberId").value(loginMember.getId())) .andExpect(jsonPath("$.memberInfo.nickname").value(loginMember.getNickname())) - .andExpect(jsonPath("$.memberInfo.memberJobGroup").value(loginMember.getJobGroup().getLabel())); + .andExpect(jsonPath("$.memberInfo.memberJobGroup").value(loginMember.getJobGroup().getLabel())) + .andExpect(jsonPath("$.remainingCredit").value(loginMember.getCredit() - reward)); } @DisplayName("[보유 크레딧이 부족하면 질문글을 등록할 수 없다.]") diff --git a/src/test/java/com/dnd/gongmuin/question_post/service/QuestionPostServiceTest.java b/src/test/java/com/dnd/gongmuin/question_post/service/QuestionPostServiceTest.java index 912fd0d0..570bfb33 100644 --- a/src/test/java/com/dnd/gongmuin/question_post/service/QuestionPostServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/question_post/service/QuestionPostServiceTest.java @@ -96,7 +96,8 @@ void registerQuestionPost() { () -> assertThat(response.content()).isEqualTo(request.content()), () -> assertThat(response.reward()).isEqualTo(request.reward()), () -> assertThat(response.targetJobGroup()).isEqualTo(request.targetJobGroup()), - () -> assertThat(response.status()).isEqualTo(QuestionPostStatus.ANSWER_WAITING.getStatus()) + () -> assertThat(response.status()).isEqualTo(QuestionPostStatus.ANSWER_WAITING.getStatus()), + () -> assertThat(response.remainingCredit()).isEqualTo(member.getCredit()) ); }