source: src/main/java/com/example/autopartz/model/Deliveryman.java

main
Last change on this file was 676144b, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 23 months ago

Added admin view of pending roles and approve functionality

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package com.example.autopartz.model;
2
3import lombok.Getter;
4import lombok.RequiredArgsConstructor;
5import lombok.Setter;
6import lombok.ToString;
7import org.hibernate.Hibernate;
8import org.springframework.security.core.GrantedAuthority;
9
10import javax.persistence.Entity;
11import javax.persistence.Table;
12import java.time.LocalDate;
13import java.util.Collection;
14import java.util.Collections;
15import java.util.Objects;
16
17@Getter
18@Setter
19@ToString
20@RequiredArgsConstructor
21@Entity
22@Table(name = "delivery_man")
23public 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}
Note: See TracBrowser for help on using the repository browser.