Skip to content

Commit

Permalink
add :: ChangePendingToNowService 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Umjiseung committed Apr 21, 2024
1 parent ea366c8 commit 9231ad7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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();
}
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);
}
}

0 comments on commit 9231ad7

Please sign in to comment.