Implement Caching and fix minor errors
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-22 09:34:24 +01:00
parent 159c03142a
commit 917ed77a95
13 changed files with 208 additions and 47 deletions
@@ -13,12 +13,15 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.concurrent.TimeUnit;
@Validated
@RestController
@RequestMapping("/user")
@@ -41,19 +44,27 @@ public class UserController {
})
@GetMapping("/profile/{id}")
public ResponseEntity<MinimalUserDTO> getUser(@PathVariable @NotNull long id) {
return new ResponseEntity<>(this.userService.getUser(id), HttpStatus.OK);
MinimalUserDTO user = this.userService.getUser(id);
return ResponseEntity.ok()
.cacheControl(CacheControl.noCache())
.body(user);
}
@Operation(summary = "Nutzer fragt sein eigenes Profil an", description = "Ein Nutzer kann sein eigenes Profil anfragen, um dessen Informationen einzusehen.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Nutzerprofil erfolgreich abgerufen",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MaximalUserDTO.class))),
@ApiResponse(responseCode = "304", description = "Nutzerprofil wurde seit dem letzten Abruf nicht verändert",
content = @Content(mediaType = "application/json")),
@ApiResponse(responseCode = "404", description = "Der Nutzer existiert nicht",
content = @Content(mediaType = "application/json"))
})
@GetMapping("/profile")
public ResponseEntity<MaximalUserDTO> getUser() {
return new ResponseEntity<>(this.userService.getSelf(), HttpStatus.OK);
MaximalUserDTO dto = this.userService.getSelf();
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS))
.body(dto);
}
@Operation(summary = "Nutzer löscht sein eigenes Profil", description = "Ein Nutzer kann sein eigenes Profil löschen. Dies entfernt alle seine Daten aus dem System.")