diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java index 7aa65e8..e8a621b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Device.java @@ -30,7 +30,7 @@ public abstract class Device { * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. */ - @Column(name = "room_id", nullable = false) + @Column(name = "room_id", nullable = false, unique = true) @NotNull private Long roomId; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java index 0a90998..7f4056b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/KnobDimmer.java @@ -33,7 +33,11 @@ public class KnobDimmer extends Dimmer { dl.setIntensity((dl.getIntensity() + 5) % 105); } else { dl.setIntensity(dl.getIntensity() + (5 - remainder)); - dl.setIntensity((dl.getIntensity() - 5) % 105); + if (dl.getIntensity() == 0) { + dl.setIntensity(100); + } else { + dl.setIntensity(dl.getIntensity() - 5); + } } } } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java index e15805b..f6edfd3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java @@ -10,7 +10,7 @@ public class Room { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id", updatable = false, nullable = false) + @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) private Long id; @@ -33,7 +33,7 @@ public class Room { * inserting from a REST call. */ @NotNull - @Column(name = "user_id", nullable = false) + @Column(name = "user_id", nullable = false, unique = true) private Long userId; /** The user given name of this room (e.g. 'Master bedroom') */ diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index 67f95d4..e33b130 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -14,7 +14,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id", updatable = false, nullable = false) + @Column(name = "id", updatable = false, nullable = false, unique = true) @ApiModelProperty(hidden = true) private Long id; @@ -24,9 +24,9 @@ public class User { @NotEmpty(message = "Please provide a full name") private String name; - /** The full name of the user */ + /** The full username of the user */ @NotNull - @Column(nullable = false) + @Column(nullable = false, unique = true) @NotEmpty(message = "Please provide a username") private String username;