Skip to content

Commit

Permalink
Merge pull request #51 from WE-ARE-RACCOONS/RAC-158
Browse files Browse the repository at this point in the history
RAC-158 feat : ๋งค์ผ ์ž์ • ๊ธฐ๊ฐ„ ์ง€๋‚œ ๋ฉ˜ํ† ๋ง ์‹ ์ฒญ ์ž๋™ ์ทจ์†Œ
  • Loading branch information
ywj9811 authored Nov 21, 2023
2 parents 1e18c6b + 947e44d commit 65f07cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/postgraduate/PostgraduateApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class PostgraduateApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService;
import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException;
import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest;
Expand All @@ -16,9 +16,13 @@
import com.postgraduate.domain.salary.domain.service.SalaryUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.*;
import static com.postgraduate.domain.salary.util.MonthFormat.getMonthFormat;
import static java.time.LocalDate.now;
Expand All @@ -29,6 +33,7 @@
public class MentoringManageUseCase {
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final MentoringUpdateService mentoringUpdateService;
private final MentoringGetService mentoringGetService;
private final RefuseSaveService refuseSaveService;
private final SalaryGetService salaryGetService;
private final SalarySaveService salarySaveService;
Expand Down Expand Up @@ -68,4 +73,14 @@ public void updateExpected(User user, Long mentoringId, MentoringDateRequest dat
mentoringUpdateService.updateDate(mentoring, dateRequest.getDate());
mentoringUpdateService.updateStatus(mentoring, EXPECTED);
}

@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
private void updateCancel() {
LocalDate now = LocalDate.now();
List<Mentoring> mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now);
for (Mentoring mentoring : mentorings) {
mentoringUpdateService.updateStatus(mentoring, CANCEL);
//TODO : ์•Œ๋ฆผ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๋‚˜๋จธ์ง€ ์ž‘์—…
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import com.postgraduate.domain.user.domain.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface MentoringRepository extends JpaRepository<Mentoring, Long> {
Optional<Mentoring> findByMentoringId(Long mentoringId);
Optional<List<Mentoring>> findAllByUserAndStatus(User user, Status status);
Optional<List<Mentoring>> findAllBySeniorAndStatus(Senior senior, Status status);
// Optional<List<Mentoring>> findAllByDeletedAtIsNull();
List<Mentoring> findAllByStatusAndCreatedAtIsBefore(Status status, LocalDate now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -29,7 +30,7 @@ public Mentoring byMentoringId(Long mentoringId) {
return mentoringRepository.findByMentoringId(mentoringId).orElseThrow(MentoringNotFoundException::new);
}

// public List<Mentoring> all() {
// return mentoringRepository.findAllByDeletedAtIsNull().orElse(new ArrayList<>());
// }
public List<Mentoring> byStatusAndCreatedAt(Status status, LocalDate now) {
return mentoringRepository.findAllByStatusAndCreatedAtIsBefore(status, now);
}
}

0 comments on commit 65f07cc

Please sign in to comment.