From f1e4a68ec3db89e06eb0451d66cf852d38b82c69 Mon Sep 17 00:00:00 2001 From: lee-june-young Date: Sun, 18 Aug 2024 18:47:05 +0900 Subject: [PATCH] =?UTF-8?q?[feat][#56]=20RecruitScheduleServiceImpl?= =?UTF-8?q?=EC=9D=98=20createRrcruitSchedule=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/RecruitCreateRequest.java | 6 ++---- .../domain/recruit/entity/RecruitSchedule.java | 8 ++++++++ .../service/RecruitScheduleServiceImpl.java | 7 ++++++- .../domain/recruit/service/RecruitService.java | 18 +++++++++++++----- 4 files changed, 29 insertions(+), 10 deletions(-) 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 81f385f..f838f19 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 @@ -1,7 +1,6 @@ package com.server.bbo_gak.domain.recruit.dto.request; 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.Season; @@ -15,15 +14,14 @@ public record RecruitCreateRequest( String deadline ) { - public Recruit toEntity(User user, Season season, RecruitSchedule schedule) { + public Recruit toEntity(User user, Season season) { return Recruit.builder() .season(season) .title(title) .siteUrl(siteUrl) .recruitStatus(RecruitStatus.APPLICATION_COMPLETED) .user(user) - .build() - .addSchedule(schedule); + .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 9dfa04c..5ab1a38 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 @@ -45,4 +45,12 @@ public RecruitSchedule(Recruit recruit, RecruitScheduleStage recruitScheduleStag public void setRecruit(Recruit recruit) { this.recruit = recruit; } + + public static RecruitSchedule of(Recruit recruit, RecruitScheduleStage recruitScheduleStage, String deadLine){ + return RecruitSchedule.builder() + .recruit(recruit) + .recruitScheduleStage(recruitScheduleStage) + .deadLine(LocalDate.parse(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 6feaf5d..04cc0de 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,11 +1,16 @@ package com.server.bbo_gak.domain.recruit.service; +import com.server.bbo_gak.domain.recruit.dao.RecruitScheduleRepository; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class RecruitScheduleServiceImpl implements RecruitScheduleService { + private final RecruitScheduleRepository recruitScheduleRepository; + @Override public void deleteRecruitSchedule() { @@ -23,6 +28,6 @@ public void getRecruitScheduleList() { @Override public RecruitSchedule createRecruitSchedule(RecruitSchedule recruitSchedule) { - return null; + return recruitScheduleRepository.save(recruitSchedule); } } 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 a1d243b..bfc029f 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 @@ -3,7 +3,6 @@ import com.server.bbo_gak.domain.card.entity.CardType; 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; @@ -93,12 +92,21 @@ private boolean isNeedsScheduleUpdate(Recruit 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); + + // 공고 일정 생성 RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( - RecruitScheduleCreateRequest.of(request.recruitScheduleStage(), request.deadline()) + RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline()) ); - Season season = seasonService.getSeasonByName(user, request.season()); - Recruit recruit = request.toEntity(user, season, recruitSchedule); - return RecruitGetResponse.from(recruitRepository.save(recruit)); + + // 공고에 공고 일정을 설정 + savedRecruit.addSchedule(recruitSchedule); + recruitRepository.save(recruit); + + return RecruitGetResponse.from(savedRecruit); } @Transactional