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()) ); }