Skip to content

Commit

Permalink
Merge pull request #257 from JNU-econovation/feature/BE-93
Browse files Browse the repository at this point in the history
[BE-93] 지원서 합/불 관리자 페이지 조회
  • Loading branch information
rlajm1203 authored Sep 16, 2024
2 parents 83d4f6a + cf70b47 commit a28430a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.econovation.recruit.api.applicant.controller;

import static com.econovation.recruitcommon.consts.RecruitStatic.APPLICANT_SUCCESS_REGISTER_MESSAGE;
import static com.econovation.recruitcommon.consts.RecruitStatic.PASS_STATE_KEY;

import com.econovation.recruit.api.applicant.command.CreateAnswerCommand;
import com.econovation.recruit.api.applicant.docs.CreateApplicantExceptionDocs;
import com.econovation.recruit.api.applicant.dto.AnswersResponseDto;
import com.econovation.recruit.api.applicant.dto.GetApplicantsStatusResponse;
import com.econovation.recruit.api.applicant.usecase.ApplicantCommandUseCase;
import com.econovation.recruit.api.applicant.usecase.ApplicantQueryUseCase;
import com.econovation.recruit.api.applicant.usecase.TimeTableLoadUseCase;
Expand All @@ -20,11 +18,6 @@
import com.econovation.recruitinfrastructure.apache.CommonsEmailSender;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.axonframework.commandhandling.gateway.CommandGateway;
Expand All @@ -34,6 +27,15 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static com.econovation.recruitcommon.consts.RecruitStatic.APPLICANT_SUCCESS_REGISTER_MESSAGE;
import static com.econovation.recruitcommon.consts.RecruitStatic.PASS_STATE_KEY;

@RestController
@RequestMapping("/api/v1")
@RequiredArgsConstructor
Expand Down Expand Up @@ -156,4 +158,12 @@ public ResponseEntity<Map<String, String>> updateStatus(@PathVariable("applicant
response.put(PASS_STATE_KEY, state);
return new ResponseEntity(response,HttpStatus.OK);
}

@Operation(summary = "지원서의 합/불 상태를 조회합니다. (합/불 관리자 페이지 전용)")
@GetMapping("year/{year}/applicants/pass-state")
public ResponseEntity<List<GetApplicantsStatusResponse>> getApplicantsStatus(@PathVariable("year") Integer year,
@RequestParam("order") String sortType) {
List<GetApplicantsStatusResponse> result = applicantQueryUseCase.getApplicantsStatus(year, sortType);
return new ResponseEntity<>(result, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.econovation.recruit.api.applicant.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.Map;

import static com.econovation.recruitcommon.consts.RecruitStatic.PASS_STATE_KEY;

@Data
@AllArgsConstructor
@Builder
public class GetApplicantsStatusResponse {
private String field1;
private String field2;
private String field3;
private String name;
private String id;
private Integer year;
private String 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.econovation.recruit.api.applicant.aggregate.AnswerAggregate;
import com.econovation.recruit.api.applicant.dto.AnswersResponseDto;
import com.econovation.recruit.api.applicant.dto.GetApplicantsStatusResponse;
import com.econovation.recruit.api.applicant.query.AnswerQuery;
import com.econovation.recruit.api.applicant.usecase.ApplicantQueryUseCase;
import com.econovation.recruit.utils.sort.SortHelper;
Expand Down Expand Up @@ -48,16 +49,7 @@ public Map<String, Object> execute(String answerId) {
public AnswersResponseDto execute(Integer year, Integer page, String sortType) {
PageInfo pageInfo = getPageInfo(year, page);
List<MongoAnswer> result = answerAdaptor.findByYear(year, page);
result.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantStateOrDefault()));

sortHelper.sort(result, sortType);
List<Map<String, Object>> sortedResult = result.stream().map(MongoAnswer::getQna).toList();
// answer id를 각 map에 추가
sortedResult.forEach(
map -> {
map.put("id", result.get(sortedResult.indexOf(map)).getId());
});

List<Map<String, Object>> sortedResult = sortAndAddIds(result, sortType);
if (sortedResult.isEmpty()) {
return AnswersResponseDto.of(Collections.emptyList(), pageInfo);
}
Expand Down Expand Up @@ -181,4 +173,22 @@ public List<Map<String, Object>> execute(List<String> fields, Integer page) {
List<MongoAnswer> byYear = answerAdaptor.findByYear(year, page);
return splitByAnswers(fields, byYear);
}

@Override
public List<GetApplicantsStatusResponse> getApplicantsStatus(Integer year, String sortType) {
List<MongoAnswer> result = answerAdaptor.findByYear(year);
List<Map<String, Object>> sortedResult = sortAndAddIds(result, sortType);
return sortedResult.stream().map(GetApplicantsStatusResponse::of).toList();
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.econovation.recruit.api.applicant.usecase;

import com.econovation.recruit.api.applicant.dto.AnswersResponseDto;
import com.econovation.recruit.api.applicant.dto.GetApplicantsStatusResponse;
import com.econovation.recruitcommon.annotation.UseCase;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer;
import java.util.List;
Expand All @@ -26,4 +27,6 @@ List<Map<String, Object>> execute(
Map<String, Map<String, Object>> findAllApplicantVo(List<String> fields);

AnswersResponseDto search(Integer page, String searchKeyword);

List<GetApplicantsStatusResponse> getApplicantsStatus(Integer year, String sortType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ResponseEntity<Interviewer> findByApplicantId(
@Operation(description = "Interviewer 전체 조회", summary = "면접관 전체 조회")
@ApiErrorExceptionsExample(InterviewerExceptionDocs.class)
@GetMapping("/interviewers")
public ResponseEntity<List<InterviewerResponseDto>> findAll(@ParameterObject String order) {
public ResponseEntity<List<InterviewerResponseDto>> findAll(@ParameterObject String order, @RequestParam(required = false) List<String> roles) {
List<InterviewerResponseDto> interviewers = interviewerUseCase.findAll(order);
return new ResponseEntity(interviewers, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public List<MongoAnswer> findByYear(Integer year, Integer page) {
return mongoTemplate.find(query, MongoAnswer.class);
}

public List<MongoAnswer> findByYear(Integer year) {
Query query =
new Query()
.addCriteria(Criteria.where("year").is(year));
return mongoTemplate.find(query, MongoAnswer.class);
}

public long getTotalCountByYear(Integer year) {
return mongoTemplate.count(Query.query(Criteria.where("year").is(year)), MongoAnswer.class);
}
Expand Down

0 comments on commit a28430a

Please sign in to comment.