invited model finally works
This commit is contained in:
parent
262dbf12e7
commit
566a2e72e3
3 changed files with 25 additions and 36 deletions
|
@ -61,7 +61,7 @@ public abstract class Device {
|
||||||
|
|
||||||
@OneToMany(mappedBy = "device", orphanRemoval = true)
|
@OneToMany(mappedBy = "device", orphanRemoval = true)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
private Set<State> states = new HashSet<>();
|
private Set<State<?>> states = new HashSet<>();
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/** Represents a recursive invitation relationship between two users. */
|
|
||||||
@Entity
|
|
||||||
public class Invited {
|
|
||||||
|
|
||||||
/** Guests that have been invited to the host's house */
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "guests")
|
|
||||||
private User guest;
|
|
||||||
|
|
||||||
/** Host ID */
|
|
||||||
@Id
|
|
||||||
@Column(nullable = false)
|
|
||||||
private int hostId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Probably unnecessary, Invited can be identified through the Host ID and the IDs from the
|
|
||||||
* guests collection which we can query for
|
|
||||||
*/
|
|
||||||
// @Id @Column
|
|
||||||
// private int guestId;
|
|
||||||
|
|
||||||
/** Determines whether a guest can access security cameras */
|
|
||||||
@Column @NotNull private boolean cameraEnabled;
|
|
||||||
|
|
||||||
/** Determines whether a guest can access scenes */
|
|
||||||
@Column @NotNull private boolean sceneEnabled;
|
|
||||||
}
|
|
|
@ -2,9 +2,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/** A user of the Smarthut application */
|
/** A user of the Smarthut application */
|
||||||
@Entity(name = "smarthutuser")
|
@Entity(name = "smarthutuser")
|
||||||
|
@ -36,9 +38,28 @@ public class User {
|
||||||
@Column(nullable = false, unique = true)
|
@Column(nullable = false, unique = true)
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/** A host user who can invite guests to their smart house */
|
/** Guests invited by this user */
|
||||||
@OneToMany(mappedBy = "guest")
|
@ManyToMany(cascade = CascadeType.DETACH)
|
||||||
private Set<Invited> guests;
|
@JoinTable(
|
||||||
|
name = "invited",
|
||||||
|
joinColumns = @JoinColumn(name = "host_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "guest_id"))
|
||||||
|
@GsonExclude
|
||||||
|
private Set<User> guests = new HashSet<>();
|
||||||
|
|
||||||
|
@ManyToMany(cascade = CascadeType.DETACH)
|
||||||
|
@JoinTable(
|
||||||
|
name = "invited",
|
||||||
|
joinColumns = @JoinColumn(name = "guest_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "host_id"))
|
||||||
|
@GsonExclude
|
||||||
|
private Set<User> hosts = new HashSet<>();
|
||||||
|
|
||||||
|
/** Determines whether a guest can access security cameras */
|
||||||
|
@Column @NotNull private boolean cameraEnabled;
|
||||||
|
|
||||||
|
/** Determines whether a guest can access scenes */
|
||||||
|
@Column @NotNull private boolean sceneEnabled;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@GsonExclude
|
@GsonExclude
|
||||||
|
|
Loading…
Reference in a new issue