removed Property.name + UI fixes + Search id fix + Code clean
This commit is contained in:
parent
0534cf0bae
commit
de95a6aed1
@ -5,7 +5,6 @@ export class Property {
|
||||
|
||||
constructor(
|
||||
public id: number,
|
||||
public name: string,
|
||||
public type: string,
|
||||
public title: string,
|
||||
public value: number | null,
|
||||
@ -26,7 +25,6 @@ export class Property {
|
||||
static fromJson(json: any): Property {
|
||||
return new Property(
|
||||
validateNumberNotNull(json['id']),
|
||||
validateStringNotEmptyNotNull(json['name']),
|
||||
validateStringNotEmptyNotNull(json['type']),
|
||||
validateStringNotEmptyNotNull(json['title']),
|
||||
validateNumberAllowNull(json['value']),
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Eigenschaft</th>
|
||||
<td>
|
||||
<app-search [searchService]="propertyService" [initial]="deviceSwitch.stateProperty?.id" [showKey]="true" (valueChange)="deviceService.setDeviceSwitch(device,'stateProperty', $event)"></app-search>
|
||||
<td class="full">
|
||||
<app-search [searchService]="propertyService" [initial]="deviceSwitch.stateProperty?.id" (valueChange)="deviceService.setDeviceSwitch(device,'stateProperty', $event)"></app-search>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -29,14 +29,14 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Status-Eigenschaft</th>
|
||||
<td>
|
||||
<app-search [searchService]="propertyService" [initial]="deviceStateScene.stateProperty?.id" [showKey]="true" (valueChange)="deviceService.setDeviceStateScene(device,'stateProperty', $event)"></app-search>
|
||||
<td class="full">
|
||||
<app-search [searchService]="propertyService" [initial]="deviceStateScene.stateProperty?.id" (valueChange)="deviceService.setDeviceStateScene(device,'stateProperty', $event)"></app-search>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Szene-Eigenschaft</th>
|
||||
<td>
|
||||
<app-search [searchService]="propertyService" [initial]="deviceStateScene.sceneProperty?.id" [showKey]="true" (valueChange)="deviceService.setDeviceStateScene(device,'sceneProperty', $event)"></app-search>
|
||||
<td class="full">
|
||||
<app-search [searchService]="propertyService" [initial]="deviceStateScene.sceneProperty?.id" (valueChange)="deviceService.setDeviceStateScene(device,'sceneProperty', $event)"></app-search>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -52,8 +52,8 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Eigenschaft</th>
|
||||
<td>
|
||||
<app-search [searchService]="propertyService" [initial]="deviceShutter.positionProperty?.id" [showKey]="true" (valueChange)="deviceService.setDeviceShutter(device,'positionProperty', $event)"></app-search>
|
||||
<td class="full">
|
||||
<app-search [searchService]="propertyService" [initial]="deviceShutter.positionProperty?.id" (valueChange)="deviceService.setDeviceShutter(device,'positionProperty', $event)"></app-search>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Bezeichnung</th>
|
||||
<th>Name</th>
|
||||
<th>Typ</th>
|
||||
<th>Wert</th>
|
||||
<th>Zeitstempel</th>
|
||||
@ -17,9 +16,6 @@
|
||||
<td>
|
||||
<app-edit-field [initial]="property.title" (valueChange)="edit(property, 'title', $event)"></app-edit-field>
|
||||
</td>
|
||||
<td>
|
||||
<app-edit-field [initial]="property.name" (valueChange)="edit(property, 'name', $event)"></app-edit-field>
|
||||
</td>
|
||||
<td>
|
||||
<select [(ngModel)]="property.type" (ngModelChange)="edit(property, 'type', property.type)">
|
||||
<option value="BOOLEAN">Schalter</option>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<app-edit-field [initial]="schedule.title" (valueChange)="set(null, 'title', $event)"></app-edit-field>
|
||||
</td>
|
||||
<td colspan="5">
|
||||
<app-search [searchService]="propertyService" [initial]="schedule.property?.id" (valueChange)="set(null, 'propertyName', $event)"></app-search>
|
||||
<app-search [searchService]="propertyService" [initial]="schedule.property?.id" (valueChange)="set(null, 'property', $event)"></app-search>
|
||||
</td>
|
||||
<td colspan="9">
|
||||
{{schedule.property?.type}}
|
||||
|
||||
@ -3,9 +3,6 @@
|
||||
<div class="initial" *ngIf="!searching" (click)="start()" [class.empty]="!selected">
|
||||
<ng-container *ngIf="selected">
|
||||
{{selected.title}}
|
||||
<ng-container *ngIf="showKey">
|
||||
[{{selected.id}}]
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="!selected">-</ng-container>
|
||||
</div>
|
||||
@ -18,15 +15,9 @@
|
||||
</div>
|
||||
<div *ngIf="selected" class="result selected" (mousedown)="dontCancelOnBlur()" (click)="select(selected)">
|
||||
{{selected.title}}
|
||||
<ng-container *ngIf="showKey">
|
||||
[{{selected.id}}]
|
||||
</ng-container>
|
||||
</div>
|
||||
<div *ngFor="let result of results" class="result" (mousedown)="dontCancelOnBlur()" (click)="select(result)">
|
||||
{{result.title}}
|
||||
<ng-container *ngIf="showKey">
|
||||
[{{result.id}}]
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -26,9 +26,6 @@ export class SearchComponent<T> implements OnInit {
|
||||
@Input()
|
||||
initial?: number;
|
||||
|
||||
@Input()
|
||||
showKey: boolean = false;
|
||||
|
||||
@Input()
|
||||
allowEmpty: boolean = true;
|
||||
|
||||
|
||||
@ -49,42 +49,42 @@ public class DemoDataService {
|
||||
private final SceneWriteService sceneWriteService;
|
||||
|
||||
public void insertDemoData() {
|
||||
final Property eg = createProperty("eg.status", PropertyType.BOOLEAN, "Erdgeschoss", knx(0, 4, 2), null);
|
||||
final Property eg_szene = createProperty("eg.szene", PropertyType.SCENE, "Erdgeschoss Szene", null, knx(0, 0, 1));
|
||||
final Property og = createProperty("og.status", PropertyType.BOOLEAN, "Obergeschoss", knx(0, 6, 6), null);
|
||||
final Property og_szene = createProperty("og.szene", PropertyType.SCENE, "Obergeschoss Szene", null, knx(0, 3, 2));
|
||||
final Property erdgeschoss = createProperty("Erdgeschoss", PropertyType.BOOLEAN, knx(0, 4, 2), null);
|
||||
final Property erdgeschoss_szene = createProperty("Erdgeschoss Szene", PropertyType.SCENE, null, knx(0, 0, 1));
|
||||
final Property obergeschoss = createProperty("Obergeschoss", PropertyType.BOOLEAN, knx(0, 6, 6), null);
|
||||
final Property obergeschoss_szene = createProperty("Obergeschoss Szene", PropertyType.SCENE, null, knx(0, 3, 2));
|
||||
|
||||
final Property fernseher = createProperty("fernseher.eg", PropertyType.BOOLEAN, "Fernseher", knx(0, 0, 20), knx(0, 0, 4));
|
||||
final Property verstaerker = createProperty("verstaerker", PropertyType.BOOLEAN, "Verstärker", knx(0, 3, 57), knx(0, 3, 56));
|
||||
final Property garten_steckdosen = createProperty("garten.steckdosen", PropertyType.BOOLEAN, "Garten Steckdosen", knx(0, 4, 12), knx(0, 4, 11));
|
||||
final Property terrasse = createProperty("terrasse", PropertyType.BOOLEAN, "Terrasse Licht", knx(0, 4, 1), knx(0, 4, 0));
|
||||
final Property fernseher = createProperty("Fernseher", PropertyType.BOOLEAN, knx(0, 0, 20), knx(0, 0, 4));
|
||||
final Property verstaerker = createProperty("Verstärker", PropertyType.BOOLEAN, knx(0, 3, 57), knx(0, 3, 56));
|
||||
final Property aussendekoration = createProperty("Außendekoration", PropertyType.BOOLEAN, knx(0, 4, 12), knx(0, 4, 11));
|
||||
final Property terrasse = createProperty("Terrasse Licht", PropertyType.BOOLEAN, knx(0, 4, 1), knx(0, 4, 0));
|
||||
|
||||
final Property ambiente_eg = createProperty("ambiente.eg", PropertyType.BOOLEAN, "Ambiente EG", knx(0, 3, 81), knx(0, 3, 80));
|
||||
final Property ambiente_og = createProperty("ambiente.og", PropertyType.BOOLEAN, "Ambiente OG", knx(0, 6, 2), knx(0, 6, 3));
|
||||
final Property ambiente_eg = createProperty("Ambiente EG", PropertyType.BOOLEAN, knx(0, 3, 81), knx(0, 3, 80));
|
||||
final Property ambiente_og = createProperty("Ambiente OG", PropertyType.BOOLEAN, knx(0, 6, 2), knx(0, 6, 3));
|
||||
|
||||
final Property bad_licht = createProperty("bad.licht", PropertyType.BOOLEAN, "Bad Licht", knx(0, 5, 19), knx(0, 3, 73));
|
||||
final Property flur_eg_licht = createProperty("flur.eg.licht", PropertyType.BOOLEAN, "Flur EG Licht", knx(0, 4, 8), knx(0, 5, 14));
|
||||
final Property bad_licht = createProperty("Bad Licht", PropertyType.BOOLEAN, knx(0, 5, 19), knx(0, 3, 73));
|
||||
final Property flur_eg_licht = createProperty("Flur EG Licht", PropertyType.BOOLEAN, knx(0, 4, 8), knx(0, 5, 14));
|
||||
|
||||
final Property wohnzimmer_rollladen = createProperty("wohnzimmer.rollladen", PropertyType.SHUTTER, "Wohnzimmer Rollladen", null, knx(0, 4, 24));
|
||||
final Property schlafzimmer_rollladen = createProperty("schlafzimmer_rollladen", PropertyType.SHUTTER, "Schlafzimmer Rollladen", null, knx(0, 3, 3));
|
||||
final Property flur_og_rollladen = createProperty("flur_og_rollladen", PropertyType.SHUTTER, "Flur OG Rollladen", null, knx(0, 5, 13));
|
||||
final Property wohnzimmer_rollladen = createProperty("Wohnzimmer Rollladen", PropertyType.SHUTTER, null, knx(0, 4, 24));
|
||||
final Property schlafzimmer_rollladen = createProperty("Schlafzimmer Rollladen", PropertyType.SHUTTER, null, knx(0, 3, 3));
|
||||
final Property flur_og_rollladen = createProperty("Flur OG Rollladen", PropertyType.SHUTTER, null, knx(0, 5, 13));
|
||||
|
||||
final Property helligkeit = createProperty("helligkeit", PropertyType.LUX, "Helligkeit", knx(0, 5, 6), null);
|
||||
final Property szene_haus = createProperty("szene_haus", PropertyType.SCENE, "Szene Haus ", null, knx(0, 0, 21));
|
||||
final Property helligkeit = createProperty("Helligkeit", PropertyType.LUX, knx(0, 5, 6), null);
|
||||
final Property szene_haus = createProperty("Szene Haus ", PropertyType.SCENE, null, knx(0, 0, 21));
|
||||
|
||||
if (sceneRepository.count() == 0) {
|
||||
final SceneDto alles_aus = sceneWriteService.create(1, "Alles AUS");
|
||||
final SceneDto nachtlicht = sceneWriteService.create(2, "Nachtlicht");
|
||||
final SceneDto dekoration_aus = sceneWriteService.create(30, "Dekoration AUS");
|
||||
final SceneDto dekoration_an = sceneWriteService.create(31, "Dekoration AN");
|
||||
final SceneDto aussendekoration_aus = sceneWriteService.create(30, "Außendekoration AUS");
|
||||
final SceneDto aussendekoration_an = sceneWriteService.create(31, "Außendekoration AN");
|
||||
|
||||
if (deviceRepository.count() == 0) {
|
||||
deviceWriteService.createDeviceStateScene(eg, eg_szene, alles_aus);
|
||||
deviceWriteService.createDeviceStateScene(og, og_szene, alles_aus);
|
||||
deviceWriteService.createDeviceStateScene(erdgeschoss, erdgeschoss_szene, alles_aus);
|
||||
deviceWriteService.createDeviceStateScene(obergeschoss, obergeschoss_szene, alles_aus);
|
||||
|
||||
deviceWriteService.createDeviceSwitch(fernseher);
|
||||
deviceWriteService.createDeviceSwitch(verstaerker);
|
||||
deviceWriteService.createDeviceSwitch(garten_steckdosen);
|
||||
deviceWriteService.createDeviceSwitch(aussendekoration);
|
||||
deviceWriteService.createDeviceSwitch(terrasse);
|
||||
|
||||
deviceWriteService.createDeviceSwitch(ambiente_eg);
|
||||
@ -153,9 +153,8 @@ public class DemoDataService {
|
||||
return knxGroupReadService.getByAddress(main, mid, sub);
|
||||
}
|
||||
|
||||
private Property createProperty(final String name, final PropertyType type, final String title, final Channel readChannel, final Channel writeChannel) {
|
||||
final Property property = propertyRepository.findByName(name).orElseGet(() -> propertyRepository.save(new Property(name, type)));
|
||||
property.setTitle(title);
|
||||
private Property createProperty(final String title, final PropertyType type, final Channel readChannel, final Channel writeChannel) {
|
||||
final Property property = propertyRepository.findByTitle(title).orElseGet(() -> propertyRepository.save(new Property(title, type)));
|
||||
property.setReadChannel(readChannel);
|
||||
property.setWriteChannel(writeChannel);
|
||||
return property;
|
||||
|
||||
@ -52,23 +52,23 @@ public class DeviceController {
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/DeviceSwitch/stateProperty")
|
||||
public DeviceDto setDeviceSwitchStateProperty(@PathVariable final long id, @RequestBody(required = false) final String name) {
|
||||
return deviceWriteService.setDeviceSwitch(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getByName)), name);
|
||||
public DeviceDto setDeviceSwitchStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||
return deviceWriteService.setDeviceSwitch(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/DeviceStateScene/stateProperty")
|
||||
public DeviceDto setDeviceStateSceneStateProperty(@PathVariable final long id, @RequestBody(required = false) final String name) {
|
||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getByName)), name);
|
||||
public DeviceDto setDeviceStateSceneStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/DeviceStateScene/sceneProperty")
|
||||
public DeviceDto setDeviceStateSceneSceneProperty(@PathVariable final long id, @RequestBody(required = false) final String name) {
|
||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setSceneProperty(mapIfNotNull(v, propertyReadService::getByName)), name);
|
||||
public DeviceDto setDeviceStateSceneSceneProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setSceneProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/DeviceShutter/positionProperty")
|
||||
public DeviceDto setDeviceShutterPositionProperty(@PathVariable final long id, @RequestBody(required = false) final String name) {
|
||||
return deviceWriteService.setDeviceShutter(id, (device, v) -> device.setPositionProperty(mapIfNotNull(v, propertyReadService::getByName)), name);
|
||||
public DeviceDto setDeviceShutterPositionProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||
return deviceWriteService.setDeviceShutter(id, (device, v) -> device.setPositionProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package de.ph87.homeautomation.property;
|
||||
|
||||
public interface IPropertyOwner {
|
||||
|
||||
String getPropertyOwnerName();
|
||||
|
||||
Property write(final String name, final double value);
|
||||
|
||||
}
|
||||
@ -22,10 +22,7 @@ public final class Property {
|
||||
@Enumerated(EnumType.STRING)
|
||||
private PropertyType type;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(unique = true)
|
||||
@Column(nullable = false, unique = true)
|
||||
private String title;
|
||||
|
||||
private ZonedDateTime timestamp;
|
||||
@ -38,8 +35,8 @@ public final class Property {
|
||||
@ManyToOne
|
||||
private Channel writeChannel;
|
||||
|
||||
public Property(final String name, final PropertyType type) {
|
||||
this.name = name;
|
||||
public Property(final String title, final PropertyType type) {
|
||||
this.title = title;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@ -27,11 +27,6 @@ public class PropertyController implements ISearchController {
|
||||
return propertyWriteService.set(id, Property::setType, PropertyType.valueOf(propertyType));
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/name")
|
||||
public PropertyDto setPropertyName(@PathVariable final long id, @RequestBody final String propertyName) {
|
||||
return propertyWriteService.set(id, Property::setName, propertyName);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/title")
|
||||
public PropertyDto setPropertyTitle(@PathVariable final long id, @RequestBody final String propertyTitle) {
|
||||
return propertyWriteService.set(id, Property::setTitle, propertyTitle);
|
||||
|
||||
@ -13,8 +13,6 @@ public final class PropertyDto implements Serializable {
|
||||
|
||||
private final PropertyType type;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String title;
|
||||
|
||||
private final Double value;
|
||||
@ -28,7 +26,6 @@ public final class PropertyDto implements Serializable {
|
||||
public PropertyDto(final Property property, final ChannelDto readChannel, final ChannelDto writeChannel) {
|
||||
this.id = property.getId();
|
||||
this.type = property.getType();
|
||||
this.name = property.getName();
|
||||
this.title = property.getTitle();
|
||||
this.value = property.getValue();
|
||||
this.timestamp = property.getTimestamp();
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
package de.ph87.homeautomation.property;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PropertyOwnerValidatorService {
|
||||
|
||||
private final Set<IPropertyOwner> owners;
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
final Map<IPropertyOwner, List<IPropertyOwner>> overlapping = owners.stream().collect(Collectors.toMap(owner -> owner, this::getOverlappingList));
|
||||
if (!overlapping.values().stream().allMatch(List::isEmpty)) {
|
||||
throw new RuntimeException(
|
||||
String.format(
|
||||
"Following IPropertyOwners have overlapping names:\n\t%s",
|
||||
overlapping.entrySet().stream()
|
||||
.map(entry -> {
|
||||
final String prefixClassName = entry.getKey().getClass().getCanonicalName();
|
||||
final String prefixPropertyName = entry.getKey().getPropertyOwnerName();
|
||||
final String overlappingList = entry.getValue().stream().map(owner -> owner.getClass().getCanonicalName() + "(" + owner.getPropertyOwnerName() + ")").collect(Collectors.joining("\n\t\t"));
|
||||
return String.format("%s(%s):\n\t\t%s", prefixClassName, prefixPropertyName, overlappingList);
|
||||
})
|
||||
.collect(Collectors.joining("\n\t"))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private List<IPropertyOwner> getOverlappingList(final IPropertyOwner a) {
|
||||
return owners.stream().filter(b -> b.getPropertyOwnerName().startsWith(a.getPropertyOwnerName())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,16 +18,12 @@ public class PropertyReadService {
|
||||
|
||||
private final PropertyMapper propertyMapper;
|
||||
|
||||
public Property getByName(final String name) {
|
||||
return propertyRepository.findByName(name).orElseThrow(RuntimeException::new);
|
||||
}
|
||||
|
||||
public List<Property> findAllByReadChannel_Id(final long readChannelId) {
|
||||
return propertyRepository.findAllByReadChannel_Id(readChannelId);
|
||||
}
|
||||
|
||||
public List<PropertyDto> findAllDtoLike(final String like) {
|
||||
return propertyRepository.findAllByNameLike(like).stream().map(propertyMapper::toDto).collect(Collectors.toList());
|
||||
return propertyRepository.findAllByTitleLike(like).stream().map(propertyMapper::toDto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public PropertyDto getDtoById(final long id) {
|
||||
|
||||
@ -7,15 +7,15 @@ import java.util.Optional;
|
||||
|
||||
public interface PropertyRepository extends CrudRepository<Property, Long> {
|
||||
|
||||
Optional<Property> findByName(String name);
|
||||
Optional<Property> findByTitle(String title);
|
||||
|
||||
List<Property> findAllByReadChannel_Id(long readChannelId);
|
||||
|
||||
List<Property> findAll();
|
||||
|
||||
List<Property> findAllByNameLike(final String like);
|
||||
List<Property> findAllByTitleLike(final String like);
|
||||
|
||||
boolean existsByName(String name);
|
||||
boolean existsByTitle(String title);
|
||||
|
||||
List<Property> findAllByReadChannelNotNull();
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ import java.util.function.BiConsumer;
|
||||
@RequiredArgsConstructor
|
||||
public class PropertyWriteService {
|
||||
|
||||
private static final String NAME_PREFIX = "NEU ";
|
||||
private static final String TITLE_PREFIX = "NEU ";
|
||||
|
||||
private final PropertyReadService propertyReadService;
|
||||
|
||||
@ -30,10 +30,6 @@ public class PropertyWriteService {
|
||||
|
||||
private final PropertyRepository propertyRepository;
|
||||
|
||||
public void write(final String name, final double value) {
|
||||
write(propertyReadService.getByName(name), value);
|
||||
}
|
||||
|
||||
public void write(final Property property, final double value) {
|
||||
channelService.write(property, value);
|
||||
}
|
||||
@ -52,17 +48,17 @@ public class PropertyWriteService {
|
||||
|
||||
public PropertyDto create() {
|
||||
final Property entry = new Property();
|
||||
entry.setTitle(generateUnusedName());
|
||||
entry.setTitle(generateUnusedTitle());
|
||||
return publish(propertyRepository.save(entry), true);
|
||||
}
|
||||
|
||||
private String generateUnusedName() {
|
||||
private String generateUnusedTitle() {
|
||||
int index = 0;
|
||||
String name = null;
|
||||
while (name == null || propertyRepository.existsByName(name)) {
|
||||
name = PropertyWriteService.NAME_PREFIX + ++index;
|
||||
String title = null;
|
||||
while (title == null || propertyRepository.existsByTitle(title)) {
|
||||
title = PropertyWriteService.TITLE_PREFIX + ++index;
|
||||
}
|
||||
return name;
|
||||
return title;
|
||||
}
|
||||
|
||||
public <T> PropertyDto set(final long id, final BiConsumer<Property, T> setter, final T value) {
|
||||
|
||||
@ -49,9 +49,9 @@ public class ScheduleController {
|
||||
return scheduleWriteService.set(id, Schedule::setTitle, title);
|
||||
}
|
||||
|
||||
@PostMapping("set/{id}/propertyName")
|
||||
public ScheduleDto setPropertyName(@PathVariable final long id, @RequestBody(required = false) final String propertyName) {
|
||||
return scheduleWriteService.set(id, (schedule, v) -> schedule.setProperty(mapIfNotNull(v, propertyReadService::getByName)), propertyName);
|
||||
@PostMapping("set/{id}/property")
|
||||
public ScheduleDto setPropertyName(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||
return scheduleWriteService.set(id, (schedule, v) -> schedule.setProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user