fix(dashboard): fix NullPointerException in getUserDashboard

- @CurrentUserId resolves to String (JWT userId claim), not User entity
- Change parameter type from User to String, parse to UUID
This commit is contained in:
Bernhard Müller 2026-07-22 08:06:45 +02:00
parent 56f8636f90
commit ef4eefa4cd

View File

@ -3,7 +3,6 @@ package at.mueller.eeg.backend.dashboard.api;
import at.mueller.eeg.backend.common.security.CurrentUserId; import at.mueller.eeg.backend.common.security.CurrentUserId;
import at.mueller.eeg.backend.dashboard.api.dto.DashboardStatsDto; import at.mueller.eeg.backend.dashboard.api.dto.DashboardStatsDto;
import at.mueller.eeg.backend.dashboard.service.DashboardService; import at.mueller.eeg.backend.dashboard.service.DashboardService;
import at.mueller.eeg.backend.iam.domain.User;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -11,6 +10,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.UUID;
@RestController @RestController
@RequestMapping("/api/dashboard") @RequestMapping("/api/dashboard")
@RequiredArgsConstructor @RequiredArgsConstructor
@ -26,8 +27,7 @@ public class DashboardController {
@GetMapping("/user") @GetMapping("/user")
@PreAuthorize("hasRole('MEMBER')") @PreAuthorize("hasRole('MEMBER')")
public ResponseEntity<DashboardStatsDto.UserStats> getUserDashboard(@CurrentUserId User user) { public ResponseEntity<DashboardStatsDto.UserStats> getUserDashboard(@CurrentUserId String userId) {
// user.getId() funktioniert, da UserDetails implementiert ist return ResponseEntity.ok(dashboardService.getUserStats(UUID.fromString(userId)));
return ResponseEntity.ok(dashboardService.getUserStats(user.getId()));
} }
} }