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 16230c4..2a7985f 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,7 +2,6 @@ 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; @@ -92,12 +91,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