[2e46f06] | 1 | package com.example.autopartz.model;
|
---|
| 2 |
|
---|
[ae042f4] | 3 | import lombok.Getter;
|
---|
| 4 | import lombok.RequiredArgsConstructor;
|
---|
| 5 | import lombok.Setter;
|
---|
| 6 | import lombok.ToString;
|
---|
[2e46f06] | 7 | import org.hibernate.Hibernate;
|
---|
[ae042f4] | 8 | import org.springframework.security.core.GrantedAuthority;
|
---|
[2e46f06] | 9 |
|
---|
[ae042f4] | 10 | import javax.persistence.Entity;
|
---|
| 11 | import javax.persistence.Table;
|
---|
[2e46f06] | 12 | import java.time.LocalDate;
|
---|
[ae042f4] | 13 | import java.util.Collection;
|
---|
| 14 | import java.util.Collections;
|
---|
[2e46f06] | 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;
|
---|
[7d43957] | 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 | }
|
---|
[2e46f06] | 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_user != null && Objects.equals(ID_user, that.ID_user);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @Override
|
---|
| 41 | public int hashCode() {
|
---|
| 42 | return getClass().hashCode();
|
---|
| 43 | }
|
---|
[ae042f4] | 44 | @Override
|
---|
| 45 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
[7d43957] | 46 | if(Objects.equals(employed_from, defaultEmployedFrom))
|
---|
| 47 | return Collections.singletonList(Role.ROLE_PENDING_DELIVERYMAN);
|
---|
| 48 | else
|
---|
| 49 | return Collections.singletonList(Role.ROLE_DELIVERYMAN);
|
---|
[ae042f4] | 50 | }
|
---|
[2e46f06] | 51 | }
|
---|