View Javadoc
1   package org.petify.backend.dto;
2   
3   import org.petify.backend.models.ApplicationUser;
4   import org.petify.backend.models.Role;
5   import org.petify.backend.models.UserAchievement;
6   import org.petify.backend.models.VolunteerStatus;
7   
8   import lombok.Getter;
9   import lombok.Setter;
10  
11  import java.time.LocalDate;
12  import java.time.LocalDateTime;
13  import java.util.HashSet;
14  import java.util.Set;
15  import java.util.stream.Collectors;
16  
17  @Getter
18  @Setter
19  public class UserResponseDTO {
20      private Integer userId;
21      private String username;
22      private String firstName;
23      private String lastName;
24      private LocalDate birthDate;
25      private String gender;
26      private String phoneNumber;
27      private String email;
28      private VolunteerStatus volunteerStatus;
29      private boolean active;
30      private LocalDateTime createdAt;
31      private Integer xpPoints;
32      private Integer level;
33      private Integer likesCount;
34      private Integer supportCount;
35      private Integer badgesCount;
36      private Integer adoptionCount;
37      private String city;
38      private Double latitude;
39      private Double longitude;
40      private Double preferredSearchDistanceKm;
41      private Boolean autoLocationEnabled;
42      private LocalDateTime locationUpdatedAt;
43      private boolean hasProfileImage;
44      private Set<Role> authorities;
45      private Integer version;
46  
47      private Set<UserAchievement> achievements;
48  
49      private Integer xpToNextLevel;
50      private boolean hasLocation;
51      private boolean hasCompleteLocationProfile;
52  
53      public UserResponseDTO() {}
54  
55      public UserResponseDTO(ApplicationUser user) {
56          this.userId = user.getUserId();
57          this.username = user.getUsername();
58          this.firstName = user.getFirstName();
59          this.lastName = user.getLastName();
60          this.birthDate = user.getBirthDate();
61          this.gender = user.getGender();
62          this.phoneNumber = user.getPhoneNumber();
63          this.email = user.getEmail();
64          this.volunteerStatus = user.getVolunteerStatus();
65          this.active = user.isActive();
66          this.createdAt = user.getCreatedAt();
67          this.xpPoints = user.getXpPoints();
68          this.level = user.getLevel();
69          this.likesCount = user.getLikesCount();
70          this.supportCount = user.getSupportCount();
71          this.badgesCount = user.getBadgesCount();
72          this.adoptionCount = user.getAdoptionCount();
73          this.city = user.getCity();
74          this.latitude = user.getLatitude();
75          this.longitude = user.getLongitude();
76          this.preferredSearchDistanceKm = user.getPreferredSearchDistanceKm();
77          this.autoLocationEnabled = user.getAutoLocationEnabled();
78          this.locationUpdatedAt = user.getLocationUpdatedAt();
79          this.hasProfileImage = user.hasProfileImage();
80  
81          this.authorities = user.getAuthorities() != null
82                  ? user.getAuthorities().stream()
83                          .filter(Role.class::isInstance)
84                          .map(Role.class::cast)
85                          .collect(Collectors.toSet()) :
86                  new HashSet<>();
87  
88          this.achievements = user.getAchievements() != null
89                  ? user.getAchievements() : new HashSet<>();
90  
91          this.version = user.getVersion();
92  
93          this.xpToNextLevel = user.getXpToNextLevel();
94          this.hasLocation = user.hasLocation();
95          this.hasCompleteLocationProfile = user.hasCompleteLocationProfile();
96      }
97  
98      public static UserResponseDTO fromUser(ApplicationUser user) {
99          return new UserResponseDTO(user);
100     }
101 }