Skip to content

Feature/search filter - #63

Merged
gitnes94 merged 4 commits into
mainfrom
feature/SearchFilter
Apr 14, 2026
Merged

Feature/search filter#63
gitnes94 merged 4 commits into
mainfrom
feature/SearchFilter

Conversation

@gitnes94

@gitnes94 gitnes94 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Resolved:

#35 — Sök och filtrera tickets
#47 — Comment author från SecurityContext istället för request body
#52 — Inconsistent Lombok usage (TicketAttachment)
#59 — JWT HMAC-nyckelderivering fixad + try-catch i OAuth2SuccessHandler

Summary by CodeRabbit

  • New Features

    • Added filtering for tickets by status, priority, issue type, assignee, and creator via query parameters.
  • Refactor

    • Comment creation now derives author from authenticated user; authorId is no longer required in requests.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gitnes94 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 19 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65572194-0b40-4cb9-9bab-473ef306bef6

📥 Commits

Reviewing files that changed from the base of the PR and between 18e9179 and 99300ac.

📒 Files selected for processing (1)
  • src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java
📝 Walkthrough

Walkthrough

The PR refactors comment authorship to use authenticated user context instead of client-provided authorId, adds dynamic filtering capability to ticket listing via query parameters, and applies Lombok annotations to TicketAttachment for cleaner code.

Changes

