Skip to content
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

[fix #171] status enum 타입 String으로 변경 #172

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public AnswerDetailResponse chooseAnswer(

private void chooseAnswer(QuestionPost questionPost, Answer answer) {
questionPost.updateIsChosen(answer);
questionPost.updateStatus(QuestionPostStatus.CHOSEN_COMPLETE);
questionPost.updateStatus(QuestionPostStatus.CHOSEN_COMPLETED);
answer.getMember().increaseCredit(questionPost.getReward());
creditHistoryService.saveChosenCreditHistory(questionPost, answer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.gongmuin.question_post.domain;

import static jakarta.persistence.ConstraintMode.*;
import static jakarta.persistence.EnumType.*;
import static jakarta.persistence.FetchType.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -56,8 +57,9 @@ public class QuestionPost extends TimeBaseEntity {
@Column(name = "is_chosen", nullable = false)
private Boolean isChosen;

@Enumerated(STRING)
@Column(name = "status", nullable = false)
private QuestionPostStatus questionPostStatus;
private QuestionPostStatus status;

@OneToMany(mappedBy = "questionPost", cascade = CascadeType.ALL)
private List<QuestionPostImage> images = new ArrayList<>();
Expand All @@ -71,7 +73,7 @@ public class QuestionPost extends TimeBaseEntity {
private QuestionPost(String title, String content, int reward, JobGroup jobGroup,
List<QuestionPostImage> images, Member member) {
this.isChosen = false;
this.questionPostStatus = QuestionPostStatus.ANSWER_WAITING;
this.status = QuestionPostStatus.ANSWER_WAITING;
this.title = title;
this.content = content;
this.reward = reward;
Expand Down Expand Up @@ -132,14 +134,14 @@ public void updateMember(Member anonymous) {
}

public void updateStatus(QuestionPostStatus status) {
this.questionPostStatus = status;
this.status = status;
}

public boolean isAnswerClosed() {
return QuestionPostStatus.ANSWER_CLOSE.equals(this.questionPostStatus);
return QuestionPostStatus.ANSWER_CLOSED.equals(this.status);
}

public boolean isAnswerWaiting() {
return QuestionPostStatus.ANSWER_WAITING.equals(this.questionPostStatus);
return QuestionPostStatus.ANSWER_WAITING.equals(this.status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public enum QuestionPostStatus {

ANSWER_WAITING("답변대기"),
ANSWER_CLOSE("답변마감"),
ANSWER_CLOSED("답변마감"),
CHOSEN_WAITING("채택대기"),
CHOSEN_COMPLETE("채택완료");
CHOSEN_COMPLETED("채택완료");

private final String status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static QuestionPostDetailResponse toQuestionPostDetailResponse(
imagesToUrls(questionPost.getImages()),
questionPost.getReward(),
questionPost.getJobGroup().getLabel(),
questionPost.getQuestionPostStatus().getStatus(),
questionPost.getStatus().getStatus(),
new MemberInfo(
member.getId(),
member.getNickname(),
Expand All @@ -67,7 +67,7 @@ public static RegisterQuestionPostResponse toRegisterQuestionPostResponse(
imagesToUrls(questionPost.getImages()),
questionPost.getReward(),
questionPost.getJobGroup().getLabel(),
questionPost.getQuestionPostStatus().getStatus(),
questionPost.getStatus().getStatus(),
new MemberInfo(
member.getId(),
member.getNickname(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public List<RefundQuestionPostDto> getRefundQuestionPostDtos() {
.from(questionPost)
.where(
questionPost.createdAt.loe(LocalDateTime.now().minusWeeks(2)),
questionPost.questionPostStatus.eq(QuestionPostStatus.ANSWER_WAITING)
questionPost.status.eq(QuestionPostStatus.ANSWER_WAITING)
)
.fetch();
}
Expand All @@ -123,10 +123,10 @@ public List<RefundQuestionPostDto> getRefundQuestionPostDtos() {
public void updateQuestionPostStatusAnswerClosed() {
queryFactory
.update(questionPost)
.set(questionPost.questionPostStatus, QuestionPostStatus.ANSWER_CLOSE)
.set(questionPost.status, QuestionPostStatus.ANSWER_CLOSED)
.where(
questionPost.createdAt.loe(LocalDateTime.now().minusWeeks(2)),
questionPost.questionPostStatus.eq(QuestionPostStatus.ANSWER_WAITING)
questionPost.status.eq(QuestionPostStatus.ANSWER_WAITING)
)
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ void registerAnswer() {

//then
Assertions.assertThat(response.content()).isEqualTo(request.content());
Assertions.assertThat(questionPost.getQuestionPostStatus()).isEqualTo(QuestionPostStatus.CHOSEN_WAITING);
Assertions.assertThat(questionPost.getStatus()).isEqualTo(QuestionPostStatus.CHOSEN_WAITING);
}

@DisplayName("[답변대기 상태가 아닌 질문글에 답변을 등록할 때 질문글 상태가 변하지 않는다.]")
@Test
void notChangeQuestionPostStatusWhenRegisterAnswerAndQuestionPostStatusIsNotAnswerWaiting() {
//given
QuestionPost questionPost = QuestionPostFixture.questionPost(1L);
ReflectionTestUtils.setField(questionPost, "questionPostStatus", QuestionPostStatus.CHOSEN_COMPLETE);
ReflectionTestUtils.setField(questionPost, "status", QuestionPostStatus.CHOSEN_COMPLETED);
Answer answer = AnswerFixture.answer(1L, questionPost.getId());
RegisterAnswerRequest request =
new RegisterAnswerRequest("답변 내용");
Expand All @@ -113,15 +113,15 @@ void notChangeQuestionPostStatusWhenRegisterAnswerAndQuestionPostStatusIsNotAnsw

//then
Assertions.assertThat(response.content()).isEqualTo(request.content());
Assertions.assertThat(questionPost.getQuestionPostStatus()).isEqualTo(QuestionPostStatus.CHOSEN_COMPLETE);
Assertions.assertThat(questionPost.getStatus()).isEqualTo(QuestionPostStatus.CHOSEN_COMPLETED);
}

@DisplayName("[답변마감 상태인 질문글에 답변을 등록할 때 예외가 발생한다.]")
@Test
void throwExceptionWhenQuestionPostStatusIsAnswerClose() {
//given
QuestionPost questionPost = QuestionPostFixture.questionPost(1L);
ReflectionTestUtils.setField(questionPost, "questionPostStatus", QuestionPostStatus.ANSWER_CLOSE);
ReflectionTestUtils.setField(questionPost, "status", QuestionPostStatus.ANSWER_CLOSED);
RegisterAnswerRequest request = new RegisterAnswerRequest("답변 내용");

given(questionPostRepository.findById(questionPost.getId())).willReturn(Optional.of(questionPost));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ void getAutoChangeStatus() {
QuestionPost findQuestionPost2 = questionPostRepository.findById(questionPost2.getId()).orElseThrow();
QuestionPost findQuestionPost3 = questionPostRepository.findById(questionPost3.getId()).orElseThrow();
assertAll(
() -> assertThat(findQuestionPost1.getQuestionPostStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSE),
() -> assertThat(findQuestionPost2.getQuestionPostStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSE),
() -> assertThat(findQuestionPost3.getQuestionPostStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSE)
() -> assertThat(findQuestionPost1.getStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSED),
() -> assertThat(findQuestionPost2.getStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSED),
() -> assertThat(findQuestionPost3.getStatus()).isEqualTo(QuestionPostStatus.ANSWER_CLOSED)
);

}
Expand Down
Loading