Badges and states added
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
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.enums.VisibilityPrivacy;
|
||||
import SuMoC.backend.user.service.UserService;
|
||||
import SuMoC.backend.user.stats.StatsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,10 +28,12 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
private final UserService userService;
|
||||
private final StatsService statsService;
|
||||
|
||||
@Autowired
|
||||
public UserController(UserService userService) {
|
||||
public UserController(UserService userService, StatsService statsService) {
|
||||
this.userService = userService;
|
||||
this.statsService = statsService;
|
||||
}
|
||||
|
||||
@Operation(summary = "Nutzer fragt ein fremdes Nutzerprofil an", description = "Ein Nutzer kann das Profil eines anderen Nutzers anfragen, um dessen öffentliche Informationen einzusehen.")
|
||||
@@ -141,4 +148,31 @@ public class UserController {
|
||||
this.userService.setVisibilityPrivacy(visibilityPrivacy);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Add stats to the current user",
|
||||
description = "Adds a value to a stat field for the current user. Optionally checks and awards badges afterwards.")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Stats updated successfully"),
|
||||
@ApiResponse(responseCode = "400", description = "Invalid stat field / invalid input",
|
||||
content = @Content(mediaType = "application/json")),
|
||||
@ApiResponse(responseCode = "403", description = "Not authorized",
|
||||
content = @Content(mediaType = "application/json"))
|
||||
})
|
||||
@RolesAllowed({"USER", "ADMIN"})
|
||||
@PostMapping("/stats/add")
|
||||
public ResponseEntity<Void> addStats(@RequestBody @Valid AddStatRequestDTO body) {
|
||||
|
||||
StatScope scope = body.getScope();
|
||||
boolean awardBadges = body.getAwardBadges() == null || body.getAwardBadges();
|
||||
|
||||
this.statsService.addStatsToCurrentUser(
|
||||
body.getStat(),
|
||||
body.getValue(),
|
||||
scope,
|
||||
awardBadges
|
||||
);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user