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

[BE-94] 지원서 합/불 관리페이지 응답 오류 수정 #259

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -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,29 @@
@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) {
public static GetApplicantsStatusResponse of(Map<String, Object> result) {
ApplicantState state;
if (result.get(PASS_STATE_KEY) instanceof ApplicantState applicantState) {
state = applicantState;
} else {
throw ApplicantWrongStateException.wrongStatusException;
}
return GetApplicantsStatusResponse.builder()
.field((String) result.get("field"))
.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())
.state(state)
.build();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 문 안에 return 을 넣고 if 밖에서 throw할 수 있을 것 같은데, else를 사용하는 이유가 궁금합니다!

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"))
                .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())
                .state(applicantState)
                .build();
    }

    throw ApplicantWrongStateException.wrongStatusException;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쌈뽕하네요 다른 이유는 없습니다. 밥먹으라는 어무이 잔소리를 들으면 이렇게 됩니다 ㅋㅋ
리뷰 반영할게요

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 ㅋㅋㅋㅋㅋ 네 좋습니다. 즐거운 추석 보내세용

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 쌈뽕하네요

}
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