Skip to content

Commit

Permalink
[BE] Release-HotFix: Cruru v1.1.1 (#768)
Browse files Browse the repository at this point in the history
82a5d2d (HEAD -> be/main, origin/be/main) fix-be: OSIV 오류 해결 (#746)
7434b61 feat-be: 프로세스 목록 조회 API  필터링 및 정렬 구현 (#756)
2e05f2b feat-be: 다중 불합격자 해제 기능 구현 (#759)
4c60d92 feat-be: 대시보드 삭제 api 구현 (#749)
fbbfee5 fix-be: 예외 처리 과정에서 NPE가 발생하지 않도록 수정  (#753)
a55783d feat-be: 다중 불합격자 기능 구현 (#751)
071cebc chore-be(Actions-Prod): 무중단 배포 설정 수정
  • Loading branch information
Dobby-Kim authored Oct 5, 2024
1 parent 3172675 commit 6f6c7e3
Show file tree
Hide file tree
Showing 62 changed files with 1,451 additions and 40 deletions.
28 changes: 28 additions & 0 deletions backend/src/docs/asciidoc/applicant.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,31 @@ operation::applicant/change-info[snippets="http-request,path-parameters,request-
==== 실패: 존재하지 않는 지원자

operation::applicant/change-info-fail/applicant-not-found[snippets="http-request,path-parameters,request-cookies,http-response"]

=== 지원자 일괄 불합격

==== 성공

operation::applicant/reject-all/[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 존재하지 않는 지원자

operation::applicant/reject-all-fail/applicant-not-found[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 이미 불합격한 지원자

operation::applicant/reject-all-fail/already-rejected[snippets="http-request,request-cookies,request-fields,http-response"]

=== 지원자 일괄 불합격 해제

==== 성공

operation::applicant/unreject-all/[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 존재하지 않는 지원자

operation::applicant/unreject-all-fail/applicant-not-found[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 불합격 하지 않은 지원자

operation::applicant/unreject-all-fail/already-unrejected[snippets="http-request,request-cookies,request-fields,http-response"]
10 changes: 10 additions & 0 deletions backend/src/docs/asciidoc/dashboard.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ operation::dashboard/create-fail/club-not-found[snippets="http-request,request-c
==== 성공

operation::dashboard/read[snippets="http-request,request-cookies,query-parameters,http-response,response-fields"]

=== 대시보드 삭제

==== 성공

operation::dashboard/delete[snippets="http-request,request-cookies,path-parameters,http-response"]

==== 실패: 존재하지 않는 대시보드

operation::dashboard/delete/not-found[snippets="http-request,request-cookies,path-parameters,http-response"]
2 changes: 1 addition & 1 deletion backend/src/docs/asciidoc/process.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

==== 성공

operation::process/read[snippets="http-request,request-cookies,query-parameters,http-response,response-fields"]
operation::process/read-filter-and-order[snippets="http-request,request-cookies,query-parameters,http-response,response-fields"]

==== 실패: 존재하지 않는 대시보드

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cruru.applicant.controller.request.ApplicantMoveRequest;
import com.cruru.applicant.controller.request.ApplicantUpdateRequest;
import com.cruru.applicant.controller.request.ApplicantsRejectRequest;
import com.cruru.applicant.controller.response.ApplicantAnswerResponses;
import com.cruru.applicant.controller.response.ApplicantBasicResponse;
import com.cruru.applicant.domain.Applicant;
Expand Down Expand Up @@ -79,4 +80,18 @@ public ResponseEntity<Void> unreject(@PathVariable Long applicantId, LoginProfil
applicantFacade.unreject(applicantId);
return ResponseEntity.ok().build();
}

@PatchMapping("/reject")
public ResponseEntity<Void> reject(@RequestBody @Valid ApplicantsRejectRequest request, LoginProfile loginProfile) {
applicantFacade.reject(request);
return ResponseEntity.ok().build();
}

@PatchMapping("/unreject")
public ResponseEntity<Void> unreject(
@RequestBody @Valid ApplicantsRejectRequest request, LoginProfile loginProfile
) {
applicantFacade.unreject(request);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.cruru.applicant.controller.request.EvaluationCreateRequest;
import com.cruru.applicant.controller.request.EvaluationUpdateRequest;
import com.cruru.applicant.controller.response.EvaluationResponses;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.Evaluation;
import com.cruru.applicant.facade.EvaluationFacade;
import com.cruru.auth.annotation.RequireAuthCheck;
import com.cruru.global.LoginProfile;
import com.cruru.process.domain.Process;
import jakarta.validation.Valid;
import java.net.URI;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,7 +28,7 @@ public class EvaluationController {

private final EvaluationFacade evaluationFacade;

@RequireAuthCheck(targetId = "applicantId", targetDomain = Applicant.class)
@RequireAuthCheck(targetId = "processId", targetDomain = Process.class)
@PostMapping
public ResponseEntity<Void> create(
@RequestBody @Valid EvaluationCreateRequest request,
Expand All @@ -41,7 +41,7 @@ public ResponseEntity<Void> create(
return ResponseEntity.created(URI.create(url)).build();
}

@RequireAuthCheck(targetId = "applicantId", targetDomain = Applicant.class)
@RequireAuthCheck(targetId = "processId", targetDomain = Process.class)
@GetMapping
public ResponseEntity<EvaluationResponses> read(
@RequestParam(name = "processId") Long processId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cruru.applicant.controller.request;

import jakarta.validation.constraints.NotNull;
import java.util.List;

public record ApplicantsRejectRequest(
@NotNull(message = "지원자 목록은 필수 값입니다.")
List<Long> applicantIds
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cruru.applicant.domain;

import com.cruru.applicant.domain.dto.ApplicantCard;
import com.cruru.applicant.exception.badrequest.ApplicantSortException;
import java.util.Arrays;
import java.util.Comparator;

public enum ApplicantSortOption {

ASC(Comparator.naturalOrder()),
DESC(Comparator.reverseOrder());

private final Comparator<Comparable> comparator;

ApplicantSortOption(Comparator<Comparable> comparator) {
this.comparator = comparator;
}

public static Comparator<ApplicantCard> getCombinedComparator(String sortByCreatedAt, String sortByScore) {
ApplicantSortOption createdAtOption = convertToSortOption(sortByCreatedAt);
ApplicantSortOption scoreOption = convertToSortOption(sortByScore);

return createdAtOption.getCreatedAtComparator()
.thenComparing(scoreOption.getScoreComparator());
}

private static ApplicantSortOption convertToSortOption(String sortOption) {
return Arrays.stream(ApplicantSortOption.values())
.filter(option -> option.name().equalsIgnoreCase(sortOption))
.findAny()
.orElseThrow(ApplicantSortException::new);
}

private Comparator<ApplicantCard> getCreatedAtComparator() {
return Comparator.comparing(ApplicantCard::createdAt, comparator);
}

private Comparator<ApplicantCard> getScoreComparator() {
return Comparator.comparing(ApplicantCard::averageScore, comparator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private boolean isOutOfRange(int score) {

@Override
public boolean isAuthorizedBy(Member member) {
return applicant.isAuthorizedBy(member);
return process.isAuthorizedBy(member);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cruru.applicant.domain;

import com.cruru.applicant.domain.dto.ApplicantCard;
import com.cruru.applicant.exception.badrequest.EvaluationStatusException;
import java.util.Arrays;
import java.util.function.Predicate;

public enum EvaluationStatus {

ALL(card -> true),
NOT_EVALUATED(ApplicantCard::hasEvaluation),
EVALUATED(ApplicantCard::hasNoEvaluation);

private final Predicate<ApplicantCard> predicate;

EvaluationStatus(Predicate<ApplicantCard> predicate) {
this.predicate = predicate;
}

public static boolean matches(ApplicantCard card, String evaluationStatus) {
return Arrays.stream(EvaluationStatus.values())
.filter(status -> status.name().equalsIgnoreCase(evaluationStatus))
.findAny()
.orElseThrow(EvaluationStatusException::new)
.predicate
.test(card);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public record ApplicantCard(
public ApplicantCardResponse toResponse() {
return new ApplicantCardResponse(id, name, createdAt, isRejected, (int) evaluationCount, averageScore);
}

public boolean hasEvaluation() {
return evaluationCount == 0;
}

public boolean hasNoEvaluation() {
return evaluationCount > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.process.domain.Process;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface ApplicantRepository extends JpaRepository<Applicant, Long> {

List<Applicant> findAllByProcess(Process process);

@EntityGraph(attributePaths = {"process.dashboard.club.member"})
@Query("SELECT a FROM Applicant a WHERE a.id = :id")
Optional<Applicant> findByIdFetchingMember(long id);

long countByProcess(Process process);

@Query("""
Expand All @@ -39,4 +47,13 @@ a.id, a.name, a.createdDate, a.isRejected, COUNT(e), COALESCE(AVG(e.score), 0.00

@Query("SELECT a FROM Applicant a JOIN FETCH a.process p JOIN FETCH p.dashboard d WHERE d = :dashboard")
List<Applicant> findAllByDashboard(@Param("dashboard") Dashboard dashboard);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("""
UPDATE Applicant a
SET a.isRejected = :isRejected
WHERE a.id in :applicantIds
""")
@Transactional
void updateRejectedStatusForApplicants(List<Long> applicantIds, boolean isRejected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
import com.cruru.applicant.domain.Evaluation;
import com.cruru.process.domain.Process;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface EvaluationRepository extends JpaRepository<Evaluation, Long> {

List<Evaluation> findAllByProcessAndApplicant(Process process, Applicant applicant);

void deleteByProcessId(long processId);

@EntityGraph(attributePaths = {"process.dashboard.club.member"})
@Query("SELECT e FROM Evaluation e WHERE e.id = :id")
Optional<Evaluation> findByIdFetchingMember(long id);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Transactional
@Query("DELETE FROM Evaluation e WHERE e.process IN :processes")
void deleteAllByProcesses(@Param("processes") List<Process> processes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.applicant.exception.badrequest;

import com.cruru.advice.badrequest.BadRequestException;

public class ApplicantSortException extends BadRequestException {

private static final String MESSAGE = "지원하는 정렬 조건이 아닙니다.";

public ApplicantSortException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cruru.applicant.exception.badrequest;

import com.cruru.advice.badrequest.BadRequestException;

public class EvaluationStatusException extends BadRequestException {

private static final String MESSAGE = "지원하는 평가 상태가 아닙니다.";

public EvaluationStatusException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cruru.applicant.controller.request.ApplicantMoveRequest;
import com.cruru.applicant.controller.request.ApplicantUpdateRequest;
import com.cruru.applicant.controller.request.ApplicantsRejectRequest;
import com.cruru.applicant.controller.response.ApplicantAnswerResponses;
import com.cruru.applicant.controller.response.ApplicantBasicResponse;
import com.cruru.applicant.controller.response.ApplicantResponse;
Expand Down Expand Up @@ -65,4 +66,14 @@ public void reject(long applicantId) {
public void unreject(long applicantId) {
applicantService.unreject(applicantId);
}

@Transactional
public void reject(ApplicantsRejectRequest request) {
applicantService.reject(request.applicantIds());
}

@Transactional
public void unreject(ApplicantsRejectRequest request) {
applicantService.unreject(request.applicantIds());
}
}
Loading

0 comments on commit 6f6c7e3

Please sign in to comment.