Skip to content
Snippets Groups Projects
Commit 261b4104 authored by Henrik's avatar Henrik
Browse files

Merge branch 'feat/add-profile-banner-to-user' into 'master'

fix: use DTO for point and streak

See merge request !83
parents 5bfc2ad8 fc96a440
No related branches found
No related tags found
1 merge request!83fix: use DTO for point and streak
Pipeline #283509 passed
......@@ -67,9 +67,6 @@ public class UserController {
@GetMapping(value = "/me", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserDTO> getUser(@AuthenticationPrincipal AuthIdentity identity) {
User user = userService.findById(identity.getId());
modelMapper.typeMap(User.class, UserDTO.class)
.addMapping(src -> src.getCheckingAccount().getBban(), UserDTO::setCheckingAccountBBAN)
.addMapping(src -> src.getSavingsAccount().getBban(), UserDTO::setSavingsAccountBBAN);
UserDTO userDTO = modelMapper.map(user, UserDTO.class);
return ResponseEntity.ok(userDTO);
}
......@@ -89,9 +86,6 @@ public class UserController {
@GetMapping(value = "/{userId}/profile", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ProfileDTO> getProfile(@PathVariable long userId) {
User user = userService.findById(userId);
modelMapper.typeMap(User.class, ProfileDTO.class)
.addMapping(src -> src.getStreak().getCurrentStreak(), ProfileDTO::setCurrentStreak)
.addMapping(src -> src.getPoint().getCurrentPoints(), ProfileDTO::setTotalPoints);
ProfileDTO profileDTO = modelMapper.map(user, ProfileDTO.class);
return ResponseEntity.ok(profileDTO);
}
......
package no.ntnu.idi.stud.savingsapp.dto.user;
import lombok.Data;
@Data
public class PointDTO {
private int currentPoints;
private int totalEarnedPoints;
}
......@@ -13,6 +13,6 @@ public class ProfileDTO {
private Long profileImage;
private Long bannerImage;
private Timestamp createdAt;
private int totalPoints;
private int currentStreak;
private PointDTO point;
private StreakDTO streak;
}
package no.ntnu.idi.stud.savingsapp.dto.user;
import java.sql.Timestamp;
import lombok.Data;
@Data
public final class StreakDTO {
private int currentStreak;
private Timestamp currentStreakCreatedAt;
private Timestamp currentStreakUpdatedAt;
private int highestStreak;
private Timestamp highestStreakCreatedAt;
private Timestamp highestStreakEndedAt;
}
......@@ -18,4 +18,6 @@ public class UserDTO {
private String subscriptionLevel;
private Long checkingAccountBBAN;
private Long savingsAccountBBAN;
private PointDTO point;
private StreakDTO streak;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment