fix remove older events
This commit is contained in:
parent
d2ce6d604e
commit
a878f8c22c
@ -17,6 +17,8 @@ import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -103,9 +105,13 @@ public class EventService {
|
||||
}
|
||||
|
||||
public void createFromPaper(Paper newPaper) {
|
||||
createFromPaper(newPaper, Collections.emptyList());
|
||||
}
|
||||
|
||||
public void createFromPaper(Paper newPaper, List<Event> events) {
|
||||
List<Timeline> timelines = timelineService.findAll();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
timeline.getEvents().removeAll(newPaper.getEvents());
|
||||
timeline.getEvents().removeAll(events);
|
||||
for (Deadline deadline : newPaper.getDeadlines()
|
||||
.stream()
|
||||
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
||||
@ -125,8 +131,9 @@ public class EventService {
|
||||
}
|
||||
|
||||
public void updatePaperDeadlines(Paper paper) {
|
||||
eventRepository.delete(eventRepository.findAllByPaper(paper));
|
||||
createFromPaper(paper);
|
||||
List<Event> foundEvents = eventRepository.findAllByPaper(paper);
|
||||
eventRepository.delete(foundEvents);
|
||||
createFromPaper(paper, foundEvents);
|
||||
}
|
||||
|
||||
public List<Event> findByCurrentDate() {
|
||||
|
Loading…
Reference in New Issue
Block a user