fix: change AuditLogRepository to use Pageable for paging query#110
Conversation
- Change findByPerformedByIdOrderByCreatedAtDesc from List to Page return type - Add Pageable parameter to support paging - Update AuditLogController.getLogsByUser accordingly
📝 WalkthroughWalkthroughThe pull request adds pagination support to the audit log retrieval endpoint. The controller's Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java (1)
35-37: Optional: align@PageableDefaultwith the siblinggetLogsendpoint for consistency.
getLogs(Line 24) declares@PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC), whilegetLogsByUseronly setssize = 20. Functionally this is fine here because the derived method namefindByPerformedByIdOrderByCreatedAtDescalready enforces the ordering, so the default page is correctly sorted. However, declaring the same sort defaults explicitly makes the API contract self-documenting and ensures consistent behavior if a caller supplies a partial?sort=...override (Spring Data appends the requestSortto the staticOrderBy..., so mixing client-supplied sorts with the implicit ordering can be surprising).♻️ Suggested alignment
- public ResponseEntity<Page<AuditLog>> getLogsByUser(`@PathVariable` String userId, - `@PageableDefault`(size = 20) Pageable pageable) { + public ResponseEntity<Page<AuditLog>> getLogsByUser(`@PathVariable` String userId, + `@PageableDefault`(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {If you go this route, you could also drop
OrderByCreatedAtDescfrom the repository method name to make the sort source unambiguous (single source of truth in the controller). Either choice is fine — just pick one.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java` around lines 35 - 37, getLogsByUser currently uses `@PageableDefault`(size = 20) while sibling getLogs uses `@PageableDefault`(size = 20, sort = "createdAt", direction = Sort.Direction.DESC); update the `@PageableDefault` on getLogsByUser to include sort = "createdAt" and direction = Sort.Direction.DESC so the controller explicitly documents and enforces the default ordering (or alternatively remove OrderByCreatedAtDesc from the repository method findByPerformedByIdOrderByCreatedAtDesc and keep the sort in the controller—pick one approach for a single source of truth).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java`:
- Around line 35-37: getLogsByUser currently uses `@PageableDefault`(size = 20)
while sibling getLogs uses `@PageableDefault`(size = 20, sort = "createdAt",
direction = Sort.Direction.DESC); update the `@PageableDefault` on getLogsByUser
to include sort = "createdAt" and direction = Sort.Direction.DESC so the
controller explicitly documents and enforces the default ordering (or
alternatively remove OrderByCreatedAtDesc from the repository method
findByPerformedByIdOrderByCreatedAtDesc and keep the sort in the controller—pick
one approach for a single source of truth).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e8ff75b6-efa9-4e2b-a481-39503ea04fb3
📒 Files selected for processing (2)
src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.javasrc/main/java/org/example/team6backend/auditlog/repository/AuditLogRepository.java
Summary by CodeRabbit