-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Team-MindWay/101-in-progress-not-event-i…
…n-progress-to-event-change-scheduleer 🔀 :: Pending인 이벤트를 Now로 전환시키는 스케줄러 구현
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/com/mindway/server/v2/domain/event/scheduler/EventScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
package com.mindway.server.v2.domain.event.scheduler; | ||
|
||
import com.mindway.server.v2.domain.event.service.ChangeNowToPastService; | ||
import com.mindway.server.v2.domain.event.service.ChangePendingToNowService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
|
||
@RequiredArgsConstructor | ||
public class EventScheduler { | ||
|
||
private final ChangeNowToPastService changeNowToPastService; | ||
private final ChangePendingToNowService changePendingToNowService; | ||
|
||
@Scheduled(cron = "0 0 0 * *", zone = "Asia/Seoul") | ||
public void changeNowToPast() { | ||
changeNowToPastService.execute(); | ||
} | ||
|
||
@Scheduled(cron = "0 0 0 * *", zone = "Asia/Seoul") | ||
public void changePendingToNow() { | ||
changePendingToNowService.execute(); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/mindway/server/v2/domain/event/service/ChangePendingToNowService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.mindway.server.v2.domain.event.service; | ||
|
||
public interface ChangePendingToNowService { | ||
void execute(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/java/com/mindway/server/v2/domain/event/service/impl/ChangePendingToNowServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.mindway.server.v2.domain.event.service.impl; | ||
|
||
import com.mindway.server.v2.domain.event.entity.Event; | ||
import com.mindway.server.v2.domain.event.entity.Status; | ||
import com.mindway.server.v2.domain.event.repository.EventRepository; | ||
import com.mindway.server.v2.domain.event.service.ChangePendingToNowService; | ||
import com.mindway.server.v2.global.annotation.ServiceWithTransaction; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
|
||
@ServiceWithTransaction | ||
@RequiredArgsConstructor | ||
public class ChangePendingToNowServiceImpl implements ChangePendingToNowService { | ||
|
||
private final EventRepository eventRepository; | ||
|
||
public void execute() { | ||
List<Event> pendingEvents = eventRepository.findByStatus(Status.PENDING); | ||
|
||
for (Event event: pendingEvents) { | ||
if (Objects.equals(event.getStarted_at(), LocalDate.now())) { | ||
saveChangeNow(event); | ||
} | ||
} | ||
} | ||
|
||
private void saveChangeNow(Event event) { | ||
event.changeStatus(Status.NOW); | ||
|
||
eventRepository.save(event); | ||
} | ||
} |