Skip to content

Feature/assign ticket to staff - #26

Merged
Ericthilen merged 8 commits into
mainfrom
feature/assign-ticket-to-staff
Apr 2, 2026
Merged

Feature/assign ticket to staff#26
Ericthilen merged 8 commits into
mainfrom
feature/assign-ticket-to-staff

Conversation

@Ericthilen

@Ericthilen Ericthilen commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

This PR adds functionality for assigning a ticket to a staff member.

An administrator can now assign a ticket to a specific staff user, and the ticket status is automatically updated.

  • Added assignee field to Ticket
  • Created AssignTicketDTO for request handling
  • Implemented assignment logic in TicketService
  • Added new endpoint: PUT /api/tickets/{ticketId}/assign
  • Added exception handling for StaffNotFoundException

Summary by CodeRabbit

  • New Features
    • Assign tickets to staff members (assigns an assignee and updates ticket status to in-progress); assignment endpoint restricted to admins.
  • Bug Fixes
    • Improved error responses for missing staff records, returning clear not-found messages when assignment targets are unavailable.

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 829e6231-36bc-4ebf-82bb-a068c055e0ef

📥 Commits

Reviewing files that changed from the base of the PR and between 987fd6e and d363a38.

📒 Files selected for processing (3)
  • src/main/java/org/example/cyberwatch/config/SecurityConfig.java
  • src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.java
✅ Files skipped from review due to trivial changes (2)
  • src/main/java/org/example/cyberwatch/config/SecurityConfig.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java

📝 Walkthrough

Walkthrough

Adds ticket assignment: new API endpoint, DTO, service logic and model association to set a ticket's assignee and update status to IN_PROGRESS; introduces StaffNotFoundException as a RuntimeException and a dedicated global exception handler returning 404.

Changes

Cohort / File(s) Summary
Exception Handling
src/main/java/org/example/cyberwatch/exception/GlobalExceptionHandler.java, src/main/java/org/example/cyberwatch/features/staff/exception/StaffNotFoundException.java
StaffNotFoundException now extends RuntimeException with a message constructor; global handler adds @ExceptionHandler(StaffNotFoundException.class) returning a 404 response body map.
Data Transfer & Models
src/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.java, src/main/java/org/example/cyberwatch/features/ticket/model/Ticket.java
Added AssignTicketDTO with validated staffId; Ticket gains a @ManyToOne assignee field and getter/setter.
Controller & Service
src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java, src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java
New PUT /api/tickets/{ticketId}/assign endpoint (admin-only) using AssignTicketDTO; TicketService injects StaffRepository and implements assignTicketToStaff to validate existence, set assignee, update status to IN_PROGRESS, and save.
Security / Config
src/main/java/org/example/cyberwatch/config/SecurityConfig.java
Added @Configuration and @EnableMethodSecurity annotations to enable method-level security.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Controller as TicketController
    participant Service as TicketService
    participant TRepo as TicketRepository
    participant SRepo as StaffRepository
    participant DB as Database

    Client->>Controller: PUT /api/tickets/{ticketId}/assign (AssignTicketDTO)
    Controller->>Service: assignTicketToStaff(ticketId, staffId)
    Service->>TRepo: findById(ticketId)
    TRepo->>DB: SELECT ticket
    DB-->>TRepo: Ticket or null
    TRepo-->>Service: Optional<Ticket>
    alt Ticket not found
        Service-->>Controller: TicketNotFoundException
        Controller-->>Client: 404 Not Found
    end
    Service->>SRepo: findById(staffId)
    SRepo->>DB: SELECT staff
    DB-->>SRepo: Staff or null
    SRepo-->>Service: Optional<Staff>
    alt Staff not found
        Service-->>Controller: StaffNotFoundException
        Controller-->>Client: 404 Not Found
    end
    Service->>Service: ticket.setAssignee(staff)\nticket.setStatus(IN_PROGRESS)
    Service->>TRepo: save(ticket)
    TRepo->>DB: UPDATE ticket
    DB-->>TRepo: Updated Ticket
    TRepo-->>Service: Ticket
    Service-->>Controller: Ticket
    Controller-->>Client: 200 OK (Ticket)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • codebyNorthsteep
  • alicewersen-rgb
  • gitnes94

Poem

🐰
I hopped a ticket to a friend,
Assigned with care from start to end,
Status climbed to "In Progress" bright,
Staff found (or not) — I set it right,
Hooray — the workflow's light and merry!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feature/assign ticket to staff' directly and concisely describes the main change: adding functionality to assign tickets to staff members, which aligns with all the modifications in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 feature/assign-ticket-to-staff

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: 3

🤖 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/controller/TicketController.java`:
- Around line 31-37: Add method-level authorization to restrict the assign
endpoint: annotate the TicketController.assignTicketToStaff method with
`@PreAuthorize`("hasRole('ADMIN')") so only admins can call it; additionally
enable method security processing by annotating the SecurityConfig class with
`@EnableMethodSecurity` (or the legacy `@EnableGlobalMethodSecurity`) and ensure the
SecurityConfig is completed so Spring processes `@PreAuthorize` annotations.

In
`@src/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.java`:
- Line 5: AssignTicketDTO currently allows null/negative staffId; add
javax.validation constraints by annotating the staffId field in AssignTicketDTO
with `@NotNull` and `@Positive` and import the corresponding
javax.validation.constraints types, and in TicketController add `@Valid` to the
`@RequestBody` parameter of the assignTicketToStaff method so Spring validates the
payload before invoking the service.

In `@src/main/java/org/example/cyberwatch/features/ticket/model/Ticket.java`:
- Around line 25-27: The Ticket entity adds a new persisted field assignee
(private Staff assignee) which creates a new assignee_id column; add a versioned
DB migration (e.g., Vxxx__add_ticket_assignee.sql) that adds the assignee_id
BIGINT NULL column and creates the foreign key constraint to staff(id)
(fk_ticket_assignee) so production schemas stay in sync when Hibernate
auto-update is disabled; ensure the migration filename follows the project's
migration numbering and include both the ALTER TABLE ... ADD COLUMN assignee_id
and ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY statements.
🪄 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: 037d1928-45b6-4f05-a652-055527680fb6

📥 Commits

Reviewing files that changed from the base of the PR and between 817f1a4 and 987fd6e.

📒 Files selected for processing (6)
  • src/main/java/org/example/cyberwatch/exception/GlobalExceptionHandler.java
  • src/main/java/org/example/cyberwatch/features/staff/exception/StaffNotFoundException.java
  • src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.java
  • src/main/java/org/example/cyberwatch/features/ticket/model/Ticket.java
  • src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java

@codebyNorthsteep codebyNorthsteep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GG

@Ericthilen
Ericthilen merged commit e481f13 into main Apr 2, 2026
1 check passed
This was referenced Apr 14, 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.

2 participants