41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
package de.ph87.homeautomation.schedule;
|
|
|
|
import de.ph87.homeautomation.schedule.astro.AstroDto;
|
|
import de.ph87.homeautomation.schedule.astro.AstroService;
|
|
import de.ph87.homeautomation.schedule.entry.ScheduleEntryDto;
|
|
import de.ph87.homeautomation.schedule.entry.ScheduleEntryMapper;
|
|
import de.ph87.homeautomation.web.WebSocketService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Slf4j
|
|
@Service
|
|
@Transactional
|
|
@RequiredArgsConstructor
|
|
public class ScheduleMapper {
|
|
|
|
private final ScheduleEntryMapper scheduleEntryMapper;
|
|
|
|
private final WebSocketService webSocketService;
|
|
|
|
private final AstroService astroService;
|
|
|
|
public ScheduleDto toDto(final Schedule schedule) {
|
|
final Set<ScheduleEntryDto> entries = schedule.getEntries().stream().map(scheduleEntryMapper::toDto).collect(Collectors.toSet());
|
|
final List<AstroDto> astros = astroService.findAllNext();
|
|
return new ScheduleDto(schedule, entries, astros);
|
|
}
|
|
|
|
public void publish(final Schedule schedule, final boolean existing) {
|
|
final ScheduleDto dto = toDto(schedule);
|
|
webSocketService.send(ScheduleDto.class, dto, existing);
|
|
}
|
|
|
|
}
|