1 | package com.example.autopartz.model;
|
---|
2 |
|
---|
3 | import lombok.Getter;
|
---|
4 | import lombok.RequiredArgsConstructor;
|
---|
5 | import lombok.Setter;
|
---|
6 | import lombok.ToString;
|
---|
7 | import org.hibernate.Hibernate;
|
---|
8 | import org.springframework.security.core.GrantedAuthority;
|
---|
9 |
|
---|
10 | import javax.persistence.Entity;
|
---|
11 | import javax.persistence.Table;
|
---|
12 | import java.time.LocalDate;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.Collections;
|
---|
15 | import java.util.Objects;
|
---|
16 |
|
---|
17 | @Getter
|
---|
18 | @Setter
|
---|
19 | @ToString
|
---|
20 | @RequiredArgsConstructor
|
---|
21 | @Entity
|
---|
22 | @Table(name = "delivery_man")
|
---|
23 | public class Deliveryman extends User{
|
---|
24 | LocalDate employed_from;
|
---|
25 | public static final LocalDate defaultEmployedFrom = LocalDate.of(2020,1,1);
|
---|
26 |
|
---|
27 | public Deliveryman(String username, String name, String email, String password, String number) {
|
---|
28 | super(username, name, email, password, number);
|
---|
29 | this.employed_from = defaultEmployedFrom;
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public boolean equals(Object o) {
|
---|
34 | if (this == o) return true;
|
---|
35 | if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
---|
36 | Deliveryman that = (Deliveryman) o;
|
---|
37 | return id != null && Objects.equals(id, that.id);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public int hashCode() {
|
---|
42 | return getClass().hashCode();
|
---|
43 | }
|
---|
44 | @Override
|
---|
45 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
46 | if(Objects.equals(employed_from, defaultEmployedFrom))
|
---|
47 | return Collections.singletonList(Role.ROLE_PENDING_DELIVERYMAN);
|
---|
48 | else
|
---|
49 | return Collections.singletonList(Role.ROLE_DELIVERYMAN);
|
---|
50 | }
|
---|
51 | }
|
---|