Skip to content

Commit

Permalink
Merge pull request #259 from JNU-econovation/fix/BE-94
Browse files Browse the repository at this point in the history
[BE-94] 지원서 합/불 관리페이지 응답 오류 수정
  • Loading branch information
LJH098 authored Sep 16, 2024
2 parents a28430a + 54f4b92 commit 8e24db1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.econovation.recruit.api.applicant.dto;

import com.econovation.recruitdomain.domains.applicant.domain.state.ApplicantState;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantWrongStateException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -12,23 +14,26 @@
@AllArgsConstructor
@Builder
public class GetApplicantsStatusResponse {
private String field;
private String field1;
private String field2;
private String field3;
private String name;
private String id;
private Integer year;
private String state;
private ApplicantState state;

public static GetApplicantsStatusResponse of(Map<String,Object> result) {
return GetApplicantsStatusResponse.builder()
.field1((String) result.get("field1"))
.field2((String) result.get("field2"))
.field3((String) result.get("field3"))
.name((String) result.get("name"))
.id((String) result.get("id"))
.year((Integer) result.get("year"))
.state(result.get(PASS_STATE_KEY).toString())
.build();
public static GetApplicantsStatusResponse of(Map<String, Object> result) {
if (result.get(PASS_STATE_KEY) instanceof ApplicantState applicantState) {
return GetApplicantsStatusResponse.builder()
.field((String) result.get("field"))
.field1((String) result.get("field1"))
.field2((String) result.get("field2"))
.name((String) result.get("name"))
.id((String) result.get("id"))
.year((Integer) result.get("year"))
.state(applicantState)
.build();
}
throw ApplicantWrongStateException.wrongStatusException;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class ApplicantStateUpdateEventHandler {
public String handle(ApplicantStateModifyEvent event){
MongoAnswer answer = answerAdaptor.findById(event.getApplicantId()).get();
ApplicantStateEvents command = event.getEvent();
boolean result = answer.stateEmptyCheckAndInit();
log.error(String.format("validate : %s", (result ? "새로운 state 초기화" : "state 초기화 하지 않고 변경")));
answer.stateEmptyCheckAndInit();
switch (command) {
case PASS:
answer.pass(periodCalculator.execute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public List<GetApplicantsStatusResponse> getApplicantsStatus(Integer year, Strin

private List<Map<String, Object>> sortAndAddIds(List<MongoAnswer> result, String sortType) {
sortHelper.sort(result, sortType);
List<Map<String, Object>> sortedResult = result.stream().map(MongoAnswer::getQna).toList();
sortedResult.forEach(
map -> {
map.put("id", result.get(sortedResult.indexOf(map)).getId());
map.put(PASS_STATE_KEY, result.get(sortedResult.indexOf(map)).getApplicantStateOrDefault());
});
return sortedResult;
return result.stream().map(
answer -> {
Map<String, Object> qna = answer.getQna();
qna.put("id", answer.getId());
qna.put(PASS_STATE_KEY, answer.getApplicantStateOrDefault());
return qna;
}).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswerRepository;
import java.util.List;

import com.econovation.recruitdomain.domains.applicant.exception.ApplicantNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -48,7 +50,11 @@ public List<MongoAnswer> findByYear(Integer year) {
Query query =
new Query()
.addCriteria(Criteria.where("year").is(year));
return mongoTemplate.find(query, MongoAnswer.class);
List<MongoAnswer> result = mongoTemplate.find(query, MongoAnswer.class);
if(result.isEmpty()) {
throw ApplicantNotFoundException.EXCEPTION;
}
return result;
}

public long getTotalCountByYear(Integer year) {
Expand Down

0 comments on commit 8e24db1

Please sign in to comment.