ScheduleController::findAll
This commit is contained in:
parent
25d78dc32a
commit
f67a0497cb
@ -44,10 +44,10 @@ public class KnxGroup {
|
|||||||
private int readInterval;
|
private int readInterval;
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
private ComInfo read = new ComInfo();
|
private KnxGroupLinkInfo read = new KnxGroupLinkInfo();
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
private ComInfo send = new ComInfo();
|
private KnxGroupLinkInfo send = new KnxGroupLinkInfo();
|
||||||
|
|
||||||
public void setAddress(final int rawAddress) {
|
public void setAddress(final int rawAddress) {
|
||||||
setAddress(new GroupAddress(rawAddress));
|
setAddress(new GroupAddress(rawAddress));
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import java.time.ZonedDateTime;
|
|||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class ComInfo {
|
public class KnxGroupLinkInfo {
|
||||||
|
|
||||||
private boolean able = true;
|
private boolean able = true;
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ public class KnxGroupLinkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ZonedDateTime getNextTimestamp() {
|
public ZonedDateTime getNextTimestamp() {
|
||||||
final Optional<ZonedDateTime> sendOptional = knxGroupRepository.findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc().map(KnxGroup::getSend).map(ComInfo::getNextTimestamp);
|
final Optional<ZonedDateTime> sendOptional = knxGroupRepository.findFirstBySend_NextTimestampNotNullOrderBySend_NextTimestampAsc().map(KnxGroup::getSend).map(KnxGroupLinkInfo::getNextTimestamp);
|
||||||
final Optional<ZonedDateTime> readOptional = knxGroupRepository.findFirstByRead_NextTimestampNotNullOrderByRead_NextTimestampAsc().map(KnxGroup::getRead).map(ComInfo::getNextTimestamp);
|
final Optional<ZonedDateTime> readOptional = knxGroupRepository.findFirstByRead_NextTimestampNotNullOrderByRead_NextTimestampAsc().map(KnxGroup::getRead).map(KnxGroupLinkInfo::getNextTimestamp);
|
||||||
if (sendOptional.isEmpty()) {
|
if (sendOptional.isEmpty()) {
|
||||||
return readOptional.orElse(null);
|
return readOptional.orElse(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,9 @@ public class Schedule {
|
|||||||
@Column(nullable = false, unique = true)
|
@Column(nullable = false, unique = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
// TODO move ownership of relation to ScheduleEntry ???
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||||
private Set<ScheduleEntry> entries = new HashSet<>();
|
private Set<ScheduleEntry> entries = new HashSet<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
package de.ph87.homeautomation.schedule;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("schedule")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ScheduleController {
|
||||||
|
|
||||||
|
private final ScheduleRepository scheduleRepository;
|
||||||
|
|
||||||
|
@GetMapping("findAll")
|
||||||
|
public List<ScheduleDto> findAll() {
|
||||||
|
return scheduleRepository.findAll().stream().map(ScheduleDto::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package de.ph87.homeautomation.schedule;
|
||||||
|
|
||||||
|
import de.ph87.homeautomation.schedule.entry.ScheduleEntryDto;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ScheduleDto {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Set<ScheduleEntryDto> entries;
|
||||||
|
|
||||||
|
public ScheduleDto(final Schedule schedule) {
|
||||||
|
id = schedule.getId();
|
||||||
|
enabled = schedule.isEnabled();
|
||||||
|
name = schedule.getName();
|
||||||
|
entries = schedule.getEntries().stream().map(ScheduleEntryDto::new).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -49,7 +49,7 @@ public class ScheduleEntry {
|
|||||||
|
|
||||||
private ZonedDateTime nextDateTime;
|
private ZonedDateTime nextDateTime;
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
private Map<String, String> properties = new HashMap<>();
|
private Map<String, String> properties = new HashMap<>();
|
||||||
|
|
||||||
public void setWorkday(final boolean enabled) {
|
public void setWorkday(final boolean enabled) {
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
package de.ph87.homeautomation.schedule.entry;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ScheduleEntryDto {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
private boolean monday;
|
||||||
|
|
||||||
|
private boolean tuesday;
|
||||||
|
|
||||||
|
private boolean wednesday;
|
||||||
|
|
||||||
|
private boolean thursday;
|
||||||
|
|
||||||
|
private boolean friday;
|
||||||
|
|
||||||
|
private boolean saturday;
|
||||||
|
|
||||||
|
private boolean sunday;
|
||||||
|
|
||||||
|
private ScheduleEntryType type;
|
||||||
|
|
||||||
|
private double zenith;
|
||||||
|
|
||||||
|
private int hour;
|
||||||
|
|
||||||
|
private int minute;
|
||||||
|
|
||||||
|
private int second;
|
||||||
|
|
||||||
|
private ZonedDateTime nextDateTime;
|
||||||
|
|
||||||
|
private Map<String, String> properties;
|
||||||
|
|
||||||
|
public ScheduleEntryDto(final ScheduleEntry scheduleEntry) {
|
||||||
|
id = scheduleEntry.getId();
|
||||||
|
enabled = scheduleEntry.isEnabled();
|
||||||
|
monday = scheduleEntry.isMonday();
|
||||||
|
tuesday = scheduleEntry.isTuesday();
|
||||||
|
wednesday = scheduleEntry.isWednesday();
|
||||||
|
thursday = scheduleEntry.isThursday();
|
||||||
|
friday = scheduleEntry.isFriday();
|
||||||
|
saturday = scheduleEntry.isSaturday();
|
||||||
|
sunday = scheduleEntry.isSunday();
|
||||||
|
type = scheduleEntry.getType();
|
||||||
|
zenith = scheduleEntry.getZenith();
|
||||||
|
hour = scheduleEntry.getHour();
|
||||||
|
minute = scheduleEntry.getMinute();
|
||||||
|
second = scheduleEntry.getSecond();
|
||||||
|
nextDateTime = scheduleEntry.getNextDateTime();
|
||||||
|
properties = new HashMap<>(scheduleEntry.getProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user