package no.kdrs.grouse.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.hateoas.ResourceSupport;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by tsodring 28/03/2018
 * <p>
 * Basic User entity to define a user that can login into the system. It is
 * assumed that the username is an email address.
 * <p>
 * Called GrouseUser as spring has a User entity define somewhere and I always
 * find it messy having both of these being used in the same method.
 */
@Entity
@Table(name = "user")
public class GrouseUser
        extends ResourceSupport {

    @Id
    @Email
    @NotNull
    @Column(name = "username", nullable = false)
    private String username;

    @JsonIgnore
    @NotNull
    @Column(name = "password", nullable = false)
    private String password;

    @NotNull
    @Column(name = "firstname", nullable = false)
    private String firstname;

    @NotNull
    @Column(name = "lastname", nullable = false)
    private String lastname;

    @ManyToMany
    @JoinTable(
            name = "user_role",
            joinColumns = @JoinColumn(
                    name = "username", referencedColumnName = "username"),
            inverseJoinColumns = @JoinColumn(
                    name = "role", referencedColumnName = "role"))
    private List<Role> roles;

    @JsonIgnore
    @OneToMany(mappedBy = "referenceUser", fetch = FetchType.LAZY)
    private List<Project> referenceProject;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<Project> getReferenceProject() {
        return referenceProject;
    }

    public void setReferenceProject(List<Project> referenceProject) {
        this.referenceProject = referenceProject;
    }

    @Override
    public String toString() {
        return "GrouseUser{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", firstname='" + firstname + '\'' +
                ", lastname='" + lastname + '\'' +
                '}';
    }
}

@@ -799,31 +799,16 @@
 rname;%0A%0A
-    @JsonIgnore
 %0A    @No

Remove @JsonIgnore