-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add manual admin assignment for PENDING tickets #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/ucms_backend/dto/AssignTicketRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.ucms_backend.dto; | ||
|
|
||
| import java.util.UUID; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class AssignTicketRequest { | ||
|
|
||
| private UUID adminId; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.ucms_backend.service; | ||
|
|
||
| import com.ucms_backend.dto.AssignTicketRequest; | ||
| import com.ucms_backend.dto.CreateTicketRequest; | ||
| import com.ucms_backend.dto.RealtimeEventResponse; | ||
| import com.ucms_backend.dto.TicketResponse; | ||
|
|
@@ -71,20 +72,30 @@ private String resolveCategoryName(Long categoryId) { | |
| .orElse(null); | ||
| } | ||
|
|
||
| private String resolveAdminName(UUID adminId) { | ||
| if (adminId == null) return null; | ||
| return profileRepository.findById(adminId) | ||
| .map(Profile::getName) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| private TicketResponse toResponse(Ticket ticket) { | ||
| boolean hasAdminResponse = ticketResponseRepository.existsByTicketId(ticket.getId()); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), null, hasAdminResponse); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), null, hasAdminResponse, | ||
| resolveAdminName(ticket.getAssignedAdminId())); | ||
| } | ||
|
|
||
| private TicketResponse toResponse(Ticket ticket, Set<Long> ticketIdsWithResponses) { | ||
| boolean hasAdminResponse = ticketIdsWithResponses.contains(ticket.getId()); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), null, hasAdminResponse); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), null, hasAdminResponse, | ||
| resolveAdminName(ticket.getAssignedAdminId())); | ||
| } | ||
|
|
||
| private TicketResponse toDetailedResponse(Ticket ticket) { | ||
| Profile studentProfile = profileRepository.findById(ticket.getUserId()).orElse(null); | ||
| boolean hasAdminResponse = ticketResponseRepository.existsByTicketId(ticket.getId()); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), studentProfile, hasAdminResponse); | ||
| return TicketResponse.from(ticket, resolveCategoryName(ticket.getCategoryId()), studentProfile, hasAdminResponse, | ||
| resolveAdminName(ticket.getAssignedAdminId())); | ||
| } | ||
|
|
||
| private void applyUrgency(Ticket ticket) { | ||
|
|
@@ -337,6 +348,37 @@ public TicketResponse confirmResolved(Long ticketId) { | |
| return toResponse(saved); | ||
| } | ||
|
|
||
| public TicketResponse assignAdmin(Long ticketId, AssignTicketRequest request) { | ||
| Ticket ticket = ticketRepository.findById(ticketId) | ||
| .orElseThrow(() -> new AppException(404, "TICKET_NOT_FOUND", "Ticket not found")); | ||
|
|
||
| if (ticket.getStatus() != TicketStatus.PENDING) { | ||
| throw new AppException(409, "INVALID_ASSIGNMENT", "Can only assign admin to PENDING tickets"); | ||
| } | ||
|
|
||
| UUID targetAdminId = (request.getAdminId() != null) | ||
| ? request.getAdminId() | ||
| : SecurityUtils.getCurrentUserId(); | ||
|
|
||
| Profile admin = profileRepository.findById(targetAdminId) | ||
| .orElseThrow(() -> new AppException(404, "ADMIN_NOT_FOUND", "Admin not found")); | ||
|
|
||
| if (!"ADMIN".equals(admin.getRole())) { | ||
| throw new AppException(400, "INVALID_ADMIN", "Target user is not an admin"); | ||
| } | ||
|
|
||
| ticket.setAssignedAdminId(targetAdminId); | ||
| Ticket saved = ticketRepository.save(ticket); | ||
|
|
||
| notificationService.createNotification( | ||
| targetAdminId, | ||
| saved.getId(), | ||
| "You have been assigned ticket #" + saved.getTicketNumber() | ||
| ); | ||
|
|
||
| return toDetailedResponse(saved); | ||
| } | ||
|
Comment on lines
+351
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Publish a realtime ticket event after admin assignment.
Suggested fix ticket.setAssignedAdminId(targetAdminId);
Ticket saved = ticketRepository.save(ticket);
+ publishTicketEvent(saved, "TICKET_ASSIGNED", "ADMIN");
notificationService.createNotification(
targetAdminId,
saved.getId(),
"You have been assigned ticket #" + saved.getTicketNumber()
);🤖 Prompt for AI Agents |
||
|
|
||
| public TicketResponse updateStatus(Long id, UpdateStatusRequest request) { | ||
| Ticket ticket = ticketRepository.findById(id) | ||
| .orElseThrow(() -> new AppException(404, "TICKET_NOT_FOUND", "Ticket not found")); | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
src/main/resources/db/migration/V13__add_ticket_assigned_admin.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ALTER TABLE ticket | ||
| ADD COLUMN assigned_admin_id UUID REFERENCES profile(auth_user_id); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid N+1 profile queries when populating
assignedAdminName.Lines [75-79] are called from list mapping paths (Lines [84-85], [90-91], [97-98]), causing one
profileRepository.findById(...)per ticket. This will degrade admin ticket-list performance.Refactor direction (batch-resolve admin names)
Then pass the map into list mappers instead of calling
findByIdper ticket.🤖 Prompt for AI Agents