Skip to content

Commit

Permalink
Merge pull request #86 from depromeet/develop
Browse files Browse the repository at this point in the history
feat 56 develop merge
  • Loading branch information
sejoon00 authored Aug 26, 2024
2 parents 1cd97ca + 76e91bb commit 79c6cb6
Show file tree
Hide file tree
Showing 14 changed files with 484 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private List<Entry<Recruit, RecruitSchedule>> getRecruitAndScheduleMaps(List<Rec

private boolean isDeadlineWithinOneDay(RecruitSchedule schedule) {
LocalDate now = LocalDate.now();
LocalDate deadline = schedule.getDeadLine();
return (deadline.equals(now) || deadline.equals(now.plusDays(1)));
LocalDate deadLine = schedule.getDeadLine();
return (deadLine.equals(now) || deadLine.equals(now.plusDays(1)));
}

private List<Notification> createNotifications(List<Entry<Recruit, RecruitSchedule>> recruitsWithOneDayLeft) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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.entity.RecruitSchedule;
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<RecruitScheduleGetResponse> createRecruitSchedule(
@PathVariable("id") Long id, //공고 id
@RequestBody RecruitScheduleCreateRequest request) {
RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule(id, request);
return ResponseEntity.ok().body(RecruitScheduleGetResponse.from(recruitSchedule));
}

/**
* 공고 일정 전체 조회
*/
@GetMapping("")
public ResponseEntity<List<RecruitScheduleGetResponse>> getRecruitScheduleList(
@PathVariable("id") Long id //공고 id
) {
return ResponseEntity.ok().body(recruitScheduleService.getRecruitScheduleList(id));
}

/**
* 공고 일정 (공고단계) 업데이트
*/
@PutMapping("/{recruit-schedule-id}/stage")
public ResponseEntity<Void> updateRecruitScheduleStage(
@PathVariable("id") Long id, //공고 id
@PathVariable("recruit-schedule-id") Long recruitScheduleId,
@RequestBody RecruitScheduleUpdateStageRequest request
) {
recruitScheduleService.updateRecruitScheduleStage(id, recruitScheduleId, request.recruitScheduleStage());
return ResponseEntity.ok().body(null);
}

/**
* 공고 일정 (공고 마감일) 업데이트
*/
@PutMapping("/{recruit-schedule-id}/deadLine")
public ResponseEntity<Void> 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);
}

/**
* 공고 일정 삭제
*/
@DeleteMapping("/{recruit-schedule-id}")
public ResponseEntity<Void> deleteRecruitSchedule(
@PathVariable("id") Long id, //공고 id
@PathVariable("recruit-schedule-id") Long recruitScheduleId
) {
recruitScheduleService.deleteRecruitSchedule(id, recruitScheduleId);
return ResponseEntity.ok().body(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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<RecruitSchedule, Long> {

List<RecruitSchedule> findAllByDeadLineBetween(LocalDate now, LocalDate nowPlusOneDay);

List<RecruitSchedule> findAllByRecruitId(Long recruitId);

Optional<RecruitSchedule> findByIdAndRecruitId(Long recruitScheduleId, Long recruitId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record RecruitCreateRequest(
String title,
String siteUrl,
String recruitScheduleStage,
String deadline
String deadLine
) {

public Recruit toEntity(User user, Season season) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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
String recruitScheduleStage,
String deadLine
) {

public static RecruitSchedule of(RecruitScheduleStage recruitScheduleStage, String deadline) {
return RecruitSchedule.builder()
public static RecruitScheduleCreateRequest of(String recruitScheduleStage, String deadLine) {
return RecruitScheduleCreateRequest.builder()
.recruitScheduleStage(recruitScheduleStage)
.deadLine(LocalDate.parse(deadline))
.deadLine(deadLine)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.server.bbo_gak.domain.recruit.dto.request;

//TODO: deadLine null값 안들어오게 처리하기
public record RecruitScheduleUpdateDeadLineRequest(String deadLine) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.server.bbo_gak.domain.recruit.dto.request;


//TODO: recruitScheduleStage null값 안들어오게 처리하기
public record RecruitScheduleUpdateStageRequest(String recruitScheduleStage) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -62,4 +62,13 @@ public void setRecruit(Recruit recruit) {
this.recruit = recruit;
}

public void updateRecruitScheduleStage(String stage) {
this.recruitScheduleStage = RecruitScheduleStage.findByValue(stage);
}

public void updateDeadLine(String deadLine) {
// TODO: date 유효성 검사해서 이상한 날짜면 에러 리턴
this.deadLine = LocalDate.parse(deadLine);
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
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);

List<RecruitScheduleGetResponse> getRecruitScheduleList(Long recruitId);

void getRecruitScheduleList();
void updateRecruitScheduleStage(Long recruitId, Long recruitScheduleId, String stage);

void updateRecruitSchedule();
void updateDeadLine(Long recruitId, Long recruitScheduleId, String deadLine);

void deleteRecruitSchedule();
void deleteRecruitSchedule(Long recruitId, Long recruitScheduleId);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
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;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class RecruitScheduleServiceImpl implements RecruitScheduleService {

private final RecruitScheduleRepository recruitScheduleRepository;
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
public void updateRecruitSchedule() {
@Transactional
public List<RecruitScheduleGetResponse> 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(
recruitScheduleId, recruitId)
.orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_NOT_FOUND));

recruitSchedule.updateRecruitScheduleStage(stage);
}

@Override
public void getRecruitScheduleList() {
@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 RecruitSchedule createRecruitSchedule(RecruitSchedule recruitSchedule) {
return recruitScheduleRepository.save(recruitSchedule);
@Transactional
public void deleteRecruitSchedule(Long recruitId, Long recruitScheduleId) {
RecruitSchedule recruitSchedule = recruitScheduleRepository.findByIdAndRecruitId(
recruitScheduleId, recruitId)
.orElseThrow(() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_NOT_FOUND));

recruitScheduleRepository.deleteById(recruitSchedule.getId());
}
}
Loading

0 comments on commit 79c6cb6

Please sign in to comment.