diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c647a9dd..f3445ca0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @hyunihs @suhhyun524 @mushroom1324 @haen-su @mirageoasis \ No newline at end of file +* @hyunihs @mushroom1324 @letskuku @yoonsseo @itsme-shawn @YoungGyo-00 \ No newline at end of file diff --git a/src/main/java/ceos/backend/domain/application/ApplicationController.java b/src/main/java/ceos/backend/domain/application/ApplicationController.java index f14f34db..fa11c758 100644 --- a/src/main/java/ceos/backend/domain/application/ApplicationController.java +++ b/src/main/java/ceos/backend/domain/application/ApplicationController.java @@ -26,15 +26,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @Slf4j @RestController @@ -191,4 +183,11 @@ public GetCreationTime getApplicationExcelCreationTime() { log.info("지원서 엑셀 파일 생성 시각 확인"); return applicationExcelService.getApplicationExcelCreationTime(); } + + @Operation(summary = "지원서 전체 삭제") + @DeleteMapping(value = "/delete") + public void deleteAllApplications() { + log.info("지원서 전체 삭제"); + applicationService.deleteAllApplications(); + } } diff --git a/src/main/java/ceos/backend/domain/application/domain/ApplicationAnswer.java b/src/main/java/ceos/backend/domain/application/domain/ApplicationAnswer.java index 08b77be9..1a291cae 100644 --- a/src/main/java/ceos/backend/domain/application/domain/ApplicationAnswer.java +++ b/src/main/java/ceos/backend/domain/application/domain/ApplicationAnswer.java @@ -17,7 +17,7 @@ public class ApplicationAnswer extends BaseEntity { private Long id; // Question : Answer = 1:1 (단방향) - @OneToOne(cascade = CascadeType.ALL) + @OneToOne @JoinColumn(name = "application_question_id") private ApplicationQuestion applicationQuestion; diff --git a/src/main/java/ceos/backend/domain/application/exception/ApplicationErrorCode.java b/src/main/java/ceos/backend/domain/application/exception/ApplicationErrorCode.java index 97295dad..910a9248 100644 --- a/src/main/java/ceos/backend/domain/application/exception/ApplicationErrorCode.java +++ b/src/main/java/ceos/backend/domain/application/exception/ApplicationErrorCode.java @@ -22,6 +22,7 @@ public enum ApplicationErrorCode implements BaseErrorCode { SAME_PASS_STATUS(BAD_REQUEST, "APPLICATION_400_7", "같은 상태로 변경할 수 없습니다."), NOT_SET_INTERVIEW_TIME(BAD_REQUEST, "APPLICATION_400_8", "면접 시간이 정해지지 않았습니다."), APPLICATION_STILL_EXIST(BAD_REQUEST, "APPLICATION_400_9", "기존 지원자 데이터가 남아있습니다."), + NOT_DELETABLE_DURING_RECRUITMENT(BAD_REQUEST, "APPLICATION_400_10", "최종 발표 전 지원자를 삭제할 수 없습니다."), APPLICANT_NOT_FOUND(BAD_REQUEST, "APPLICATION_404_3", "존재하지 않는 지원자입니다."), diff --git a/src/main/java/ceos/backend/domain/application/exception/exceptions/NotDeletableDuringRecruitment.java b/src/main/java/ceos/backend/domain/application/exception/exceptions/NotDeletableDuringRecruitment.java new file mode 100644 index 00000000..4a0e2e6e --- /dev/null +++ b/src/main/java/ceos/backend/domain/application/exception/exceptions/NotDeletableDuringRecruitment.java @@ -0,0 +1,12 @@ +package ceos.backend.domain.application.exception.exceptions; + +import ceos.backend.domain.application.exception.ApplicationErrorCode; +import ceos.backend.global.error.BaseErrorException; + +public class NotDeletableDuringRecruitment extends BaseErrorException { + public static final NotDeletableDuringRecruitment EXCEPTION = new NotDeletableDuringRecruitment(); + + private NotDeletableDuringRecruitment() { + super(ApplicationErrorCode.NOT_DELETABLE_DURING_RECRUITMENT); + } +} diff --git a/src/main/java/ceos/backend/domain/application/service/ApplicationService.java b/src/main/java/ceos/backend/domain/application/service/ApplicationService.java index 934bae3a..ac9d66a7 100644 --- a/src/main/java/ceos/backend/domain/application/service/ApplicationService.java +++ b/src/main/java/ceos/backend/domain/application/service/ApplicationService.java @@ -18,6 +18,7 @@ import ceos.backend.domain.application.dto.response.GetApplications; import ceos.backend.domain.application.dto.response.GetInterviewTime; import ceos.backend.domain.application.dto.response.GetResultResponse; +import ceos.backend.domain.application.exception.exceptions.NotDeletableDuringRecruitment; import ceos.backend.domain.application.helper.ApplicationHelper; import ceos.backend.domain.application.mapper.ApplicationMapper; import ceos.backend.domain.application.repository.ApplicationAnswerRepository; @@ -35,6 +36,8 @@ import ceos.backend.global.common.entity.Part; import ceos.backend.global.util.InterviewDateTimeConvertor; import ceos.backend.global.util.ParsedDurationConvertor; + +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -264,4 +267,16 @@ public void updateFinalPassStatus(Long applicationId, UpdatePassStatus updatePas application.updateFinalPass(updatePassStatus.getPass()); } + + @Transactional + public void deleteAllApplications() { + Recruitment recruitment = recruitmentHelper.takeRecruitment(); + // 현재 시간이 resultDateFinal 이전이면 삭제 불가 + if(LocalDateTime.now().isBefore(recruitment.getResultDateFinal())) { + throw NotDeletableDuringRecruitment.EXCEPTION; + } + // application, applicationAnswer, applicationInterview 삭제 (cascade) + applicationRepository.deleteAll(); + } + } diff --git a/src/main/java/ceos/backend/domain/recruitment/service/RecruitmentService.java b/src/main/java/ceos/backend/domain/recruitment/service/RecruitmentService.java index a50a9752..47172796 100644 --- a/src/main/java/ceos/backend/domain/recruitment/service/RecruitmentService.java +++ b/src/main/java/ceos/backend/domain/recruitment/service/RecruitmentService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; + @Slf4j @Service @RequiredArgsConstructor @@ -34,6 +36,7 @@ public UserRecruitmentDTO getUserRecruitment() { @Transactional public void updateRecruitment(RecruitmentDTO recruitmentDTO) { Recruitment recruitment = recruitmentHelper.takeRecruitment(); + recruitment.validAmenablePeriod(LocalDateTime.now()); // 객체 업데이트 recruitment.updateRecruitment(recruitmentDTO);