Skip to content

Commit

Permalink
Merge pull request #109 from JNU-econovation/feature/BE-41
Browse files Browse the repository at this point in the history
[BE-41] 페이지 네이션 maxPage 제공
  • Loading branch information
BlackBean99 authored Sep 2, 2023
2 parents 0d38190 + 4d4a013 commit 8837cbe
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 16 deletions.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified server/.gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import com.econovation.recruitcommon.annotation.XssProtected;
import com.econovation.recruitdomain.domains.applicant.dto.BlockRequestDto;
import com.econovation.recruitdomain.domains.applicant.dto.TimeTableVo;
import com.econovation.recruitdomain.domains.dto.ApplicantPaginationResponseDto;
import com.econovation.recruitdomain.domains.dto.QuestionRequestDto;
import com.econovation.recruitdomain.domains.timetable.domain.TimeTable;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -45,7 +47,8 @@ public class ApplicantController {
@ApiErrorExceptionsExample(CreateApplicantExceptionDocs.class)
@XssProtected
@PostMapping("/applicants")
public ResponseEntity registerApplicant(@RequestBody List<BlockRequestDto> blockElements) {
public ResponseEntity registerApplicant(
@RequestBody @Valid List<BlockRequestDto> blockElements) {
UUID applicantId = applicantRegisterUseCase.execute(blockElements);
return new ResponseEntity<>(applicantId, HttpStatus.OK);
}
Expand All @@ -65,9 +68,8 @@ public ResponseEntity<List<Map<String, String>>> getApplicants() {

@Operation(summary = "모든 지원자의 지원서를 페이지 단위로(1페이지당 8개) 조회합니다.")
@GetMapping("/page/{page}/applicants")
public ResponseEntity<List<Map<String, String>>> getApplicantsByPage(
public ResponseEntity<ApplicantPaginationResponseDto> getApplicantsByPage(
// TODO 정렬 기준 추가
// @PathVariable(value = "page") Integer page, String sortType) {
@PathVariable(value = "page") Integer page) {
return new ResponseEntity<>(answerLoadUseCase.execute(page), HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.econovation.recruitcommon.exception.OutOfIndexException;
import com.econovation.recruitdomain.domains.applicant.adaptor.AnswerAdaptor;
import com.econovation.recruitdomain.domains.applicant.domain.Answer;
import com.econovation.recruitdomain.domains.dto.ApplicantPaginationResponseDto;
import com.econovation.recruitdomain.domains.score.adaptor.ScoreAdaptor;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -128,11 +129,16 @@ public List<Map<String, String>> execute() {
}

@Override
public List<Map<String, String>> execute(Integer page) {
public ApplicantPaginationResponseDto execute(Integer page) {
if (page < 1) throw OutOfIndexException.EXCEPTION;
List<Answer> answers = answerAdaptor.findAll(page);
List<Map<String, String>> results = splitByAnswersInApplicantId(answers);
return results;
// maxPage
Integer maxPage = results.size() / 8;
return ApplicantPaginationResponseDto.builder()
.applicants(results)
.maxPage(maxPage + 1)
.build();

// if (sortType.equals("score")) {
// Map -> id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ public void execute(String type, String name, Integer parentId) {

@Override
public void execute(List<QuestionRequestDto> questions) {
questionAdaptor.saveAll(
// DB 내에 있는 질문은 기존에 있는 것은 생략하고 저장한다
List<Question> questionList = questionAdaptor.findAll();
List<Question> filteredQuestions =
questions.stream()
.filter(
question ->
questionList.stream()
.noneMatch(
q ->
q.getName()
.equals(
question.getName())))
.map(
question ->
Question.builder()
.questionType(question.getType())
.name(question.getName())
.parentId(question.getParentId())
.build())
.collect(Collectors.toList()));
.collect(Collectors.toList());
questionAdaptor.saveAll(filteredQuestions);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.econovation.recruit.api.applicant.usecase;

import com.econovation.recruitcommon.annotation.UseCase;
import com.econovation.recruitdomain.domains.dto.ApplicantPaginationResponseDto;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -13,7 +14,7 @@ public interface AnswerLoadUseCase {

List<Map<String, String>> execute();

List<Map<String, String>> execute(Integer page);
ApplicantPaginationResponseDto execute(Integer page);
// List<Map<String, String>> execute(Integer page, String sortType);

Map<String, String> execute(String applicantId, List<String> fields);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.econovation.recruit.api.config.security;

import static com.econovation.recruitcommon.consts.RecruitStatic.RolePattern;
import static com.econovation.recruitcommon.consts.RecruitStatic.SwaggerPatterns;

import com.econovation.recruitcommon.helper.SpringEnvironmentHelper;
Expand All @@ -22,7 +23,6 @@
@RequiredArgsConstructor
@EnableWebSecurity
public class SecurityConfig {

private final FilterConfig filterConfig;

@Value("${swagger.user}")
Expand Down Expand Up @@ -78,6 +78,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// .mvcMatchers(HttpMethod.GET,
// "/v1/events/{eventId:[0-9]*$}/comments/**")
// .permitAll()
.mvcMatchers(HttpMethod.GET, "/api/v1/token")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/api/v1/questions")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/api/v1/applicants")
Expand All @@ -94,7 +96,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// ( jwt 필터나 , basic auth 필터의 순서는 상관이없다.) --> 왜냐면 jwt는 토큰 여부 파악만하고 있으면 검증이고 없으면 넘김.
// 내부 소스까지 실행을 못함. 권한 문제 때문에.
.anyRequest()
.hasRole("USER");
.hasAnyRole(RolePattern);
http.apply(filterConfig);

return http.build();
Expand All @@ -103,7 +105,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@Bean
public RoleHierarchyImpl roleHierarchy() {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy("ROLE_SUPER_ADMIN > ROLE_ADMIN > ROLE_MANAGER > ROLE_USER");
roleHierarchy.setHierarchy("ROLE_PRESIDENT > ROLE_OPERATION > ROLE_TF");
return roleHierarchy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
public class ApplicantRegisterEventHandler {
private final SlackMessageProvider slackMessageProvider;
private final SlackProperties slackProperties;

private final CardAdaptor cardAdaptor;
private final BoardRegisterUseCase boardRegisterUseCase;

Expand All @@ -40,7 +39,7 @@ public void handle(ApplicantRegisterEvent applicantRegistEvent) {
applicantRegistEvent.getApplicantId(),
applicantRegistEvent.getHopeField(),
card.getId());
slackMessageProvider.sendMessage(slackProperties.getUrl(), message);
// slackMessageProvider.sendMessage(slackProperties.getUrl(), message);
}

private String generateApplicantRegisterMessage(ApplicantRegisterEvent applicantRegistEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.econovation.recruitdomain.domains.dto.LoginRequestDto;
import com.econovation.recruitdomain.domains.dto.SignUpRequestDto;
import com.econovation.recruitdomain.domains.interviewer.domain.Interviewer;
import com.econovation.recruitdomain.domains.interviewer.exception.InterviewerAlreadySubmitException;
import com.econovation.recruitdomain.domains.interviewer.exception.InterviewerNotMatchException;
import com.econovation.recruitdomain.out.InterviewerLoadPort;
import com.econovation.recruitdomain.out.InterviewerRecordPort;
Expand Down Expand Up @@ -40,8 +41,8 @@ private void checkPassword(String password, String encodePassword) {
@Override
@Transactional
public void signUp(SignUpRequestDto signUpRequestDto) {
if (interviewerLoadPort.loadInterviewerByEmail(signUpRequestDto.getEmail()) != null)
throw InterviewerNotMatchException.EXCEPTION;
if (interviewerLoadPort.loadOptionalInterviewerByEmail(signUpRequestDto.getEmail()) == null)
throw InterviewerAlreadySubmitException.EXCEPTION;
String encededPassword = passwordEncoder.encode(signUpRequestDto.getPassword());
Interviewer interviewer =
Interviewer.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public class RecruitStatic {
public static final String[] SwaggerPatterns = {
"/swagger-resources/**",
"/swagger-ui/**",
"/swagger-ui.html",
"/v3/api-docs/**",
"/v3/api-docs",
"/api-docs/**",
"/api-docs"
};
public static final String[] RolePattern = {
"ROLE_TF", "ROLE_PRESIDENT", "ROLE_OPERATION",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.hibernate.validator.constraints.Length;

@Getter
@RequiredArgsConstructor
public class BlockRequestDto {
// private String type;
private String name;
// 한글 기준으로 1000자 이하
@Length(max = 1000)
private String answer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.econovation.recruitdomain.domains.dto;

import java.util.List;
import java.util.Map;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ApplicantPaginationResponseDto {
List<Map<String, String>> applicants;
Integer maxPage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.econovation.recruitdomain.out.InterviewerLoadPort;
import com.econovation.recruitdomain.out.InterviewerRecordPort;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;

@Adaptor
Expand Down Expand Up @@ -40,6 +41,11 @@ public Interviewer loadInterviewerByEmail(String email) {
.orElseThrow(() -> InterviewerNotFoundException.EXCEPTION);
}

@Override
public Optional<Interviewer> loadOptionalInterviewerByEmail(String email) {
return interviewerRepository.findByEmail(email);
}

public List<Interviewer> saveAll(List<Interviewer> interviewer) {
return interviewerRepository.saveAll(interviewer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.econovation.recruitdomain.domains.interviewer.exception;

import com.econovation.recruitcommon.exception.RecruitCodeException;

public class InterviewerAlreadySubmitException extends RecruitCodeException {
public static final InterviewerAlreadySubmitException EXCEPTION =
new InterviewerAlreadySubmitException();

private InterviewerAlreadySubmitException() {
super(InterviewerErrorCode.INTERVIEWER_ALREADY_SUBMIT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum InterviewerErrorCode implements BaseErrorCode {
INTERVIEWER_INVALID_ROLE(BAD_REQUEST, "INTERVIEWER_400_4", "유효하지 않은 Role 을 입력했습니다."),
INVALID_PASSWORD(BAD_REQUEST, "INTERVIEWER_400_5", "유효하지 않은 비밀번호입니다."),
INTERVIEWER_NOT_MATCH(NOT_FOUND, "INTERVIEWER_400_6", "등록되지 않은 이메일과 비밀번호로 로그인을 시도했습니다."),
INTERVIEWER_ALREADY_SUBMIT(BAD_REQUEST, "INTERVIEWER_400_7", "이미 가입한 면접자입니다."),
;
private Integer status;
private String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.econovation.recruitdomain.domains.interviewer.domain.Interviewer;
import java.util.List;
import java.util.Optional;

public interface InterviewerLoadPort {
Interviewer loadInterviewById(Long idpId);
Expand All @@ -11,4 +12,6 @@ public interface InterviewerLoadPort {
List<Interviewer> findAll();

Interviewer loadInterviewerByEmail(String email);

Optional<Interviewer> loadOptionalInterviewerByEmail(String email);
}

0 comments on commit 8837cbe

Please sign in to comment.