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
* a REST call.
*/
@Column(name = "room_id", nullable = false)
@Column(name = "room_id", nullable = false, unique = true)
@NotNull
private Long roomId;

View file

@ -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);
}
}
}
}

View file

@ -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') */

View file

@ -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;