Feature/assign ticket to staff - #26
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
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
📒 Files selected for processing (6)
src/main/java/org/example/cyberwatch/exception/GlobalExceptionHandler.javasrc/main/java/org/example/cyberwatch/features/staff/exception/StaffNotFoundException.javasrc/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.javasrc/main/java/org/example/cyberwatch/features/ticket/model/AssignTicketDTO.javasrc/main/java/org/example/cyberwatch/features/ticket/model/Ticket.javasrc/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java
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.
Summary by CodeRabbit