Skip to content

Commit

Permalink
age instead of birthdate for public profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 17, 2023
1 parent 2133dd5 commit adf1070
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/main/java/net/dancier/dancer/core/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import org.springframework.util.StringUtils;

import java.time.Instant;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Data;
import net.dancier.dancer.core.model.Gender;

import java.time.LocalDate;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
Expand All @@ -20,7 +21,7 @@ public class ProfileOfCurrentUserDto {
private String dancerName;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date birthDate;
private LocalDate birthDate;

private Set<DanceProfileDto> ableTo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.dancier.dancer.core.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import net.dancier.dancer.authentication.model.User;
import net.dancier.dancer.core.model.Dancer;
import net.dancier.dancer.core.model.Gender;

import java.util.Date;
import java.time.LocalDate;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -20,7 +18,7 @@ public static PublicProfileDto of(Dancer dancer) {
publicProfileDto.setSize(dancer.getSize());
publicProfileDto.setGender(dancer.getGender());
publicProfileDto.setDancerName(dancer.getDancerName());
publicProfileDto.setBirthDate(dancer.getBirthDate());
publicProfileDto.setAge(LocalDate.now().getYear() - dancer.getBirthDate().getYear());
publicProfileDto.setAbleTo(dancer.getAbleTo().stream()
.map(dp -> {
DanceProfileDto danceProfileDto = new DanceProfileDto();
Expand Down Expand Up @@ -53,8 +51,7 @@ public static PublicProfileDto of(Dancer dancer) {

private String dancerName;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date birthDate;
private Integer age;

private Set<DanceProfileDto> ableTo;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/dancier/dancer/core/model/Dancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.persistence.*;
import java.time.Instant;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -38,9 +39,8 @@ public class Dancer implements Recommendable{

private Integer size;

@Column(name = "birth_date")
@Temporal(TemporalType.DATE)
private Date birthDate;
@Column(name = "birth_date", columnDefinition = "DATE")
private LocalDate birthDate;

@Enumerated(EnumType.STRING)
private Gender gender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ private static List<String> getDances(Dancer dancer) {
);
return result.stream().toList();
}
private static Integer age(Date birthdate) {
private static Integer age(LocalDate birthdate) {
LocalDate now = LocalDate.now();
if (birthdate!=null) {
return Period.between(
Instant
.ofEpochMilli(birthdate.getTime())
.atZone(ZoneId.systemDefault()).toLocalDate() , now)
birthdate , now)
.getYears();
} else {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.util.Date;
import java.util.Set;

Expand Down Expand Up @@ -66,7 +67,7 @@ void fromVirginProfileToPopulatedProfile() throws Exception {


profileOfCurrentUserDto.setGender(Gender.DIVERS);
profileOfCurrentUserDto.setBirthDate(new Date());
profileOfCurrentUserDto.setBirthDate(LocalDate.now());
profileOfCurrentUserDto.setAbleTo(Set.of(danceProfileDto));
profileOfCurrentUserDto.setWantsTo(Set.of(danceProfileDto));
profileOfCurrentUserDto.setZipCode("44339");
Expand Down

0 comments on commit adf1070

Please sign in to comment.