-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat-be: 특정 지원자 카드를 대시보드의 다른 프로세스로 이동 (#30)
* Create draft PR for #29 * feat(Applicant): 지원서 프로세스 변경 API 기능 구현 Co-Authored-By: Leetaehoon <xogns1514@gmail.com> * style: 코드 컨벤션 개행 추가 및 제거 --------- Co-authored-by: Leetaehoon <xogns1514@gmail.com> Co-authored-by: Do Yeop Kim <113661364+Dobby-Kim@users.noreply.github.com>
- Loading branch information
1 parent
21363fc
commit 00407ed
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/cruru/applicant/controller/ApplicantController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cruru.applicant.controller; | ||
|
||
import com.cruru.applicant.controller.dto.ApplicantMoveRequest; | ||
import com.cruru.applicant.service.ApplicantService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/applicants") | ||
@RequiredArgsConstructor | ||
public class ApplicantController { | ||
|
||
private final ApplicantService applicantService; | ||
|
||
@PutMapping("/move-process/{processId}") | ||
public ResponseEntity<Void> updateApplicantProcess( | ||
@PathVariable long processId, | ||
@RequestBody ApplicantMoveRequest moveRequest) { | ||
|
||
applicantService.updateApplicantProcess(processId, moveRequest); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/cruru/applicant/controller/dto/ApplicantMoveRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.cruru.applicant.controller.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
|
||
public record ApplicantMoveRequest( | ||
@JsonProperty(value = "applicant_ids") | ||
List<Long> applicantIds | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/cruru/applicant/service/ApplicantService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cruru.applicant.service; | ||
|
||
import com.cruru.applicant.controller.dto.ApplicantMoveRequest; | ||
import com.cruru.applicant.domain.Applicant; | ||
import com.cruru.applicant.domain.repository.ApplicantRepository; | ||
import com.cruru.process.domain.Process; | ||
import com.cruru.process.domain.repository.ProcessRepository; | ||
import com.cruru.process.exception.ProcessNotFoundException; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ApplicantService { | ||
|
||
private final ApplicantRepository applicantRepository; | ||
private final ProcessRepository processRepository; | ||
|
||
public void updateApplicantProcess(long processId, ApplicantMoveRequest moveRequest) { | ||
Process process = processRepository.findById(processId) | ||
.orElseThrow(ProcessNotFoundException::new); | ||
|
||
List<Applicant> applicants = applicantRepository.findAllById(moveRequest.applicantIds()); | ||
applicants.forEach(applicant -> applicant.updateProcess(process)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/cruru/process/exception/ProcessNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.process.exception; | ||
|
||
import com.cruru.advice.NotFoundException; | ||
|
||
public class ProcessNotFoundException extends NotFoundException { | ||
|
||
private static final String MESSAGE = "존재하지 않는 프로세스입니다."; | ||
|
||
public ProcessNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/com/cruru/applicant/service/ApplicantServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.cruru.applicant.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.cruru.applicant.controller.dto.ApplicantMoveRequest; | ||
import com.cruru.applicant.domain.Applicant; | ||
import com.cruru.applicant.domain.repository.ApplicantRepository; | ||
import com.cruru.dashboard.domain.Dashboard; | ||
import com.cruru.dashboard.domain.repository.DashboardRepository; | ||
import com.cruru.process.domain.Process; | ||
import com.cruru.process.domain.repository.ProcessRepository; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
class ApplicantServiceTest { | ||
|
||
@Autowired | ||
private ApplicantService applicantService; | ||
|
||
@Autowired | ||
private ApplicantRepository applicantRepository; | ||
|
||
@Autowired | ||
private ProcessRepository processRepository; | ||
|
||
@Autowired | ||
private DashboardRepository dashboardRepository; | ||
|
||
@DisplayName("다건의 지원서를 요청된 프로세스로 일괄 변경한다.") | ||
@Test | ||
void updateApplicantProcess() { | ||
// given | ||
Dashboard dashboard = dashboardRepository.save(new Dashboard(1L, "모집 공고1", null)); | ||
Process beforeProcess = new Process(1L, "이전 프로세스", "프로세스 설명1", dashboard); | ||
Process afterProcess = new Process(2L, "이후 프로세스", "프로세스 설명2", dashboard); | ||
List<Process> processes = List.of(beforeProcess, afterProcess); | ||
processRepository.saveAll(processes); | ||
List<Applicant> applicants = List.of(new Applicant(1L, null, null, null, beforeProcess), | ||
new Applicant(2L, null, null, null, beforeProcess), new Applicant(3L, null, null, null, beforeProcess), | ||
new Applicant(4L, null, null, null, beforeProcess), new Applicant(5L, null, null, null, beforeProcess)); | ||
|
||
// when | ||
List<Long> applicantIds = List.of(1L, 2L, 3L, 4L, 5L); | ||
ApplicantMoveRequest moveRequest = new ApplicantMoveRequest(applicantIds); | ||
applicantService.updateApplicantProcess(2L, moveRequest); | ||
|
||
// then | ||
List<Applicant> actualApplicants = applicantRepository.findAllById(applicantIds); | ||
List<Process> actualProcesses = actualApplicants.stream() | ||
.map(Applicant::getProcess) | ||
.toList(); | ||
assertThat(actualProcesses.stream() | ||
.allMatch(process -> process.equals(afterProcess))).isTrue(); | ||
} | ||
} | ||
|