-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 면접 예약 API 구현 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
94eb07c
feat: 면접 예약 API 구현
hodoon 6b966e8
feat: 면접 예약 API InterviewSlotRepository 쿼리 추가
hodoon 3c98cc7
feat: 면접 예약 API
hodoon 83a5012
Merge branch 'dev' into feat/#45-1
hodoon 79fb59c
fix: 면접 예약 API 수정 완료
hodoon 881c958
Merge branch 'feat/#45-1' of https://github.com/DASOM-GitHub/dasom-we…
hodoon 438fc5c
feat: Google Credentials 주입 방식 파일이 아닌 JSON 값으로 받도록 수정
ysw789 be79688
chore: .gitignore 적용되지 않는 항목 제거
ysw789 e54c4cb
Merge remote-tracking branch 'origin/feat/#45-1' into feat/#45-1
ysw789 051c4a4
fix: 면접 예약 API 수정 완료
hodoon caf2c7a
fix: 면접 예약 API 수정 완료
hodoon ba34fa7
fix: 면접 예약 API 수정 완료
hodoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
src/main/java/dmu/dasom/api/domain/interview/dto/InterviewReservationRequestDto.java
This file contains hidden or 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,17 @@ | ||
| package dmu.dasom.api.domain.interview.dto; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewReservationRequestDto { | ||
|
|
||
| private Long slotId; // 예약할 슬롯 ID | ||
|
|
||
| private Long applicantId; // 지원자 ID | ||
|
|
||
| private String reservationCode; // 학번 뒤 4자리 + 전화번호 뒤 4자리 조합 코드 | ||
hodoon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/main/java/dmu/dasom/api/domain/interview/dto/InterviewReservationResponseDto.java
This file contains hidden or 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,20 @@ | ||
| package dmu.dasom.api.domain.interview.dto; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewReservationResponseDto { | ||
|
|
||
| private Long reservationId; // 예약 ID | ||
|
|
||
| private Long slotId; // 슬롯 ID | ||
|
|
||
| private Long applicantId; // 지원자 ID | ||
|
|
||
| private String reservationCode; // 예약 코드 (학번+전화번호 조합) | ||
|
|
||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/dmu/dasom/api/domain/interview/dto/InterviewSlotRequestDto.java
This file contains hidden or 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,22 @@ | ||
| package dmu.dasom.api.domain.interview.dto; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewSlotRequestDto { | ||
|
|
||
| private LocalDate interviewDate; // 면접 날짜 | ||
|
|
||
| private LocalTime startTime; // 시작 시간 | ||
|
|
||
| private LocalTime endTime; // 종료 시간 | ||
|
|
||
| private Integer maxCandidates; // 최대 지원자 수 | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/dmu/dasom/api/domain/interview/dto/InterviewSlotResponseDto.java
This file contains hidden or 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,32 @@ | ||
| package dmu.dasom.api.domain.interview.dto; | ||
|
|
||
| import dmu.dasom.api.domain.interview.entity.InterviewSlot; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewSlotResponseDto { | ||
|
|
||
| private Long id; // 슬롯 ID | ||
| private LocalDate interviewDate; // 면접 날짜 | ||
| private LocalTime startTime; // 시작 시간 | ||
| private LocalTime endTime; // 종료 시간 | ||
| private Integer maxCandidates; // 최대 지원자 수 | ||
| private Integer currentCandidates; // 현재 예약된 지원자 수 | ||
|
|
||
| public InterviewSlotResponseDto(InterviewSlot slot){ | ||
| this.id = slot.getId(); | ||
| this.interviewDate = slot.getInterviewDate(); | ||
| this.startTime = slot.getStartTime(); | ||
| this.endTime = slot.getEndTime(); | ||
| this.maxCandidates = slot.getMaxCandidates(); | ||
| this.currentCandidates = slot.getCurrentCandidates(); | ||
| } | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/dmu/dasom/api/domain/interview/entity/InterviewReservation.java
This file contains hidden or 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 dmu.dasom.api.domain.interview.entity; | ||
|
|
||
| import dmu.dasom.api.domain.applicant.entity.Applicant; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewReservation { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "slot_id", nullable = false) | ||
| private InterviewSlot slot; // 연관된 면접 슬롯 | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "applicant_id", nullable = false) | ||
| private Applicant applicant; // 지원자 | ||
|
|
||
| @Column(nullable = false, unique = true, length = 8) | ||
| private String reservationCode; // 학번 뒤 4자리 + 전화번호 뒤 4자리 조합 코드 | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/main/java/dmu/dasom/api/domain/interview/entity/InterviewSlot.java
This file contains hidden or 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,54 @@ | ||
| package dmu.dasom.api.domain.interview.entity; | ||
|
|
||
| import dmu.dasom.api.domain.interview.enums.Status; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class InterviewSlot { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDate interviewDate; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalTime startTime; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalTime endTime; // 종료 시간 | ||
|
|
||
| @Column(nullable = false) | ||
| private Integer maxCandidates; // 최대 지원자 수 | ||
|
|
||
| @Column(nullable = false) | ||
| private Integer currentCandidates; // 현재 예약된 지원자 수 | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false, length = 16) | ||
| private Status status; // 면접 슬롯 상태 (ACTIVE, INACTIVE, CLOSED) | ||
|
|
||
| public void incrementCurrentCandidates() { | ||
| this.currentCandidates++; | ||
| if (this.currentCandidates >= this.maxCandidates) { | ||
| this.status = Status.CLOSED; // 최대 지원자 수에 도달하면 상태 변경 | ||
| } | ||
| } | ||
|
|
||
| public void decrementCurrentCandidates() { | ||
| this.currentCandidates--; | ||
| if (status == Status.CLOSED && this.currentCandidates < this.maxCandidates) { | ||
| this.status = Status.ACTIVE; // 지원자 수가 줄어들면 다시 활성화 | ||
| } | ||
| } | ||
|
|
||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/dmu/dasom/api/domain/interview/enums/Status.java
This file contains hidden or 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,7 @@ | ||
| package dmu.dasom.api.domain.interview.enums; | ||
|
|
||
| public enum Status { | ||
hodoon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ACTIVE, // 활성화된 슬롯 | ||
| INACTIVE, // 비활성화된 슬롯 | ||
| CLOSED // 예약 마감된 슬롯 | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/dmu/dasom/api/domain/interview/repositoty/InterviewReservationRepository.java
This file contains hidden or 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 dmu.dasom.api.domain.interview.repositoty; | ||
|
|
||
| import dmu.dasom.api.domain.interview.entity.InterviewReservation; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface InterviewReservationRepository extends JpaRepository<InterviewReservation, Long> { | ||
| boolean existsByReservationCode(String reservationCode); | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/dmu/dasom/api/domain/interview/repositoty/InterviewSlotRepository.java
This file contains hidden or 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,18 @@ | ||
| package dmu.dasom.api.domain.interview.repositoty; | ||
|
|
||
| import dmu.dasom.api.domain.interview.entity.InterviewSlot; | ||
| import dmu.dasom.api.domain.interview.enums.Status; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface InterviewSlotRepository extends JpaRepository<InterviewSlot, Long> { | ||
| Collection<InterviewSlot> findAllByCurrentCandidatesLessThanMaxCandidates(); | ||
| List<InterviewSlot> findAllByStatusAndCurrentCandidatesLessThanMaxCandidates( | ||
| Status status); | ||
|
|
||
| boolean exists(); | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/dmu/dasom/api/domain/interview/service/InterviewService.java
This file contains hidden or 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,26 @@ | ||
| package dmu.dasom.api.domain.interview.service; | ||
|
|
||
| import dmu.dasom.api.domain.interview.dto.InterviewReservationRequestDto; | ||
| import dmu.dasom.api.domain.interview.dto.InterviewSlotResponseDto; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| public interface InterviewService { | ||
|
|
||
| // 면접 슬롯 생성 | ||
| List<InterviewSlotResponseDto> createInterviewSlots(LocalDate newStartDate, LocalDate newEndDate, LocalTime newStartTime, LocalTime newEndTime); | ||
|
|
||
| // 예약 가능한 면접 슬롯 조회 | ||
| List<InterviewSlotResponseDto> getAvailableSlots(); | ||
|
|
||
| // 면접 예약 | ||
| void reserveInterviewSlot(InterviewReservationRequestDto request); | ||
|
|
||
| // 면접 예약 취소 | ||
| void cancelReservation(Long reservationId, Long applicantId); | ||
|
|
||
|
|
||
| } |
131 changes: 131 additions & 0 deletions
131
src/main/java/dmu/dasom/api/domain/interview/service/InterviewServiceImpl.java
This file contains hidden or 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,131 @@ | ||
| package dmu.dasom.api.domain.interview.service; | ||
|
|
||
| import dmu.dasom.api.domain.applicant.entity.Applicant; | ||
| import dmu.dasom.api.domain.applicant.repository.ApplicantRepository; | ||
| import dmu.dasom.api.domain.common.exception.CustomException; | ||
| import dmu.dasom.api.domain.common.exception.ErrorCode; | ||
| import dmu.dasom.api.domain.interview.dto.InterviewReservationRequestDto; | ||
| import dmu.dasom.api.domain.interview.dto.InterviewSlotResponseDto; | ||
| import dmu.dasom.api.domain.interview.entity.InterviewReservation; | ||
| import dmu.dasom.api.domain.interview.entity.InterviewSlot; | ||
| import dmu.dasom.api.domain.interview.enums.Status; | ||
| import dmu.dasom.api.domain.interview.repositoty.InterviewReservationRepository; | ||
| import dmu.dasom.api.domain.interview.repositoty.InterviewSlotRepository; | ||
| import dmu.dasom.api.domain.recruit.service.RecruitServiceImpl; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| @Transactional(readOnly = true) | ||
| public class InterviewServiceImpl implements InterviewService{ | ||
|
|
||
| private final InterviewSlotRepository interviewSlotRepository; | ||
| private final InterviewReservationRepository interviewReservationRepository; | ||
| private final ApplicantRepository applicantRepository; | ||
| private final RecruitServiceImpl recruitService; | ||
|
|
||
| // 면접 슬롯 생성 | ||
| @Override | ||
| @Transactional | ||
| public List<InterviewSlotResponseDto> createInterviewSlots(LocalDate newStartDate, LocalDate newEndDate, LocalTime newStartTime, LocalTime newEndTime) { | ||
| boolean slotsExist = interviewSlotRepository.exists(); | ||
|
|
||
| if(slotsExist){ | ||
| interviewSlotRepository.deleteAll(); | ||
| } | ||
|
|
||
| List<InterviewSlotResponseDto> newSlots = new ArrayList<>(); | ||
| for(LocalDate date = newStartDate; !date.isAfter(newEndDate); date = date.plusDays(1)){ | ||
| LocalTime currentTime = newStartTime; | ||
| while (currentTime.isBefore(newEndTime)){ | ||
| LocalTime slotEndTime = currentTime.plusMinutes(20); | ||
|
|
||
| InterviewSlot slot = InterviewSlot.builder() | ||
| .interviewDate(date) | ||
| .startTime(currentTime) | ||
| .endTime(slotEndTime) | ||
| .maxCandidates(2) | ||
| .currentCandidates(0) | ||
| .status(Status.ACTIVE) | ||
| .build(); | ||
|
|
||
| interviewSlotRepository.save(slot); | ||
| newSlots.add(new InterviewSlotResponseDto(slot)); | ||
| currentTime = slotEndTime; | ||
| } | ||
| } | ||
|
|
||
| return newSlots; | ||
| } | ||
|
|
||
| // 예약 가능한 면접 슬롯 조회 | ||
| @Override | ||
| public List<InterviewSlotResponseDto> getAvailableSlots() { | ||
| return interviewSlotRepository.findAllByStatusAndCurrentCandidatesLessThanMaxCandidates(Status.ACTIVE) | ||
| .stream() | ||
| .map(InterviewSlotResponseDto::new) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void reserveInterviewSlot(InterviewReservationRequestDto request) { | ||
| InterviewSlot slot = interviewSlotRepository.findById(request.getSlotId()) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.SLOT_NOT_FOUND)); | ||
|
|
||
| if(!slot.getStatus().equals(Status.ACTIVE)){ | ||
| throw new CustomException(ErrorCode.SLOT_NOT_ACTIVE); | ||
| } | ||
|
|
||
| if (slot.getCurrentCandidates() >= slot.getMaxCandidates()) { | ||
| throw new CustomException(ErrorCode.SLOT_FULL); | ||
| } | ||
|
|
||
| Applicant applicant = applicantRepository.findById(request.getApplicantId()) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.APPLICANT_NOT_FOUND)); | ||
|
|
||
| boolean alreadyReserved = interviewReservationRepository.existsByReservationCode(request.getReservationCode()); | ||
| if (alreadyReserved) { | ||
| throw new CustomException(ErrorCode.ALREADY_RESERVED); | ||
| } | ||
|
|
||
| // 예약 정보 저장 | ||
| InterviewReservation reservation = InterviewReservation.builder() | ||
| .slot(slot) | ||
| .applicant(applicant) | ||
| .reservationCode(request.getReservationCode()) | ||
| .build(); | ||
|
|
||
| interviewReservationRepository.save(reservation); | ||
|
|
||
| // 현재 예약 인원 증가 | ||
| slot.incrementCurrentCandidates(); | ||
| } | ||
|
|
||
| // 면접 예약 취소 | ||
| @Override | ||
| @Transactional | ||
| public void cancelReservation(Long reservationId, Long applicantId) { | ||
| InterviewReservation reservation = interviewReservationRepository.findById(reservationId) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.RESERVATION_NOT_FOUND)); | ||
|
|
||
| if (!reservation.getApplicant().getId().equals(applicantId)) { | ||
| throw new CustomException(ErrorCode.UNAUTHORIZED); | ||
| } | ||
|
|
||
| // 현재 예약 인원 감소 | ||
| InterviewSlot slot = reservation.getSlot(); | ||
| slot.decrementCurrentCandidates(); | ||
|
|
||
| // 예약 삭제 | ||
| interviewReservationRepository.delete(reservation); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.