Skip to content

Commit

Permalink
feat-be: 평가 테이블에 평가자 이름 필드 추가 및 API 변경 (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 24, 2024
1 parent e2cff5d commit 45273d9
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 38 deletions.
36 changes: 18 additions & 18 deletions backend/src/main/java/com/cruru/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private void runDataLoader() {
LocalDateTime endDate = LocalDateTime.of(2054, 10, 16, 10, 0, 0);
dashboardRepository.save(dashboard);
String description = """
<h2>2025 신입생 (7기) 선발 일정 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>서류접수:</strong> 2024년 10월 6일(금) 오후 3시 ~ 10월 16일(월) 오전 10시</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>프리코스:</strong> 2024년 10월 19일(목) ~ 11월 15일(수)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>1차 합격자 발표:</strong> 2024년 12월 11일(월) 오후 3시, 개별 E-mail 통보</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 코딩 테스트:</strong> 2024년 12월 16일(토)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 합격자 발표:</strong> 2024년 12월 27일(수) 오후 3시, 개별 E-mail 통보 </li></ol><p><br></p><h2>2025 신입생 (7기) 교육 기간 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>2025년 2월 ~ 11월 (약 10개월) </li></ol>
""";
<h2>2025 신입생 (7기) 선발 일정 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>서류접수:</strong> 2024년 10월 6일(금) 오후 3시 ~ 10월 16일(월) 오전 10시</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>프리코스:</strong> 2024년 10월 19일(목) ~ 11월 15일(수)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>1차 합격자 발표:</strong> 2024년 12월 11일(월) 오후 3시, 개별 E-mail 통보</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 코딩 테스트:</strong> 2024년 12월 16일(토)</li><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span><strong>최종 합격자 발표:</strong> 2024년 12월 27일(수) 오후 3시, 개별 E-mail 통보 </li></ol><p><br></p><h2>2025 신입생 (7기) 교육 기간 </h2><p><br></p><ol><li data-list=\"bullet\"><span class=\"ql-ui\" contenteditable=\"false\"></span>2025년 2월 ~ 11월 (약 10개월) </li></ol>
""";
ApplyForm applyForm = new ApplyForm(
"우아한테크코스 2025 백엔드 신입생 모집 ",
description,
Expand Down Expand Up @@ -335,22 +335,22 @@ private void runDataLoader() {
answerRepository.saveAll(answers);

List<Evaluation> evaluations = List.of(
new Evaluation(5, "우수한 실력", firstProcess, lurgi),
new Evaluation(4, "좋은 잠재력", codingTest, lurgi),
new Evaluation(3, "노력 필요", firstProcess, dobby),
new Evaluation(5, "매우 긍정적", codingTest, dobby),
new Evaluation(3, "성장 가능성", firstProcess, arrr),
new Evaluation(4, "기본기 탄탄", codingTest, arrr),
new Evaluation(4, "뛰어난 이해력", firstProcess, chocochip),
new Evaluation(5, "매우 뛰어남", codingTest, chocochip),
new Evaluation(2, "열정적", firstProcess, myungoh),
new Evaluation(1, "개선 필요", codingTest, myungoh),
new Evaluation(5, "빠른 학습 능력", firstProcess, rush),
new Evaluation(1, "-> 불합격", codingTest, rush),
new Evaluation(4, "꼼꼼함", firstProcess, nyangin),
new Evaluation(4, "전과 동일", codingTest, nyangin),
new Evaluation(3, "예술적 감각", firstProcess, redpanda),
new Evaluation(4, "좋은 평가", codingTest, redpanda)
new Evaluation("김도엽", 5, "우수한 실력", firstProcess, lurgi),
new Evaluation("권기호", 4, "좋은 잠재력", codingTest, lurgi),
new Evaluation("최가희", 3, "노력 필요", firstProcess, dobby),
new Evaluation("박정우", 5, "매우 긍정적", codingTest, dobby),
new Evaluation("김형호", 3, "성장 가능성", firstProcess, arrr),
new Evaluation("홍성진", 4, "기본기 탄탄", codingTest, arrr),
new Evaluation("김다은", 4, "뛰어난 이해력", firstProcess, chocochip),
new Evaluation("이태훈", 5, "매우 뛰어남", codingTest, chocochip),
new Evaluation("김도엽", 2, "열정적", firstProcess, myungoh),
new Evaluation("권기호", 1, "개선 필요", codingTest, myungoh),
new Evaluation("최가희", 5, "빠른 학습 능력", firstProcess, rush),
new Evaluation("박정우", 1, "-> 불합격", codingTest, rush),
new Evaluation("김형호", 4, "꼼꼼함", firstProcess, nyangin),
new Evaluation("홍성진", 4, "전과 동일", codingTest, nyangin),
new Evaluation("김다은", 3, "예술적 감각", firstProcess, redpanda),
new Evaluation("이태훈", 4, "좋은 평가", codingTest, redpanda)
);
evaluationRepository.saveAll(evaluations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import jakarta.validation.constraints.Positive;

public record EvaluationCreateRequest(
@NotNull(message = "평가자 이름은 필수 값입니다.")
String evaluator,

@NotNull(message = "평가 점수는 필수 값입니다.")
@Positive(message = "평가 점수는 1 이상 5 이하의 정수입니다.")
Integer score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import jakarta.validation.constraints.Positive;

public record EvaluationUpdateRequest(
@NotNull(message = "평가자 이름은 필수 값입니다.")
String evaluator,

@NotNull(message = "평가 점수는 필수 값입니다.")
@Positive(message = "평가 점수는 1 이상 5 이하의 정수입니다.")
Integer score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public record EvaluationResponse(
long evaluationId,

String evaluator,

int score,

String content,
Expand Down
18 changes: 17 additions & 1 deletion backend/src/main/java/com/cruru/applicant/domain/Evaluation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Evaluation extends BaseEntity implements SecureResource {
@Column(name = "evaluation_id")
private Long id;

private String evaluator;

private Integer score;

private String content;
Expand All @@ -45,8 +47,9 @@ public class Evaluation extends BaseEntity implements SecureResource {
@JoinColumn(name = "applicant_id")
private Applicant applicant;

public Evaluation(int score, String content, Process process, Applicant applicant) {
public Evaluation(String evaluator, int score, String content, Process process, Applicant applicant) {
validateScore(score);
this.evaluator = evaluator;
this.score = score;
this.content = content;
this.process = process;
Expand All @@ -63,6 +66,18 @@ private boolean isOutOfRange(int score) {
return score < MIN_SCORE || score > MAX_SCORE;
}

public boolean isEvaluator(String evaluator) {
return this.evaluator.equals(evaluator);
}

public boolean isContent(String content) {
return this.content.equals(content);
}

public boolean isScore(int score) {
return this.score == score;
}

@Override
public boolean isAuthorizedBy(Member member) {
return process.isAuthorizedBy(member);
Expand All @@ -89,6 +104,7 @@ public int hashCode() {
public String toString() {
return "Evaluation{" +
"id=" + id +
", evaluator='" + evaluator + '\'' +
", score=" + score +
", content='" + content + '\'' +
", process=" + process +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private EvaluationResponses toEvaluationResponses(List<Evaluation> evaluations)
private EvaluationResponse toEvaluationResponse(Evaluation evaluation) {
return new EvaluationResponse(
evaluation.getId(),
evaluation.getEvaluator(),
evaluation.getScore(),
evaluation.getContent(),
evaluation.getCreatedDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public Evaluation findById(Long evaluationId) {

@Transactional
public void create(EvaluationCreateRequest request, Process process, Applicant applicant) {
evaluationRepository.save(new Evaluation(request.score(), request.content(), process, applicant));
evaluationRepository.save(new Evaluation(
request.evaluator(),
request.score(),
request.content(),
process,
applicant
));
}

public List<Evaluation> findAllByProcessAndApplicant(Process process, Applicant applicant) {
Expand All @@ -39,6 +45,7 @@ public void update(EvaluationUpdateRequest request, Evaluation evaluation) {
evaluationRepository.save(
new Evaluation(
evaluation.getId(),
request.evaluator(),
request.score(),
request.content(),
evaluation.getProcess(),
Expand All @@ -49,7 +56,11 @@ public void update(EvaluationUpdateRequest request, Evaluation evaluation) {
}

private boolean changeExists(EvaluationUpdateRequest request, Evaluation evaluation) {
return !(evaluation.getContent().equals(request.content()) && evaluation.getScore().equals(request.score()));
return !(
evaluation.isContent(request.content())
&& evaluation.isScore(request.score())
&& evaluation.isEvaluator(request.evaluator())
);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE evaluation
ADD evaluator VARCHAR(255);
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class EvaluationControllerTest extends ControllerTest {

private static final FieldDescriptor[] EVALUATION_FIELD_DESCRIPTORS = {
fieldWithPath("evaluationId").description("평가의 id"),
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 내용"),
fieldWithPath("createdDate").description("평가 생성 날짜")
Expand Down Expand Up @@ -70,10 +71,11 @@ void setUp() {
@Test
void create() {
// given
String evaluator = "김도엽";
int score = 4;
String content = "서류가 인상적입니다.";
String url = String.format("/v1/evaluations?processId=%d&applicantId=%d", process.getId(), applicant.getId());
EvaluationCreateRequest request = new EvaluationCreateRequest(score, content);
EvaluationCreateRequest request = new EvaluationCreateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -88,6 +90,7 @@ void create() {
parameterWithName("applicantId").description("지원자의 id")
),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand All @@ -100,6 +103,7 @@ void create() {
@Test
void create_applicantNotFound() {
// given
String evaluator = "김도엽";
int score = 4;
String content = "서류가 인상적입니다.";
long invalidApplicantId = -1;
Expand All @@ -108,7 +112,7 @@ void create_applicantNotFound() {
process.getId(),
invalidApplicantId
);
EvaluationCreateRequest request = new EvaluationCreateRequest(score, content);
EvaluationCreateRequest request = new EvaluationCreateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -123,6 +127,7 @@ void create_applicantNotFound() {
parameterWithName("applicantId").description("존재하지 않는 지원자의 id")
),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand All @@ -135,6 +140,7 @@ void create_applicantNotFound() {
@Test
void create_processNotFound() {
// given
String evaluator = "김도엽";
int score = 4;
String content = "서류가 인상적입니다.";
Long invalidProcessId = -1L;
Expand All @@ -143,7 +149,7 @@ void create_processNotFound() {
invalidProcessId,
applicant.getId()
);
EvaluationCreateRequest request = new EvaluationCreateRequest(score, content);
EvaluationCreateRequest request = new EvaluationCreateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -158,6 +164,7 @@ void create_processNotFound() {
parameterWithName("applicantId").description("지원자의 id")
),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand All @@ -170,14 +177,15 @@ void create_processNotFound() {
@Test
void create_invalidScore() {
// given
String evaluator = "김도엽";
int invalidScore = -4;
String content = "서류가 인상적입니다.";
String url = String.format(
"/v1/evaluations?processId=%d&applicantId=%d",
process.getId(),
applicant.getId()
);
EvaluationCreateRequest request = new EvaluationCreateRequest(invalidScore, content);
EvaluationCreateRequest request = new EvaluationCreateRequest(evaluator, invalidScore, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -192,6 +200,7 @@ void create_invalidScore() {
parameterWithName("applicantId").description("지원자의 id")
),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("적절하지 않은 평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand Down Expand Up @@ -284,10 +293,11 @@ void read_processNotFound() {
@Test
void update() {
// given
String evaluator = "김형호";
Evaluation evaluation = evaluationRepository.save(EvaluationFixture.fivePoints(process, applicant));
int score = 2;
String content = "맞춤법이 틀렸습니다.";
EvaluationUpdateRequest request = new EvaluationUpdateRequest(score, content);
EvaluationUpdateRequest request = new EvaluationUpdateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -299,6 +309,7 @@ void update() {
requestCookies(cookieWithName("accessToken").description("사용자 토큰")),
pathParameters(parameterWithName("evaluationId").description("평가의 id")),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand All @@ -311,9 +322,10 @@ void update() {
@Test
void update_evaluationNotFound() {
// given
String evaluator = "김형호";
int score = 2;
String content = "맞춤법이 틀렸습니다.";
EvaluationUpdateRequest request = new EvaluationUpdateRequest(score, content);
EvaluationUpdateRequest request = new EvaluationUpdateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -325,6 +337,7 @@ void update_evaluationNotFound() {
requestCookies(cookieWithName("accessToken").description("사용자 토큰")),
pathParameters(parameterWithName("evaluationId").description("존재하지 않는 평가의 id")),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand All @@ -337,10 +350,11 @@ void update_evaluationNotFound() {
@Test
void update_invalidScore() {
// given
String evaluator = "김형호";
Evaluation evaluation = evaluationRepository.save(EvaluationFixture.fivePoints());
int score = -1;
String content = "맞춤법이 틀렸습니다.";
EvaluationUpdateRequest request = new EvaluationUpdateRequest(score, content);
EvaluationUpdateRequest request = new EvaluationUpdateRequest(evaluator, score, content);

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -352,6 +366,7 @@ void update_invalidScore() {
requestCookies(cookieWithName("accessToken").description("사용자 토큰")),
pathParameters(parameterWithName("evaluationId").description("평가의 id")),
requestFields(
fieldWithPath("evaluator").description("평가자 이름"),
fieldWithPath("score").description("적절하지 않은 평가 점수"),
fieldWithPath("content").description("평가 주관식 내용")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class EvaluationTest {
@ParameterizedTest
void invalidEvaluationScore(int invalidScore) {
// given
String evaluator = "김도엽";
String content = "포트폴리오가 인상적입니다.";

// when&then
assertThatThrownBy(() -> new Evaluation(invalidScore, content, null, null))
assertThatThrownBy(() -> new Evaluation(evaluator, invalidScore, content, null, null))
.isInstanceOf(EvaluationScoreException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void sameIdUpdate() {
Evaluation saved = evaluationRepository.save(evaluation);

//when
Evaluation updatedEvaluation = new Evaluation(evaluation.getId(), 5, "포트폴리오가 인상 깊었습니다.", null, null);
Evaluation updatedEvaluation = new Evaluation(evaluation.getId(), "김도엽", 5, "포트폴리오가 인상 깊었습니다.", null, null);
evaluationRepository.save(updatedEvaluation);

//then
Expand Down
Loading

0 comments on commit 45273d9

Please sign in to comment.