invited model finally works

This commit is contained in:
Tommaso Rodolfo Masera 2020-04-18 15:35:04 +02:00
parent 262dbf12e7
commit 566a2e72e3
3 changed files with 25 additions and 36 deletions

View file

@ -61,7 +61,7 @@ public abstract class Device {
@OneToMany(mappedBy = "device", orphanRemoval = true)
@GsonExclude
private Set<State> states = new HashSet<>();
private Set<State<?>> states = new HashSet<>();
public long getId() {
return id;

View file

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

View file

@ -2,9 +2,11 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
/** A user of the Smarthut application */
@Entity(name = "smarthutuser")
@ -36,9 +38,28 @@ public class User {
@Column(nullable = false, unique = true)
private String email;
/** A host user who can invite guests to their smart house */
@OneToMany(mappedBy = "guest")
private Set<Invited> guests;
/** Guests invited by this user */
@ManyToMany(cascade = CascadeType.DETACH)
@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)
@GsonExclude