Merge branch 'main' into cachingAndPP
# Conflicts: # src/main/java/SuMoC/backend/gamification/badges/BadgeController.java # src/main/java/SuMoC/backend/gamification/scoretable/LeaderboardController.java # src/main/java/SuMoC/backend/gamification/scoretable/LeaderboardService.java # src/main/java/SuMoC/backend/user/controller/UserController.java # src/main/java/SuMoC/backend/user/models/User.java
This commit is contained in:
@@ -77,6 +77,16 @@ public class FriendshipController {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Request a friendship with another user by friend code.", description = "Sends a friendship request to another user identified by their friend code from the logged in user.")
|
||||
@PostMapping("/request/by-friendcode/{friendCode}")
|
||||
public ResponseEntity<Void> requestFriendshipByFriendcode(@PathVariable String friendCode) {
|
||||
User user = getAuthenticatedUser();
|
||||
User requestedFriend = userRepository.findByFriendCode(friendCode).orElseThrow();
|
||||
checkSelfAction(user.getId(), requestedFriend.getId());
|
||||
friendshipService.requestFriendship(user, requestedFriend.getId());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Accept a friendship request.", description = "Accepts a pending friendship request for the logged in user from user with friendId.")
|
||||
@PostMapping("/accept/{friendId}")
|
||||
public ResponseEntity<Void> acceptFriendship(@PathVariable Long friendId) {
|
||||
|
||||
@@ -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;
|
||||
@@ -27,10 +32,12 @@ import java.util.concurrent.TimeUnit;
|
||||
@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.")
|
||||
@@ -154,6 +161,33 @@ public class UserController {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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.")
|
||||
@ApiResponses(value = {
|
||||
|
||||
Reference in New Issue
Block a user