Skip to content

Feature/changestatus#85

Merged
HerrKanin merged 5 commits into
mainfrom
feature/changestatus
Apr 14, 2026
Merged

Feature/changestatus#85
HerrKanin merged 5 commits into
mainfrom
feature/changestatus

Conversation

@HerrKanin

@HerrKanin HerrKanin commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Admins can now update incident status directly from the admin panel using an interactive dropdown selector, replacing the static status display.
    • Status changes automatically notify the original incident creator when applicable.
    • All incident status changes are recorded in the activity log for audit and tracking purposes.

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@HerrKanin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 49 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 43 minutes and 49 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: b3330ee2-bbc9-4dd6-a0be-0e5c10661e68

📥 Commits

Reviewing files that changed from the base of the PR and between d163164 and cfbb161.

📒 Files selected for processing (3)
  • src/main/java/org/example/team6backend/incident/controller/IncidentController.java
  • src/main/java/org/example/team6backend/incident/service/IncidentService.java
  • src/main/resources/templates/admin.html
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Backend API Endpoint
src/main/java/org/example/team6backend/incident/controller/IncidentController.java
New ADMIN-only PATCH endpoint at /{incidentId}/status that accepts UpdateIncidentStatusRequest and delegates to service layer for status updates.
Request DTO
src/main/java/org/example/team6backend/incident/dto/UpdateIncidentStatusRequest.java
New public record with single @NotNull validated status field of type IncidentStatus for request payload validation.
Service Layer Logic
src/main/java/org/example/team6backend/incident/service/IncidentService.java
New transactional updateIncidentStatus() method that persists status changes, records activity logs (STATUS_CHANGED), creates creator notifications when status changes, and reloads incident with documents before returning.
Frontend UI & Scripts
src/main/resources/templates/admin.html
Replaced static incident status badges with interactive <select> dropdown; added CSS styling for status colors and dropdown interactions; introduced updateIncidentStatus(incidentId, newStatus) client function that PATCHes the backend and reloads data on success.

Sequence Diagram

sequenceDiagram
    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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Admins now click dropdowns to adjust incident ways,
Status updates hop along with activity displays,
Creators receive notifications when changes occur,
A transactional dance where all records softly blur! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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/changestatus' is vague and does not clearly convey the specific functionality being added. Use a more descriptive title such as 'Add PATCH endpoint to update incident status' or 'Implement incident status update feature with notifications' to clearly communicate the main change.
✅ 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/changestatus

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

🧹 Nitpick comments (1)
src/main/java/org/example/team6backend/incident/service/IncidentService.java (1)

201-209: Use displayName in status-change messages.

oldStatus and newStatus render as enum constants like IN_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

📥 Commits

Reviewing files that changed from the base of the PR and between bb46927 and d163164.

📒 Files selected for processing (4)
  • src/main/java/org/example/team6backend/incident/controller/IncidentController.java
  • src/main/java/org/example/team6backend/incident/dto/UpdateIncidentStatusRequest.java
  • src/main/java/org/example/team6backend/incident/service/IncidentService.java
  • src/main/resources/templates/admin.html

Comment thread src/main/java/org/example/team6backend/incident/service/IncidentService.java Outdated
Comment thread src/main/resources/templates/admin.html
@HerrKanin
HerrKanin merged commit 07871b9 into main Apr 14, 2026
3 checks passed
@kristinaxm
kristinaxm deleted the feature/changestatus branch April 23, 2026 17:30
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