added uniqueness constraints

This commit is contained in:
Tommaso Rodolfo Masera 2020-03-03 11:04:58 +01:00
parent eede89b7be
commit e806c18809
4 changed files with 11 additions and 7 deletions

View file

@ -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 * The room this device belongs in, as a foreign key id. To use when updating and inserting from
* a REST call. * a REST call.
*/ */
@Column(name = "room_id", nullable = false) @Column(name = "room_id", nullable = false, unique = true)
@NotNull @NotNull
private Long roomId; private Long roomId;

View file

@ -33,7 +33,11 @@ public class KnobDimmer extends Dimmer {
dl.setIntensity((dl.getIntensity() + 5) % 105); dl.setIntensity((dl.getIntensity() + 5) % 105);
} else { } else {
dl.setIntensity(dl.getIntensity() + (5 - remainder)); 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);
}
} }
} }
} }

View file

@ -10,7 +10,7 @@ public class Room {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false) @Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private Long id; private Long id;
@ -33,7 +33,7 @@ public class Room {
* inserting from a REST call. * inserting from a REST call.
*/ */
@NotNull @NotNull
@Column(name = "user_id", nullable = false) @Column(name = "user_id", nullable = false, unique = true)
private Long userId; private Long userId;
/** The user given name of this room (e.g. 'Master bedroom') */ /** The user given name of this room (e.g. 'Master bedroom') */

View file

@ -14,7 +14,7 @@ public class User {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false) @Column(name = "id", updatable = false, nullable = false, unique = true)
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
private Long id; private Long id;
@ -24,9 +24,9 @@ public class User {
@NotEmpty(message = "Please provide a full name") @NotEmpty(message = "Please provide a full name")
private String name; private String name;
/** The full name of the user */ /** The full username of the user */
@NotNull @NotNull
@Column(nullable = false) @Column(nullable = false, unique = true)
@NotEmpty(message = "Please provide a username") @NotEmpty(message = "Please provide a username")
private String username; private String username;