PPaste!

Account.java

Home - All the pastes - Authored by Thooms

Raw version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.eisti.account;

import java.time.ZonedDateTime;

import javax.persistence.*;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

import com.eisti.models.Station.Station;
import com.fasterxml.jackson.annotation.JsonIgnore;

@SuppressWarnings("serial")
@Entity
@Table(name = "account")
public class Account implements java.io.Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @Column(unique = true)
    private String email;

    @JsonIgnore
    private String password;

    private String role = "ROLE_USER";

    private Instant created;

    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @JoinTable(name = "favorites", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "station_id"))
    private List<Station> favorites;

    protected Account() {
        favorites = new ArrayList<>();
    }

    public Account(String email, String password, String role) {
        this();
        this.email = email;
        this.password = password;
        this.role = role;
        this.created = Instant.now();
    }

    public Long getId() {
        return id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

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

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Instant getCreated() {
        return created;
    }

    public List<Station> getFavorites() {
        return favorites;
    }

    public boolean containsStationFromFavorite(Station station){
        return favorites.contains(station);
    }

    public boolean deleteStationFromFavorite(Station station){
        if (containsStationFromFavorite(station))
            return this.favorites.remove(station);
        return false;
    }

    public boolean addFavoriteStation(Station station){
        return favorites.add(station);
    }
}