1 | package com.example.moviezone.model;
|
---|
2 |
|
---|
3 | import javax.persistence.*;
|
---|
4 | import lombok.Getter;
|
---|
5 | import lombok.Setter;
|
---|
6 | import lombok.ToString;
|
---|
7 | import org.springframework.security.core.GrantedAuthority;
|
---|
8 |
|
---|
9 | import java.time.LocalDate;
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.Collections;
|
---|
12 | import java.util.Objects;
|
---|
13 |
|
---|
14 | @Entity
|
---|
15 | @Getter
|
---|
16 | @Setter
|
---|
17 | @ToString
|
---|
18 | @Table(name = "workers")
|
---|
19 | @PrimaryKeyJoinColumn(name = "id_worker")
|
---|
20 | public class Worker extends User {
|
---|
21 |
|
---|
22 | String position;
|
---|
23 |
|
---|
24 | String work_hours_from;
|
---|
25 | String work_hours_to;
|
---|
26 |
|
---|
27 | @ManyToOne
|
---|
28 | @JoinColumn(name = "id_cinema")
|
---|
29 | Cinema cinema;
|
---|
30 |
|
---|
31 | public Worker(String password, String first_name, String last_name, String address, String contact_number, String username) {
|
---|
32 | super(password, first_name, last_name, address, contact_number, username);
|
---|
33 | }
|
---|
34 | public Worker(String password, String first_name, String last_name, String address, String contact_number, String username,String position,String work_hours_from,String work_hours_to,Cinema cinema) {
|
---|
35 | super(password, first_name, last_name, address, contact_number, username);
|
---|
36 | this.position=position;
|
---|
37 | this.work_hours_from=work_hours_from;
|
---|
38 | this.work_hours_to=work_hours_to;
|
---|
39 | this.cinema=cinema;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public boolean equals(Object o) {
|
---|
44 | if (this == o) return true;
|
---|
45 | if (o == null || getClass() != o.getClass()) return false;
|
---|
46 | Worker worker = (Worker) o;
|
---|
47 | return id_user!=null && Objects.equals(id_user, worker.id_user);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public int hashCode() {
|
---|
52 | return Objects.hash();
|
---|
53 | }
|
---|
54 |
|
---|
55 | public Worker() {
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
61 | if (position.equalsIgnoreCase("admin"))
|
---|
62 | return Collections.singletonList(Role.ROLE_ADMIN);
|
---|
63 | else{
|
---|
64 | return Collections.singletonList(Role.ROLE_WORKER);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|