From dceca7d3109857954ea921ddc235b7f0019a8729 Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 10:54:58 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[feat][#56]=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=83=9D=EC=84=B1=20&=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=EC=A1=B0=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecruitScheduleController.java | 40 +++++++++++++++++++ .../dao/RecruitScheduleRepository.java | 2 + .../request/RecruitScheduleCreateRequest.java | 10 ++--- .../recruit/entity/RecruitSchedule.java | 3 +- .../service/RecruitScheduleService.java | 8 +++- .../service/RecruitScheduleServiceImpl.java | 21 ++++++++-- .../recruit/service/RecruitService.java | 3 +- 7 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java new file mode 100644 index 0000000..6310278 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java @@ -0,0 +1,40 @@ +package com.server.bbo_gak.domain.recruit.controller; + +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; +import com.server.bbo_gak.domain.recruit.service.RecruitScheduleService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/recruits/{id}/recruit-schedule") +@RequiredArgsConstructor +public class RecruitScheduleController { + private final RecruitScheduleService recruitScheduleService; + + + /** + * 공고 일정 생성 + */ + @PostMapping("") + public ResponseEntity createRecruitSchedule( + @PathVariable("id") Long id, //공고 id + @RequestBody RecruitScheduleCreateRequest request) { + recruitScheduleService.createRecruitSchedule(id, request); + return ResponseEntity.ok().body(null); + } + + /** + * 공고 일정 전체 조회 + */ + @GetMapping("") + public ResponseEntity> getRecruitScheduleList( + @PathVariable("id") Long id //공고 id + ) { + return ResponseEntity.ok().body(recruitScheduleService.getRecruitScheduleList(id)); + } + +} diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java b/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java index 27c0f79..c652f46 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java @@ -8,4 +8,6 @@ public interface RecruitScheduleRepository extends JpaRepository { List findAllByDeadLineBetween(LocalDate now, LocalDate nowPlusOneDay); + + List findAllByRecruitId(Long recruitId); } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java index 4ec85de..1a7c4f6 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java @@ -1,18 +1,18 @@ package com.server.bbo_gak.domain.recruit.dto.request; -import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; -import java.time.LocalDate; +import lombok.Builder; +@Builder public record RecruitScheduleCreateRequest( RecruitScheduleStage recruitScheduleStage, String deadline ) { - public static RecruitSchedule of(RecruitScheduleStage recruitScheduleStage, String deadline) { - return RecruitSchedule.builder() + public static RecruitScheduleCreateRequest of(RecruitScheduleStage recruitScheduleStage, String deadline) { + return RecruitScheduleCreateRequest.builder() .recruitScheduleStage(recruitScheduleStage) - .deadLine(LocalDate.parse(deadline)) + .deadline(deadline) .build(); } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java index 5ab1a38..41c0f0d 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java @@ -50,7 +50,8 @@ public static RecruitSchedule of(Recruit recruit, RecruitScheduleStage recruitSc return RecruitSchedule.builder() .recruit(recruit) .recruitScheduleStage(recruitScheduleStage) - .deadLine(LocalDate.parse(deadLine)).build(); + .deadLine(LocalDate.parse(deadLine)) + .build(); } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java index 196b406..9a44987 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java @@ -1,14 +1,18 @@ package com.server.bbo_gak.domain.recruit.service; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; import org.springframework.stereotype.Service; +import java.util.List; + @Service public interface RecruitScheduleService { - RecruitSchedule createRecruitSchedule(RecruitSchedule recruitSchedule); + RecruitSchedule createRecruitSchedule(Long id, RecruitScheduleCreateRequest request); - void getRecruitScheduleList(); + List getRecruitScheduleList(Long recruitId); void updateRecruitSchedule(); diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java index 04cc0de..ccdd1a0 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java @@ -1,15 +1,24 @@ package com.server.bbo_gak.domain.recruit.service; +import com.server.bbo_gak.domain.recruit.dao.RecruitRepository; import com.server.bbo_gak.domain.recruit.dao.RecruitScheduleRepository; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; +import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; +import com.server.bbo_gak.global.error.exception.ErrorCode; +import com.server.bbo_gak.global.error.exception.NotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor public class RecruitScheduleServiceImpl implements RecruitScheduleService { private final RecruitScheduleRepository recruitScheduleRepository; + private final RecruitRepository recruitRepository; @Override public void deleteRecruitSchedule() { @@ -22,12 +31,16 @@ public void updateRecruitSchedule() { } @Override - public void getRecruitScheduleList() { - + public List getRecruitScheduleList(Long recruitId) { + return recruitScheduleRepository.findAllByRecruitId(recruitId).stream() + .map(RecruitScheduleGetResponse::from) + .toList(); } @Override - public RecruitSchedule createRecruitSchedule(RecruitSchedule recruitSchedule) { - return recruitScheduleRepository.save(recruitSchedule); + public RecruitSchedule createRecruitSchedule(Long id, RecruitScheduleCreateRequest request) { + Recruit recruit = recruitRepository.findById(id) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); + return recruitScheduleRepository.save(RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline())); } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java index 2a7985f..a7fa815 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java @@ -2,6 +2,7 @@ import com.server.bbo_gak.domain.recruit.dao.RecruitRepository; import com.server.bbo_gak.domain.recruit.dto.request.RecruitCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetResponse; import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; @@ -98,7 +99,7 @@ public RecruitGetResponse createRecruit(User user, RecruitCreateRequest request) // 공고 일정 생성 RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( - RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline()) + recruit.getId(), RecruitScheduleCreateRequest.of(request.recruitScheduleStage(), request.deadline()) ); // 공고에 공고 일정을 설정 From 61b17e68e6b7422fbfe91c2c01ec1eac9de8974a Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 17:30:46 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[fix][#56]=20=EA=B3=B5=EA=B3=A0=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EC=83=9D=EC=84=B1=20Request=20-=20=EA=B3=B5?= =?UTF-8?q?=EA=B3=A0=20=EB=8B=A8=EA=B3=84=20String=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/RecruitScheduleCreateRequest.java | 5 +- .../recruit/entity/RecruitSchedule.java | 4 +- .../recruit/service/RecruitService.java | 257 +++++++++--------- 3 files changed, 133 insertions(+), 133 deletions(-) diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java index 1a7c4f6..0117916 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java @@ -1,15 +1,14 @@ package com.server.bbo_gak.domain.recruit.dto.request; -import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; import lombok.Builder; @Builder public record RecruitScheduleCreateRequest( - RecruitScheduleStage recruitScheduleStage, + String recruitScheduleStage, String deadline ) { - public static RecruitScheduleCreateRequest of(RecruitScheduleStage recruitScheduleStage, String deadline) { + public static RecruitScheduleCreateRequest of(String recruitScheduleStage, String deadline) { return RecruitScheduleCreateRequest.builder() .recruitScheduleStage(recruitScheduleStage) .deadline(deadline) diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java index f0f3b2d..3f61d6a 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java @@ -47,10 +47,10 @@ public RecruitSchedule(Recruit recruit, RecruitScheduleStage recruitScheduleStag this.deadLine = deadLine; } - public static RecruitSchedule of(Recruit recruit, RecruitScheduleStage recruitScheduleStage, String deadLine) { + public static RecruitSchedule of(Recruit recruit, String recruitScheduleStage, String deadLine) { return RecruitSchedule.builder() .recruit(recruit) - .recruitScheduleStage(recruitScheduleStage) + .recruitScheduleStage(RecruitScheduleStage.findByValue(recruitScheduleStage)) .deadLine(LocalDate.parse(deadLine)).build(); } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java index c248c2a..820bdb9 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java @@ -7,7 +7,6 @@ import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetResponse; import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; -import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; import com.server.bbo_gak.domain.recruit.entity.RecruitStatusCategory; import com.server.bbo_gak.domain.recruit.entity.Season; @@ -27,146 +26,148 @@ @RequiredArgsConstructor public class RecruitService { - private final RecruitRepository recruitRepository; - private final SeasonService seasonService; - private final RecruitScheduleService recruitScheduleService; - - public List getTotalRecruitList(User user) { - List recruits = recruitRepository.findAllByUserId(user.getId()); - - return recruits.stream() - .sorted((r1, r2) -> r2.getCreatedDate().compareTo(r1.getCreatedDate())) - .map(RecruitGetResponse::from) - .toList(); + private final RecruitRepository recruitRepository; + private final SeasonService seasonService; + private final RecruitScheduleService recruitScheduleService; + + public List getTotalRecruitList(User user) { + List recruits = recruitRepository.findAllByUserId(user.getId()); + + return recruits.stream() + .sorted((r1, r2) -> r2.getCreatedDate().compareTo(r1.getCreatedDate())) + .map(RecruitGetResponse::from) + .toList(); + } + + public List getRecruitListBySeason(User user, String seasonName) { + Season season = seasonService.getSeasonByName(user, seasonName); + return recruitRepository.findAllByUserIdAndSeason(user.getId(), season).stream() + .map(RecruitGetResponse::from) + .toList(); + } + + + // TODO: 진행중인 공고는 일정등록이 안된 것을 우선으로 그 이후에는 RecruitSchedule이 현재와 가까운 순으로 정렬한다. + public List getProgressingRecruitList(User user) { + + List recruits = recruitRepository.findAllByUserId(user.getId()); + + // 불합격이 아닌 공고중에서 스케줄이 비어 있거나 지난 일정만 등록되어 있는 공고 중에서 지원 상태가 불합격인 공고를 분리해냄 + Map> partitionedRecruitsByNeedingSchedule = partitionRecruits(recruits); + + List recruitsNeedingSchedule = partitionedRecruitsByNeedingSchedule.get(true); + List recruitsWithSchedule = partitionedRecruitsByNeedingSchedule.get(false); + + //recruitsWithSchedule에서 시간이 지나지 않은 스케줄 중에서 가장 현재와 가까운 걸 기준으로 정렬 + List sortedRecruitsWithSchedule = recruitsWithSchedule.stream() + .sorted(Comparator.comparing(this::getNearestUpcomingDate)) + .toList(); + + recruitsNeedingSchedule.addAll(sortedRecruitsWithSchedule); + + return recruitsNeedingSchedule.stream() + .map(RecruitGetResponse::from) + .toList(); + } + + private LocalDate getNearestUpcomingDate(Recruit recruit) { + return recruit.getScheduleList().stream() + .map(RecruitSchedule::getDeadLine) + .filter(deadLine -> deadLine.isAfter(LocalDate.now())) + .min(Comparator.naturalOrder()) + .orElse(LocalDate.MAX); + } + + private Map> partitionRecruits(List recruits) { + return recruits.stream() + .filter(recruit -> !RecruitStatusCategory.isRejectionStatus( + recruit.getRecruitStatus())) // 불합격 상태 필터링 + .collect(Collectors.partitioningBy(this::isNeedsScheduleUpdate)); + } + + private boolean isNeedsScheduleUpdate(Recruit recruit) { + List scheduleList = recruit.getScheduleList(); + return scheduleList.isEmpty() || scheduleList.stream() + .allMatch(schedule -> schedule.getDeadLine().isBefore(LocalDate.now())); + } + + public RecruitGetInnerResponse getRecruit(User user, Long recruitId) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); + return RecruitGetInnerResponse.from(recruit); + } + + @Transactional + public RecruitGetResponse createRecruit(User user, RecruitCreateRequest request) { + + Season season = seasonService.getSeasonByName(user, request.season()); + Recruit recruit = request.toEntity(user, season); + // 공고 저장하여 id 확보 + Recruit savedRecruit = recruitRepository.save(recruit); + + addRecruitScheduleIfRequired(request, savedRecruit); + + // 공고에 공고 일정을 설정 + recruitRepository.save(recruit); + + return RecruitGetResponse.from(savedRecruit); + } + + private void addRecruitScheduleIfRequired(RecruitCreateRequest request, Recruit recruit) { + if (request.deadline() != null && !request.deadline().isEmpty()) { + RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( + recruit.getId(), + RecruitScheduleCreateRequest.of( + request.recruitScheduleStage(), request.deadline()) + ); + recruit.addSchedule(recruitSchedule); } + } - public List getRecruitListBySeason(User user, String seasonName) { - Season season = seasonService.getSeasonByName(user, seasonName); - return recruitRepository.findAllByUserIdAndSeason(user.getId(), season).stream() - .map(RecruitGetResponse::from) - .toList(); - } - - - // TODO: 진행중인 공고는 일정등록이 안된 것을 우선으로 그 이후에는 RecruitSchedule이 현재와 가까운 순으로 정렬한다. - public List getProgressingRecruitList(User user) { - - List recruits = recruitRepository.findAllByUserId(user.getId()); - - // 불합격이 아닌 공고중에서 스케줄이 비어 있거나 지난 일정만 등록되어 있는 공고 중에서 지원 상태가 불합격인 공고를 분리해냄 - Map> partitionedRecruitsByNeedingSchedule = partitionRecruits(recruits); - - List recruitsNeedingSchedule = partitionedRecruitsByNeedingSchedule.get(true); - List recruitsWithSchedule = partitionedRecruitsByNeedingSchedule.get(false); - - //recruitsWithSchedule에서 시간이 지나지 않은 스케줄 중에서 가장 현재와 가까운 걸 기준으로 정렬 - List sortedRecruitsWithSchedule = recruitsWithSchedule.stream() - .sorted(Comparator.comparing(this::getNearestUpcomingDate)) - .toList(); + @Transactional + public void deleteRecruit(User user, Long recruitId) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); - recruitsNeedingSchedule.addAll(sortedRecruitsWithSchedule); + recruitRepository.deleteById(recruit.getId()); + } - return recruitsNeedingSchedule.stream() - .map(RecruitGetResponse::from) - .toList(); - } + @Transactional + public RecruitGetResponse updateRecruitTitle(User user, Long recruitId, String title) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); - private LocalDate getNearestUpcomingDate(Recruit recruit) { - return recruit.getScheduleList().stream() - .map(RecruitSchedule::getDeadLine) - .filter(deadLine -> deadLine.isAfter(LocalDate.now())) - .min(Comparator.naturalOrder()) - .orElse(LocalDate.MAX); - } + recruit.updateTitle(title); - private Map> partitionRecruits(List recruits) { - return recruits.stream() - .filter(recruit -> !RecruitStatusCategory.isRejectionStatus(recruit.getRecruitStatus())) // 불합격 상태 필터링 - .collect(Collectors.partitioningBy(this::isNeedsScheduleUpdate)); - } + return RecruitGetResponse.from(recruitRepository.save(recruit)); + } - private boolean isNeedsScheduleUpdate(Recruit recruit) { - List scheduleList = recruit.getScheduleList(); - return scheduleList.isEmpty() || scheduleList.stream() - .allMatch(schedule -> schedule.getDeadLine().isBefore(LocalDate.now())); - } + @Transactional + public RecruitGetResponse updateRecruitSeason(User user, Long recruitId, String seasonName) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); + Season season = seasonService.getSeasonByName(user, seasonName); + recruit.updateSeason(season); - public RecruitGetInnerResponse getRecruit(User user, Long recruitId) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); - return RecruitGetInnerResponse.from(recruit); - } + return RecruitGetResponse.from(recruitRepository.save(recruit)); + } - @Transactional - public RecruitGetResponse createRecruit(User user, RecruitCreateRequest request) { + @Transactional + public RecruitGetResponse updateRecruitStatus(User user, Long recruitId, String recruitStatus) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); - Season season = seasonService.getSeasonByName(user, request.season()); - Recruit recruit = request.toEntity(user, season); - // 공고 저장하여 id 확보 - Recruit savedRecruit = recruitRepository.save(recruit); + recruit.updateRecruitStatus(RecruitStatus.findByValue(recruitStatus)); - addRecruitScheduleIfRequired(request, savedRecruit); + return RecruitGetResponse.from(recruitRepository.save(recruit)); + } - // 공고에 공고 일정을 설정 - recruitRepository.save(recruit); + @Transactional + public RecruitGetResponse updateRecruitSiteUrl(User user, Long recruitId, String siteUrl) { + Recruit recruit = findRecruitByUserAndId(user, recruitId); - return RecruitGetResponse.from(savedRecruit); - } - - private void addRecruitScheduleIfRequired(RecruitCreateRequest request, Recruit recruit) { - if (request.deadline() != null && !request.deadline().isEmpty()) { - RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( - RecruitSchedule.of(recruit.getId(), RecruitScheduleStage.findByValue(request.recruitScheduleStage()), - request.deadline()) - ); - recruit.addSchedule(recruitSchedule); - } - } + recruit.updateSiteUrl(siteUrl); - @Transactional - public void deleteRecruit(User user, Long recruitId) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); + return RecruitGetResponse.from(recruitRepository.save(recruit)); + } - recruitRepository.deleteById(recruit.getId()); - } - - @Transactional - public RecruitGetResponse updateRecruitTitle(User user, Long recruitId, String title) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); - - recruit.updateTitle(title); - - return RecruitGetResponse.from(recruitRepository.save(recruit)); - } - - @Transactional - public RecruitGetResponse updateRecruitSeason(User user, Long recruitId, String seasonName) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); - Season season = seasonService.getSeasonByName(user, seasonName); - recruit.updateSeason(season); - - return RecruitGetResponse.from(recruitRepository.save(recruit)); - } - - @Transactional - public RecruitGetResponse updateRecruitStatus(User user, Long recruitId, String recruitStatus) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); - - recruit.updateRecruitStatus(RecruitStatus.findByValue(recruitStatus)); - - return RecruitGetResponse.from(recruitRepository.save(recruit)); - } - - @Transactional - public RecruitGetResponse updateRecruitSiteUrl(User user, Long recruitId, String siteUrl) { - Recruit recruit = findRecruitByUserAndId(user, recruitId); - - recruit.updateSiteUrl(siteUrl); - - return RecruitGetResponse.from(recruitRepository.save(recruit)); - } - - private Recruit findRecruitByUserAndId(User user, Long recruitId) { - return recruitRepository.findByUserIdAndId(user.getId(), recruitId) - .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); - } + private Recruit findRecruitByUserAndId(User user, Long recruitId) { + return recruitRepository.findByUserIdAndId(user.getId(), recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); + } } From 2376541c55f53e13c55f5368d4e3780320e0c881 Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 18:01:44 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[feat][#56]=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20-=20=EA=B3=B5=EA=B3=A0=EB=8B=A8=EA=B3=84?= =?UTF-8?q?=20&=20=EB=A7=88=EA=B0=90=EC=9D=BC=20=EC=88=98=EC=A0=95=20api?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecruitScheduleController.java | 27 +++++++ .../dao/RecruitScheduleRepository.java | 3 + .../RecruitScheduleUpdateDeadLineRequest.java | 5 ++ .../RecruitScheduleUpdateStageRequest.java | 5 ++ .../recruit/entity/RecruitSchedule.java | 8 ++ .../service/RecruitScheduleService.java | 5 +- .../service/RecruitScheduleServiceImpl.java | 19 ++++- .../global/error/exception/ErrorCode.java | 2 + .../RecruitScheduleControllerTest.java | 75 +++++++++++++++++++ 9 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java create mode 100644 src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java create mode 100644 src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java index 6310278..d791029 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java @@ -1,6 +1,8 @@ package com.server.bbo_gak.domain.recruit.controller; import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateDeadLineRequest; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateStageRequest; import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; import com.server.bbo_gak.domain.recruit.service.RecruitScheduleService; import lombok.RequiredArgsConstructor; @@ -37,4 +39,29 @@ public ResponseEntity> getRecruitScheduleList( return ResponseEntity.ok().body(recruitScheduleService.getRecruitScheduleList(id)); } + /** + * 공고 일정 (공고단계) 업데이트 + */ + @PutMapping("/{recruit-schedule-id}/stage") + public ResponseEntity updateRecruitScheduleStage( + @PathVariable("id") Long id, //공고 id + @PathVariable("recruit-schedule-id") Long recruitScheduleId, + @RequestBody RecruitScheduleUpdateStageRequest request + ) { + recruitScheduleService.updateRecruitScheduleStage(id, recruitScheduleId, request.stage()); + return ResponseEntity.ok().body(null); + } + + /** + * 공고 일정 (공고 마감일) 업데이트 + */ + @PutMapping("/{recruit-schedule-id}/deadLine") + public ResponseEntity updateDeadLine( + @PathVariable("id") Long id, //공고 id + @PathVariable("recruit-schedule-id") Long recruitScheduleId, + @RequestBody RecruitScheduleUpdateDeadLineRequest request + ) { + recruitScheduleService.updateDeadLine(id, recruitScheduleId, request.deadLine()); + return ResponseEntity.ok().body(null); + } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java b/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java index c652f46..ec21f42 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dao/RecruitScheduleRepository.java @@ -3,6 +3,7 @@ import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; import java.time.LocalDate; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface RecruitScheduleRepository extends JpaRepository { @@ -10,4 +11,6 @@ public interface RecruitScheduleRepository extends JpaRepository findAllByDeadLineBetween(LocalDate now, LocalDate nowPlusOneDay); List findAllByRecruitId(Long recruitId); + + Optional findByIdAndRecruitId(Long recruitScheduleId, Long recruitId); } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java new file mode 100644 index 0000000..03d7522 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java @@ -0,0 +1,5 @@ +package com.server.bbo_gak.domain.recruit.dto.request; + +public record RecruitScheduleUpdateDeadLineRequest(String deadLine) { + +} diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java new file mode 100644 index 0000000..8735bc4 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java @@ -0,0 +1,5 @@ +package com.server.bbo_gak.domain.recruit.dto.request; + +public record RecruitScheduleUpdateStageRequest(String stage) { + +} diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java index 3f61d6a..d3e55bd 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java @@ -62,4 +62,12 @@ public void setRecruit(Recruit recruit) { this.recruit = recruit; } + public void updateRecruitScheduleStage(String stage) { + this.recruitScheduleStage = RecruitScheduleStage.findByValue(stage); + } + + public void updateDeadLine(String deadLine) { + this.deadLine = LocalDate.parse(deadLine); + } + } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java index 9a44987..e404093 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java @@ -14,7 +14,10 @@ public interface RecruitScheduleService { List getRecruitScheduleList(Long recruitId); - void updateRecruitSchedule(); + void updateRecruitScheduleStage(Long recruitId, Long recruitScheduleId, String stage); + + void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLine); + void deleteRecruitSchedule(); } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java index ccdd1a0..7f1d196 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -25,11 +26,25 @@ public void deleteRecruitSchedule() { } - @Override - public void updateRecruitSchedule() { + @Transactional + public void updateRecruitScheduleStage(Long recruitId, Long recruitScheduleId, String stage) { + RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId( + recruitScheduleId, recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_NOT_FOUND)); + recruitSchedule.updateRecruitScheduleStage(stage); } + @Transactional + public void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLine){ + RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId( + recruitScheduleId, recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_NOT_FOUND)); + + recruitSchedule.updateDeadLine(deadLine); + } + + @Override public List getRecruitScheduleList(Long recruitId) { return recruitScheduleRepository.findAllByRecruitId(recruitId).stream() diff --git a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java index 26ddeb2..08fc3e2 100644 --- a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java +++ b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java @@ -54,6 +54,8 @@ public enum ErrorCode { RECRUIT_STATUS_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고 지원 상태를 찾을 수 없습니다"), RECRUIT_SCHEDULE_STAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고 일정 단계를 찾을 수 없습니다"), + //RecruitSchedule + RECRUIT_SCHEDULE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고일정을 찾을 수 없습니다"), CARD_TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 카드와 태그 매핑을 찾을 수 없습니다"), diff --git a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java new file mode 100644 index 0000000..374cec8 --- /dev/null +++ b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java @@ -0,0 +1,75 @@ +package com.server.bbo_gak.domain.recruit.controller; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; +import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; +import com.server.bbo_gak.global.AbstractRestDocsTests; +import com.server.bbo_gak.global.RestDocsFactory; +import java.util.List; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@SpringBootTest +@ActiveProfiles("test") +@Sql({"/all-data-delete.sql", "/recruit-test-data.sql"}) +class RecruitScheduleControllerTest extends AbstractRestDocsTests { + + private static final String DEFAULT_URL = "/api/v1/recruits/{id}/recruit-schedule"; + + @Autowired + private RestDocsFactory restDocsFactory; + + @Nested + class 공고일정_생성 { + + @Test + public void 성공() throws Exception { + RecruitScheduleCreateRequest request = new RecruitScheduleCreateRequest( + "1차 면접", + "2024-08-31" + ); + + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL, request, HttpMethod.POST, objectMapper, 1L)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[POST] 공고일정 생성 성공", "공고일정 생성", "RecruitSchedule", request, null)); + } + } + + @Nested + class 공고일정_전체조회 { + + // 첫 번째 response 객체 + RecruitScheduleGetResponse response1 = RecruitScheduleGetResponse.builder() + .id(1L) + .recruitScheduleStage(RecruitScheduleStage.CLOSING_DOCUMENT.getValue()) + .deadLine("2025-01-01T00:00:00") + .build(); + + // 두 번째 response 객체 + RecruitScheduleGetResponse response2 = RecruitScheduleGetResponse.builder() + .id(2L) + .recruitScheduleStage(RecruitScheduleStage.FIRST_INTERVIEW.getValue()) + .deadLine("2025-02-01T00:00:00") + .build(); + + @Test + public void 성공() throws Exception { + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL, null, HttpMethod.GET, objectMapper, 1L)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResourceList("[GET] 공고일정 전체 조회 성공", "공고일정 전체 조회 ", "RecruitSchedule", List.of(), + List.of(response1, response2))); + } + + } +} \ No newline at end of file From 12d9ead0b904ec3995ea958f56bffb9bdbfee6e2 Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 18:27:05 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[feat][#56]=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20-=20=EA=B3=B5=EA=B3=A0=EB=8B=A8=EA=B3=84?= =?UTF-8?q?=20&=20=EB=A7=88=EA=B0=90=EC=9D=BC=20=EC=88=98=EC=A0=95=20Contr?= =?UTF-8?q?ollerTest=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecruitScheduleControllerTest.java | 34 ++++++++++- .../resources/recruit-schedule-test-data.sql | 59 +++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/recruit-schedule-test-data.sql diff --git a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java index 374cec8..765ab15 100644 --- a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java @@ -3,6 +3,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleCreateRequest; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateDeadLineRequest; +import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateStageRequest; import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; import com.server.bbo_gak.global.AbstractRestDocsTests; @@ -20,7 +22,7 @@ @Transactional @SpringBootTest @ActiveProfiles("test") -@Sql({"/all-data-delete.sql", "/recruit-test-data.sql"}) +@Sql({"/all-data-delete.sql", "/recruit-schedule-test-data.sql"}) class RecruitScheduleControllerTest extends AbstractRestDocsTests { private static final String DEFAULT_URL = "/api/v1/recruits/{id}/recruit-schedule"; @@ -70,6 +72,36 @@ class 공고일정_전체조회 { .andDo(restDocsFactory.getSuccessResourceList("[GET] 공고일정 전체 조회 성공", "공고일정 전체 조회 ", "RecruitSchedule", List.of(), List.of(response1, response2))); } + } + + @Nested + class 공고일정_공고단계_업데이트 { + @Test + public void 성공() throws Exception { + RecruitScheduleUpdateStageRequest request = new RecruitScheduleUpdateStageRequest( + "2차 면접" + ); + + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL+"/{recruit-schedule-id}/stage", request, HttpMethod.PUT, objectMapper, 1L, 1L)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[PUT] 공고단계 업데이트 성공", "공고단계 업데이트", "RecruitSchedule", request, null)); + } + } + + @Nested + class 공고일정_마감일_업데이트 { + @Test + public void 성공() throws Exception { + RecruitScheduleUpdateDeadLineRequest request = new RecruitScheduleUpdateDeadLineRequest( + "2024-12-25" + ); + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL+"/{recruit-schedule-id}/deadLine", request, HttpMethod.PUT, objectMapper, 1L, 1L)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[PUT] 공고마감일 업데이트 성공", "공고마감일 업데이트", "RecruitSchedule", request, null)); + } } + } \ No newline at end of file diff --git a/src/test/resources/recruit-schedule-test-data.sql b/src/test/resources/recruit-schedule-test-data.sql new file mode 100644 index 0000000..8f4176b --- /dev/null +++ b/src/test/resources/recruit-schedule-test-data.sql @@ -0,0 +1,59 @@ +INSERT INTO users (deleted, created_at, update_at, user_id, dtype, email, login_id, name, password, role) +VALUES (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 1, 'AuthTestUser', 'test', 'test', 'test', + 'test', 'USER'), + (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 2, 'AuthTestUser', 'test', 'test', 'test', + 'test', 'USER'), + (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 3, 'AuthTestUser', 'test', 'test', 'test', + 'test', 'USER') +; + +-- Season 테이블에 데이터 삽입 +INSERT INTO recruit_season (recruit_season_id, name, user_id, deleted, update_at, created_at) +VALUES (1, '2024 상반기', 1, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000'), + (2, '2024 하반기', 1, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000'), + (3, '2024 상반기', 2, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000'), + (4, '2024 하반기', 2, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000'), + (5, '2024 상반기', 3, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000'), + (6, '2024 하반기', 3, false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000') +; + +-- Recruit 테이블에 데이터 삽입 +INSERT INTO recruit (recruit_id, title, site_url, recruit_status, recruit_season_id, user_id, created_at, update_at, + deleted) +VALUES (1, 'Title for one day left', 'http://example.com/1', 'DOCUMENT_PASSED', 1, 1, CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, false), + (2, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 2, 1, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false), + (3, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 3, 2, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false), + (4, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 3, 2, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false), + (5, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 4, 2, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false), + (6, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 5, 3, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false), + (7, 'Title for more than one day left', 'http://example.com/2', 'PREPARATION_IN_PROGRESS', 6, 3, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, false) +; + +-- RecruitSchedule 테이블에 데이터 삽입 +INSERT INTO recruit_schedule (recruit_schedule_id, recruit_id, recruit_schedule_stage, dead_line, deleted, update_at, created_at) +VALUES (1, 1, 'FIRST_INTERVIEW', TIMESTAMPADD(DAY, 3, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (2, 4, 'FIRST_INTERVIEW', TIMESTAMPADD(DAY, 3, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (3, 5, 'FIRST_INTERVIEW', TIMESTAMPADD(DAY, 1, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (4, 6, 'FIRST_INTERVIEW', TIMESTAMPADD(DAY, 2, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (5, 6, 'SECOND_INTERVIEW', TIMESTAMPADD(DAY, 3, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (6, 7, 'FIRST_INTERVIEW', TIMESTAMPADD(DAY, -2, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (7, 7, 'SECOND_INTERVIEW', TIMESTAMPADD(DAY, -1, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000'), + (8, 7, 'FINAL_INTERVIEW', TIMESTAMPADD(DAY, 1, CURRENT_TIMESTAMP), false, '2024-07-24 21:26:28.000000', '2024-07-24 21:26:28.000000') +; + +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, false, '2024-07-24 21:22:04.000000', 1, '2024-07-24 21:22:07.000000', '2024-07-24 21:22:08.000000', 1, + 'test_contents', 'test_title', 1); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, false, '1970-01-01 00:00:00.001000', 2, '1970-01-01 00:00:00.001000', '1970-01-01 00:00:00.001000', 1, + 'testc', 'testc', 1); +INSERT INTO card (deleted, copy_flag, access_time, card_id, created_at, update_at, user_id, content, title, recruit_id) +VALUES (false, false, '1970-01-01 00:00:00.001000', 3, '1970-01-01 00:00:00.001000', '1970-01-01 00:00:00.001000', 1, + 'testc', 'testt', 1); \ No newline at end of file From 4ba72a1343771596165c744e40b043f7c5e5aabf Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 18:42:10 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[feat][#56]=20=EA=B3=B5=EA=B3=A0=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20-=20=EC=82=AD=EC=A0=9C=20api=20&=20Control?= =?UTF-8?q?lerTest=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecruitScheduleController.java | 12 +++++++ .../service/RecruitScheduleService.java | 3 +- .../service/RecruitScheduleServiceImpl.java | 34 ++++++++++++------- .../RecruitScheduleControllerTest.java | 12 +++++++ 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java index d791029..dd34654 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java @@ -64,4 +64,16 @@ public ResponseEntity updateDeadLine( recruitScheduleService.updateDeadLine(id, recruitScheduleId, request.deadLine()); return ResponseEntity.ok().body(null); } + + /** + * 공고 일정 삭제 + */ + @DeleteMapping("/{recruit-schedule-id}") + public ResponseEntity deleteRecruitSchedule( + @PathVariable("id") Long id, //공고 id + @PathVariable("recruit-schedule-id") Long recruitScheduleId + ) { + recruitScheduleService.deleteRecruitSchedule(id, recruitScheduleId); + return ResponseEntity.ok().body(null); + } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java index e404093..8c80311 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleService.java @@ -18,6 +18,5 @@ public interface RecruitScheduleService { void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLine); - - void deleteRecruitSchedule(); + void deleteRecruitSchedule(Long recruitId, Long recruitScheduleId); } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java index 7f1d196..ff4d8d8 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java @@ -22,10 +22,22 @@ public class RecruitScheduleServiceImpl implements RecruitScheduleService { private final RecruitRepository recruitRepository; @Override - public void deleteRecruitSchedule() { - + @Transactional + public RecruitSchedule createRecruitSchedule(Long id, RecruitScheduleCreateRequest request) { + Recruit recruit = recruitRepository.findById(id) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); + return recruitScheduleRepository.save(RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline())); + } + + @Override + @Transactional + public List getRecruitScheduleList(Long recruitId) { + return recruitScheduleRepository.findAllByRecruitId(recruitId).stream() + .map(RecruitScheduleGetResponse::from) + .toList(); } + @Override @Transactional public void updateRecruitScheduleStage(Long recruitId, Long recruitScheduleId, String stage) { RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId( @@ -35,6 +47,7 @@ public void updateRecruitScheduleStage(Long recruitId, Long recruitScheduleId, S recruitSchedule.updateRecruitScheduleStage(stage); } + @Override @Transactional public void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLine){ RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId( @@ -44,18 +57,13 @@ public void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLi recruitSchedule.updateDeadLine(deadLine); } - @Override - public List getRecruitScheduleList(Long recruitId) { - return recruitScheduleRepository.findAllByRecruitId(recruitId).stream() - .map(RecruitScheduleGetResponse::from) - .toList(); - } + @Transactional + public void deleteRecruitSchedule(Long recruitId, Long recruitScheduleId) { + RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId( + recruitScheduleId, recruitId) + .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_NOT_FOUND)); - @Override - public RecruitSchedule createRecruitSchedule(Long id, RecruitScheduleCreateRequest request) { - Recruit recruit = recruitRepository.findById(id) - .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); - return recruitScheduleRepository.save(RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline())); + recruitScheduleRepository.deleteById(recruitSchedule.getId()); } } diff --git a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java index 765ab15..1b4485c 100644 --- a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleControllerTest.java @@ -104,4 +104,16 @@ class 공고일정_마감일_업데이트 { } } + @Nested + class 공고일정_삭제 { + + @Test + public void 성공() throws Exception { + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL+"/{recruit-schedule-id}", null, HttpMethod.DELETE, objectMapper, 1L, 1L)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[DELETE] 공고일정 삭제 성공", "공고일정 삭제", "RecruitSchedule", null, null)); + } + } + } \ No newline at end of file From f7d506c86d43857341a3962223176f05fb96781b Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 19:51:00 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[feat][#56]=20deadline=20->=20deadLine?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/service/NotificationScheduler.java | 4 ++-- .../domain/recruit/dto/request/RecruitCreateRequest.java | 2 +- .../recruit/dto/request/RecruitScheduleCreateRequest.java | 6 +++--- .../domain/recruit/service/RecruitScheduleServiceImpl.java | 2 +- .../bbo_gak/domain/recruit/service/RecruitService.java | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/server/bbo_gak/domain/notification/service/NotificationScheduler.java b/src/main/java/com/server/bbo_gak/domain/notification/service/NotificationScheduler.java index e441867..3fab08b 100644 --- a/src/main/java/com/server/bbo_gak/domain/notification/service/NotificationScheduler.java +++ b/src/main/java/com/server/bbo_gak/domain/notification/service/NotificationScheduler.java @@ -65,8 +65,8 @@ private List> getRecruitAndScheduleMaps(List createNotifications(List> recruitsWithOneDayLeft) { diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java index 82d0962..a07f655 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java @@ -10,7 +10,7 @@ public record RecruitCreateRequest( String title, String siteUrl, String recruitScheduleStage, - String deadline + String deadLine ) { public Recruit toEntity(User user, Season season) { diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java index 0117916..99a9053 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleCreateRequest.java @@ -5,13 +5,13 @@ @Builder public record RecruitScheduleCreateRequest( String recruitScheduleStage, - String deadline + String deadLine ) { - public static RecruitScheduleCreateRequest of(String recruitScheduleStage, String deadline) { + public static RecruitScheduleCreateRequest of(String recruitScheduleStage, String deadLine) { return RecruitScheduleCreateRequest.builder() .recruitScheduleStage(recruitScheduleStage) - .deadline(deadline) + .deadLine(deadLine) .build(); } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java index ff4d8d8..1d019e5 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitScheduleServiceImpl.java @@ -26,7 +26,7 @@ public class RecruitScheduleServiceImpl implements RecruitScheduleService { public RecruitSchedule createRecruitSchedule(Long id, RecruitScheduleCreateRequest request) { Recruit recruit = recruitRepository.findById(id) .orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_NOT_FOUND)); - return recruitScheduleRepository.save(RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline())); + return recruitScheduleRepository.save(RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadLine())); } @Override diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java index 820bdb9..a49504b 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java @@ -113,11 +113,11 @@ public RecruitGetResponse createRecruit(User user, RecruitCreateRequest request) } private void addRecruitScheduleIfRequired(RecruitCreateRequest request, Recruit recruit) { - if (request.deadline() != null && !request.deadline().isEmpty()) { + if (request.deadLine() != null && !request.deadLine().isEmpty()) { RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( recruit.getId(), RecruitScheduleCreateRequest.of( - request.recruitScheduleStage(), request.deadline()) + request.recruitScheduleStage(), request.deadLine()) ); recruit.addSchedule(recruitSchedule); } From 35abc7c72a5ffabd63c57295e13ee636162bb0aa Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 19:51:39 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[fix][#56]=20todo=20=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/RecruitScheduleUpdateDeadLineRequest.java | 1 + .../dto/request/RecruitScheduleUpdateStageRequest.java | 4 +++- .../server/bbo_gak/domain/recruit/entity/RecruitSchedule.java | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java index 03d7522..7f30e6d 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateDeadLineRequest.java @@ -1,5 +1,6 @@ package com.server.bbo_gak.domain.recruit.dto.request; +//TODO: deadLine null값 안들어오게 처리하기 public record RecruitScheduleUpdateDeadLineRequest(String deadLine) { } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java index 8735bc4..327f752 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitScheduleUpdateStageRequest.java @@ -1,5 +1,7 @@ package com.server.bbo_gak.domain.recruit.dto.request; -public record RecruitScheduleUpdateStageRequest(String stage) { + +//TODO: recruitScheduleStage null값 안들어오게 처리하기 +public record RecruitScheduleUpdateStageRequest(String recruitScheduleStage) { } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java index d3e55bd..1f3f1d6 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitSchedule.java @@ -67,6 +67,7 @@ public void updateRecruitScheduleStage(String stage) { } public void updateDeadLine(String deadLine) { + // TODO: date 유효성 검사해서 이상한 날짜면 에러 리턴 this.deadLine = LocalDate.parse(deadLine); } From 26103e41921dfa283ce99110399de67e9b272704 Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 25 Aug 2024 19:51:49 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[fix][#56]=20=EA=B3=B5=EA=B3=A0=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=EB=A6=AC=ED=84=B4?= =?UTF-8?q?=EA=B0=92=20=EC=A3=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/controller/RecruitScheduleController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java index dd34654..6f477b9 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/controller/RecruitScheduleController.java @@ -4,6 +4,7 @@ import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateDeadLineRequest; import com.server.bbo_gak.domain.recruit.dto.request.RecruitScheduleUpdateStageRequest; import com.server.bbo_gak.domain.recruit.dto.response.RecruitScheduleGetResponse; +import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; import com.server.bbo_gak.domain.recruit.service.RecruitScheduleService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -22,11 +23,11 @@ public class RecruitScheduleController { * 공고 일정 생성 */ @PostMapping("") - public ResponseEntity createRecruitSchedule( + public ResponseEntity createRecruitSchedule( @PathVariable("id") Long id, //공고 id @RequestBody RecruitScheduleCreateRequest request) { - recruitScheduleService.createRecruitSchedule(id, request); - return ResponseEntity.ok().body(null); + RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule(id, request); + return ResponseEntity.ok().body(RecruitScheduleGetResponse.from(recruitSchedule)); } /** @@ -48,7 +49,7 @@ public ResponseEntity updateRecruitScheduleStage( @PathVariable("recruit-schedule-id") Long recruitScheduleId, @RequestBody RecruitScheduleUpdateStageRequest request ) { - recruitScheduleService.updateRecruitScheduleStage(id, recruitScheduleId, request.stage()); + recruitScheduleService.updateRecruitScheduleStage(id, recruitScheduleId, request.recruitScheduleStage()); return ResponseEntity.ok().body(null); }