Feature/changestatus#85
Conversation
|
Warning Rate limit exceeded
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 43 minutes and 49 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes introduce an admin-restricted PATCH endpoint for updating incident status. A new request DTO validates the status field. The service layer persists updates, logs activity changes, and optionally notifies the incident creator. The frontend UI replaces static status badges with an interactive dropdown selector and corresponding update function. Changes
Sequence DiagramsequenceDiagram
participant Admin as Admin User
participant Controller as IncidentController
participant Service as IncidentService
participant DB as Database
participant ActivityLog as Activity Log
participant NotifService as Notification Service
Admin->>Controller: PATCH /api/incidents/{id}/status
Controller->>Service: updateIncidentStatus(id, newStatus, admin)
Service->>DB: Find Incident by ID
DB-->>Service: Incident
alt Status Changed
Service->>DB: Update status & timestamp
Service->>ActivityLog: Record STATUS_CHANGED
alt Creator Exists & Not Current User
Service->>NotifService: Create notification for creator
NotifService-->>Service: Notification queued
end
end
Service->>DB: Reload Incident with Documents
DB-->>Service: Updated Incident
Service-->>Controller: Incident
Controller-->>Admin: IncidentResponse (200 OK)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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: 2
🧹 Nitpick comments (1)
src/main/java/org/example/team6backend/incident/service/IncidentService.java (1)
201-209: UsedisplayNamein status-change messages.
oldStatusandnewStatusrender as enum constants likeIN_PROGRESS. The enum already carries human-readable labels, so the activity log and notification text can be cleaner.✨ Suggested polish
activityLogService.log("STATUS_CHANGED", - currentUser.getName() + " changed status from " + oldStatus + " to " + newStatus, savedIncident, + currentUser.getName() + " changed status from " + oldStatus.getDisplayName() + " to " + + newStatus.getDisplayName(), + savedIncident, currentUser); if (savedIncident.getCreatedBy() != null && !savedIncident.getCreatedBy().getId().equals(currentUser.getId())) { notificationService.createNotification( - "Your incident status was changed from " + oldStatus + " to " + newStatus, + "Your incident status was changed from " + oldStatus.getDisplayName() + " to " + + newStatus.getDisplayName(), savedIncident.getCreatedBy(), savedIncident); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/example/team6backend/incident/service/IncidentService.java` around lines 201 - 209, The activity log and notification currently use raw enum values oldStatus and newStatus (e.g., IN_PROGRESS); update the message construction in IncidentService where activityLogService.log(...) and notificationService.createNotification(...) are called to use the enum's human-readable label (e.g., oldStatus.getDisplayName() and newStatus.getDisplayName() or savedIncident.getStatus().getDisplayName() as appropriate) instead of the enum constant names, so both the activity entry and the notification read the displayName strings; keep the same message templates and users (currentUser.getName(), savedIncident.getCreatedBy()) but replace oldStatus/newStatus with their displayName accessors.
🤖 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/team6backend/incident/service/IncidentService.java`:
- Around line 190-199: The code mutates updatedAt and persists even when
newStatus equals the current status; move the equality check (compare oldStatus
and newStatus) to before you call incident.setIncidentStatus(...),
setUpdatedAt(...), and incidentRepository.save(...), and if they are the same
return the existing incident using the same return shape as the change path
(i.e., return the incident found by findByIdWithDocuments(...) or simply return
the current incident) so no DB write or updatedAt change occurs; update the
logic in IncidentService around the oldStatus/newStatus check and the
incidentRepository.save call accordingly.
In `@src/main/resources/templates/admin.html`:
- Around line 1316-1318: The select loses the original value on change because
the handler only receives the new value; modify the HTML to capture the element
and its prior value (e.g., add onfocus="this.dataset.prev=this.value" and change
onchange to call updateIncidentStatus(this, ${incident.id}) or similar), then
update the updateIncidentStatus function to accept the select element, perform
the PATCH, and on any failure set select.value = select.dataset.prev and restore
any related UI (CSS class like status-select / status-<...>) before showing the
toast; apply the same pattern to the other affected select instances referenced
around lines 1474-1492.
---
Nitpick comments:
In
`@src/main/java/org/example/team6backend/incident/service/IncidentService.java`:
- Around line 201-209: The activity log and notification currently use raw enum
values oldStatus and newStatus (e.g., IN_PROGRESS); update the message
construction in IncidentService where activityLogService.log(...) and
notificationService.createNotification(...) are called to use the enum's
human-readable label (e.g., oldStatus.getDisplayName() and
newStatus.getDisplayName() or savedIncident.getStatus().getDisplayName() as
appropriate) instead of the enum constant names, so both the activity entry and
the notification read the displayName strings; keep the same message templates
and users (currentUser.getName(), savedIncident.getCreatedBy()) but replace
oldStatus/newStatus with their displayName accessors.
🪄 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: 26fc67a9-4531-4329-a470-23df59035971
📒 Files selected for processing (4)
src/main/java/org/example/team6backend/incident/controller/IncidentController.javasrc/main/java/org/example/team6backend/incident/dto/UpdateIncidentStatusRequest.javasrc/main/java/org/example/team6backend/incident/service/IncidentService.javasrc/main/resources/templates/admin.html
Summary by CodeRabbit