38 lines
950 B
Java
38 lines
950 B
Java
package de.ph87.homeautomation.schedule;
|
|
|
|
import de.ph87.homeautomation.web.NotFoundException;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Service
|
|
@Transactional
|
|
@RequiredArgsConstructor
|
|
public class ScheduleReader {
|
|
|
|
private final ScheduleRepository scheduleRepository;
|
|
|
|
private final ScheduleMapper scheduleMapper;
|
|
|
|
public Schedule getById(final long id) {
|
|
return scheduleRepository.findById(id).orElseThrow(() -> new NotFoundException("Schedule.id=%d", id));
|
|
}
|
|
|
|
public List<Schedule> findAll() {
|
|
return scheduleRepository.findAll();
|
|
}
|
|
|
|
public List<ScheduleDto> findAllDtos() {
|
|
return findAll().stream().map(scheduleMapper::toDto).toList();
|
|
}
|
|
|
|
public ScheduleDto getDtoById(final long id) {
|
|
return scheduleMapper.toDto(getById(id));
|
|
}
|
|
|
|
}
|