[e6b2246] | 1 | package com.example.moviezone.model;
|
---|
| 2 |
|
---|
[2269653] | 3 | import javax.persistence.*;
|
---|
[e6b2246] | 4 | import lombok.Getter;
|
---|
| 5 | import lombok.Setter;
|
---|
| 6 | import lombok.ToString;
|
---|
[ac25203] | 7 | import org.springframework.security.core.GrantedAuthority;
|
---|
| 8 |
|
---|
[27adfc8] | 9 | import java.time.LocalDate;
|
---|
[ac25203] | 10 | import java.util.Collection;
|
---|
| 11 | import java.util.Collections;
|
---|
[d7f5da9] | 12 | import java.util.Objects;
|
---|
[e6b2246] | 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 |
|
---|
[eb226b2] | 27 | @ManyToOne
|
---|
| 28 | @JoinColumn(name = "id_cinema")
|
---|
[e6b2246] | 29 | Cinema cinema;
|
---|
[27adfc8] | 30 |
|
---|
[6032d44] | 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 | }
|
---|
[5444409] | 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 | }
|
---|
[6032d44] | 41 |
|
---|
[d7f5da9] | 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 |
|
---|
[6032d44] | 55 | public Worker() {
|
---|
| 56 |
|
---|
| 57 | }
|
---|
[27adfc8] | 58 |
|
---|
[ac25203] | 59 | @Override
|
---|
| 60 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
[1e7126f] | 61 | if (position.equalsIgnoreCase("admin"))
|
---|
| 62 | return Collections.singletonList(Role.ROLE_ADMIN);
|
---|
| 63 | else{
|
---|
| 64 | return Collections.singletonList(Role.ROLE_WORKER);
|
---|
| 65 | }
|
---|
[ac25203] | 66 | }
|
---|
[e6b2246] | 67 |
|
---|
| 68 | }
|
---|