fix: accept ISO datetime for audit log from/to parameters
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 54s
CI / docker (push) Successful in 37s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 36s

The frontend sends full ISO timestamps (e.g. 2026-03-19T17:55:29Z) but
the controller expected LocalDate (yyyy-MM-dd). This caused null parsing,
which threw NullPointerException in the repository WHERE clause. Changed
to accept Instant directly with sensible defaults (last 7 days).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-26 19:07:09 +01:00
parent 1080c76e99
commit 499fd7f8e8

View File

@@ -19,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
@RestController @RestController
@RequestMapping("/api/v1/admin/audit") @RequestMapping("/api/v1/admin/audit")
@@ -43,8 +41,8 @@ public class AuditLogController {
@RequestParam(required = false) String username, @RequestParam(required = false) String username,
@RequestParam(required = false) String category, @RequestParam(required = false) String category,
@RequestParam(required = false) String search, @RequestParam(required = false) String search,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from, @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant from,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to, @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant to,
@RequestParam(defaultValue = "timestamp") String sort, @RequestParam(defaultValue = "timestamp") String sort,
@RequestParam(defaultValue = "desc") String order, @RequestParam(defaultValue = "desc") String order,
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "0") int page,
@@ -52,8 +50,8 @@ public class AuditLogController {
size = Math.min(size, 100); size = Math.min(size, 100);
Instant fromInstant = from != null ? from.atStartOfDay(ZoneOffset.UTC).toInstant() : null; Instant fromInstant = from != null ? from : Instant.now().minus(java.time.Duration.ofDays(7));
Instant toInstant = to != null ? to.plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant() : null; Instant toInstant = to != null ? to : Instant.now();
AuditCategory cat = null; AuditCategory cat = null;
if (category != null && !category.isEmpty()) { if (category != null && !category.isEmpty()) {