StatsListAdd #16
@@ -1,12 +1,10 @@
|
||||
package SuMoC.backend.user.controller;
|
||||
|
||||
import SuMoC.backend.security.dtos.LoginResponseDTO;
|
||||
import SuMoC.backend.user.dtos.AddStatRequestDTO;
|
||||
import SuMoC.backend.user.dtos.MaximalUserDTO;
|
||||
import SuMoC.backend.user.dtos.MinimalUserDTO;
|
||||
import SuMoC.backend.user.dtos.StatScope;
|
||||
import SuMoC.backend.user.dtos.*;
|
||||
import SuMoC.backend.user.enums.VisibilityPrivacy;
|
||||
import SuMoC.backend.user.service.UserService;
|
||||
import SuMoC.backend.user.stats.StatsList;
|
||||
import SuMoC.backend.user.stats.StatsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
@@ -24,7 +22,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Validated
|
||||
@@ -186,7 +183,20 @@ public class UserController {
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "get stats of current user",
|
||||
description = "Returns all stats of a user")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Stats were found",
|
||||
content = @Content(mediaType = "application/json")),
|
||||
@ApiResponse(responseCode = "403", description = "Not authorized",
|
||||
content = @Content(mediaType = "application/json"))
|
||||
})
|
||||
@RolesAllowed({"USER", "ADMIN"})
|
||||
@GetMapping("/stats")
|
||||
public ResponseEntity<StatsList> getStats() {
|
||||
StatsList stats = this.statsService.getStats();
|
||||
return ResponseEntity.ok().body(stats);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "Add a profile Picture to the user.", description = "A user can add or update a profile picture to be displayed on his profile.")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package SuMoC.backend.user.stats;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@@ -13,6 +14,7 @@ public class Stats {
|
||||
|
||||
@Schema(description = "The StatsList to which these stats belong.", required = true)
|
||||
@ManyToOne
|
||||
@JsonIgnore
|
||||
private StatsList statsList;
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
import SuMoC.backend.gamification.Timeframe;
|
||||
import SuMoC.backend.user.models.User;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@@ -21,6 +22,7 @@ public class StatsList {
|
||||
@OneToOne
|
||||
@MapsId
|
||||
@JoinColumn(name = "user_id")
|
||||
@JsonIgnore
|
||||
private User user;
|
||||
|
||||
@Schema(description = "Total stats of the user.")
|
||||
|
||||
@@ -90,4 +90,9 @@ public class StatsService {
|
||||
badgeService.checkAndAwardBadges();
|
||||
}
|
||||
}
|
||||
|
||||
public StatsList getStats() {
|
||||
User user = currentUserService.get();
|
||||
return user.getStats();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user