Cohort / File(s) Summary
Comment Authorship Refactoring
src/main/java/org/example/cyberwatch/config/SecurityConfig.java, src/main/java/org/example/cyberwatch/features/comment/controller/CommentController.java, src/main/java/org/example/cyberwatch/features/comment/model/CommentDTO.java, src/main/java/org/example/cyberwatch/features/comment/service/CommentService.java
Removed authorId from CommentDTO and updated comment creation to derive author from @AuthenticationPrincipal Staff author instead of client input. CommentService now receives Staff directly, eliminating StaffRepository dependency and lookup logic. SecurityConfig rule for /api/tickets/** commented out, affecting fallback authorization.
Ticket Filtering Feature
src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java, src/main/java/org/example/cyberwatch/features/ticket/model/TicketFilterParams.java, src/main/java/org/example/cyberwatch/features/ticket/repository/TicketRepository.java, src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java
Added new TicketFilterParams model with nullable filter fields (status, priority, issueType, assignedToId, createdById) and isEmpty() method. TicketController.getAllTickets now accepts filter parameters. TicketRepository gains new JPQL findByFilters() supporting multi-criteria dynamic filtering. TicketService adds getFilteredTickets() that conditionally applies filtering.
Code Cleanup
src/main/java/org/example/cyberwatch/features/ticket/model/TicketAttachment.java
Refactored entity to use Lombok @Getter, @Setter, and @NoArgsConstructor annotations, removing manual getter/setter implementations and explicit constructor.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CommentController
    participant AuthenticationPrincipal as Auth Context
    participant CommentService
    participant TicketRepository
    participant ActivityLogService
    
    rect rgba(100, 200, 150, 0.5)
    Note over Client,ActivityLogService: Old Flow (Client-Provided Author)
    Client->>CommentController: POST /api/tickets/{id}/comments<br/>(CommentDTO with authorId)
    CommentController->>CommentService: addComment(ticketId, dto)
    CommentService->>TicketRepository: findById(ticketId)
    TicketRepository-->>CommentService: Ticket
    CommentService->>CommentService: lookup Staff by dto.authorId
    end
    
    rect rgba(150, 150, 200, 0.5)
    Note over Client,ActivityLogService: New Flow (Authenticated Author)
    Client->>CommentController: POST /api/tickets/{id}/comments<br/>(CommentDTO without authorId)
    AuthenticationPrincipal-->>CommentController: Staff (authenticated principal)
    CommentController->>CommentService: addComment(ticketId, dto, author)
    CommentService->>TicketRepository: findById(ticketId)
    TicketRepository-->>CommentService: Ticket
    CommentService->>ActivityLogService: log activity
    ActivityLogService-->>CommentService: logged
    CommentService-->>CommentController: Comment created
    CommentController-->>Client: 201 CommentResponseDTO
    end
Loading
sequenceDiagram
    participant Client
    participant TicketController
    participant TicketService
    participant TicketRepository
    participant DTOMapper
    
    rect rgba(150, 200, 150, 0.5)
    Note over Client,DTOMapper: Ticket Filtering Flow
    Client->>TicketController: GET /api/tickets?status=OPEN&priority=HIGH
    TicketController->>TicketController: parse query params → TicketFilterParams
    alt filters.isEmpty()
        TicketService->>TicketService: getAllTickets()
    else filters present
        TicketService->>TicketRepository: findByFilters(status, priority, ...)
        TicketRepository->>TicketRepository: dynamic WHERE clause filtering
        TicketRepository-->>TicketService: List\<Ticket\>
    end
    TicketService->>DTOMapper: map to TicketResponseDTO list
    DTOMapper-->>TicketService: List\<TicketResponseDTO\>
    TicketService-->>TicketController: filtered results
    TicketController-->>Client: 200 List\<TicketResponseDTO\>
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • Feature/audit logging #31 — Modifies comment endpoints and activity logging for comments; shares overlapping changes to CommentController and CommentService architecture.
  • Feature/ticket entity life cycle #23 — Extends ticket listing flow with DTO-based endpoints and repository query methods; overlaps with TicketController, TicketService, and TicketRepository modifications.
  • Feature/security fun #57 — Modifies SecurityConfig authorization rules; related to the /api/tickets/** permit rule changes in this PR.

Suggested reviewers

  • alicewersen-rgb
  • codebyNorthsteep
  • Ericthilen

🐰 With auth now whispered by Spring's embrace,
And tickets filtered by their rightful place,
Comments know their author's truested face,
Lombok cleans the clutter, sets the pace!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/search filter' is vague and generic, using non-descriptive terms that don't clearly convey the scope of changes across multiple systems including security configuration, comment author handling, and Lombok refactoring. Consider a more descriptive title that captures the primary change, such as 'Add ticket filtering with enhanced security context for comments' or break into focused PRs.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/SearchFilter

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/java/org/example/cyberwatch/features/comment/service/CommentService.java (1)

38-45: Add a fail-fast guard for missing authenticated author.

Consider rejecting null author early to avoid persisting invalid data or surfacing a later NPE/constraint error if security wiring is misconfigured.

Proposed patch
 public CommentResponseDTO addComment(Long ticketId, CommentDTO dto, Staff author) {
+    if (author == null) {
+        throw new IllegalStateException("Authenticated author is required");
+    }
+
     Ticket ticket = ticketRepository.findById(ticketId)
             .orElseThrow(() -> new TicketNotFoundException(ticketId));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/cyberwatch/features/comment/service/CommentService.java`
around lines 38 - 45, The addComment(Long ticketId, CommentDTO dto, Staff
author) method should fail fast when author is null: add an early null-check for
the author parameter at the start of the method (before creating Comment), and
throw a clear exception (e.g., IllegalArgumentException or a custom
UnauthorizedException) with a descriptive message so we never proceed to
setTicket/setAuthor or persist an invalid Comment; update tests if any rely on
null-author behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java`:
- Around line 97-106: The branch that returns all tickets when filters.isEmpty()
is inconsistent with the filtered path's ordering; update getAllTickets() (or
the empty-filters branch) so it returns tickets ordered by createdAt DESC to
match ticketRepository.findByFilters(...) ordering. Locate the getAllTickets()
method in TicketService and change its repository call to use an ordered query
(or delegate to the repository method ensuring createdAt DESC), so both the
no-filter path and the filtered path return tickets "nyast först".

---

Nitpick comments:
In
`@src/main/java/org/example/cyberwatch/features/comment/service/CommentService.java`:
- Around line 38-45: The addComment(Long ticketId, CommentDTO dto, Staff author)
method should fail fast when author is null: add an early null-check for the
author parameter at the start of the method (before creating Comment), and throw
a clear exception (e.g., IllegalArgumentException or a custom
UnauthorizedException) with a descriptive message so we never proceed to
setTicket/setAuthor or persist an invalid Comment; update tests if any rely on
null-author behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 126b3c70-5ecb-459e-a391-08c7b7a933b4

📥 Commits

Reviewing files that changed from the base of the PR and between bea96fb and 18e9179.

📒 Files selected for processing (9)
  • src/main/java/org/example/cyberwatch/config/SecurityConfig.java
  • src/main/java/org/example/cyberwatch/features/comment/controller/CommentController.java
  • src/main/java/org/example/cyberwatch/features/comment/model/CommentDTO.java
  • src/main/java/org/example/cyberwatch/features/comment/service/CommentService.java
  • src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/TicketAttachment.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/TicketFilterParams.java
  • src/main/java/org/example/cyberwatch/features/ticket/repository/TicketRepository.java
  • src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java

Comment thread src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java Outdated
@gitnes94
gitnes94 merged commit 751e0be into main Apr 14, 2026
1 check passed
@gitnes94
gitnes94 deleted the feature/SearchFilter branch April 14, 2026 07:26
This was referenced Apr 17, 2026
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