Skip to content

fix: change AuditLogRepository to use Pageable for paging query#110

Merged
SandraNelj merged 1 commit into
mainfrom
fix/auditlog-fix
Apr 25, 2026
Merged

fix: change AuditLogRepository to use Pageable for paging query#110
SandraNelj merged 1 commit into
mainfrom
fix/auditlog-fix

Conversation

@SandraNelj

@SandraNelj SandraNelj commented Apr 25, 2026

Copy link
Copy Markdown
Contributor
  • Change findByPerformedByIdOrderByCreatedAtDesc from List to Page return type
  • Add Pageable parameter to support paging
  • Update AuditLogController.getLogsByUser accordingly

Summary by CodeRabbit

  • New Features
    • Added pagination support to audit log retrieval, enabling users to fetch results in manageable pages with a default size of 20 items per page.

- Change findByPerformedByIdOrderByCreatedAtDesc from List to Page return type
- Add Pageable parameter to support paging
- Update AuditLogController.getLogsByUser accordingly
@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The pull request adds pagination support to the audit log retrieval endpoint. The controller's getLogsByUser method now accepts a Pageable parameter with a default page size of 20, which is forwarded to the repository method that was similarly updated to handle pagination.

Changes

Cohort / File(s) Summary
Audit Log Pagination Enhancement
src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java, src/main/java/org/example/team6backend/auditlog/repository/AuditLogRepository.java
Both controller and repository methods updated to accept a Pageable parameter, enabling pagination support for audit log retrieval by user with a default page size of 20.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hop hop, the logs now dance in pages neat,
No more one giant bundle to complete!
Twenty records per bound, so tidy and trim,
The audit trail sparkles, a pagination hymn! ✨📜

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating AuditLogRepository to use Pageable for paging queries, which is reflected in both the repository and controller modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/auditlog-fix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java (1)

35-37: Optional: align @PageableDefault with the sibling getLogs endpoint for consistency.

getLogs (Line 24) declares @PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC), while getLogsByUser only sets size = 20. Functionally this is fine here because the derived method name findByPerformedByIdOrderByCreatedAtDesc already 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 request Sort to the static OrderBy..., 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 OrderByCreatedAtDesc from 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

📥 Commits

Reviewing files that changed from the base of the PR and between 687d1d3 and d725ec4.

📒 Files selected for processing (2)
  • src/main/java/org/example/team6backend/auditlog/controller/AuditLogController.java
  • src/main/java/org/example/team6backend/auditlog/repository/AuditLogRepository.java

@SandraNelj
SandraNelj merged commit 9b2a718 into main Apr 25, 2026
3 checks passed
@kristinaxm
kristinaxm deleted the fix/auditlog-fix branch April 27, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant