property toggle
This commit is contained in:
parent
6e82cc3855
commit
172ee3a337
@ -55,6 +55,20 @@ public class PropertyController implements ISearchController {
|
|||||||
return propertyWriteService.set(id, (p, v) -> p.setWriteChannel(channelService.getById(v)), channelId);
|
return propertyWriteService.set(id, (p, v) -> p.setWriteChannel(channelService.getById(v)), channelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("toggle/{id}")
|
||||||
|
public PropertyDto setValue(@PathVariable final long id) {
|
||||||
|
final boolean oldState = getOldStateBoolean(id, false);
|
||||||
|
return propertyWriteService.set(id, propertyWriteService::writeToChannel, oldState ? 0.0 : 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getOldStateBoolean(final long id, final boolean orElse) {
|
||||||
|
final Double oldValue = propertyReadService.getDtoById(id).getValue();
|
||||||
|
if (oldValue == null || oldValue.isNaN()) {
|
||||||
|
return orElse;
|
||||||
|
}
|
||||||
|
return oldValue > 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GetMapping("getById/{id}")
|
@GetMapping("getById/{id}")
|
||||||
public SearchResult getById(@PathVariable final long id) {
|
public SearchResult getById(@PathVariable final long id) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user