Skip to content

Refactor/rest api fetch js#99

Closed
kristinaxm wants to merge 2 commits into
mainfrom
refactor/rest-api-fetch-js
Closed

Refactor/rest api fetch js#99
kristinaxm wants to merge 2 commits into
mainfrom
refactor/rest-api-fetch-js

Conversation

@kristinaxm

@kristinaxm kristinaxm commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • File attachment support when creating incidents
    • Document deletion functionality
    • Enhanced document metadata display (file type, size)
  • Improvements

    • Standardized HTTP response codes (201 Created for new resources)
    • Improved UI responsiveness with client-side rendering
    • Better user navigation and sign-out flow
    • Enhanced comment submission response with confirmation data
  • Bug Fixes

    • Improved user account deletion with proper cascade handling

@kristinaxm kristinaxm self-assigned this Apr 23, 2026
@kristinaxm kristinaxm closed this Apr 23, 2026
@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 77557106-32c2-489f-9f09-a0831e1548d2

📥 Commits

Reviewing files that changed from the base of the PR and between 8e74b47 and 2a5f3aa.

📒 Files selected for processing (19)
  • src/main/java/org/example/team6backend/activity/controller/ActivityLogController.java
  • src/main/java/org/example/team6backend/comment/controller/CommentController.java
  • src/main/java/org/example/team6backend/config/SecurityConfig.java
  • src/main/java/org/example/team6backend/document/controller/DocumentController.java
  • src/main/java/org/example/team6backend/document/dto/DocumentDTO.java
  • src/main/java/org/example/team6backend/document/repository/DocumentRepository.java
  • src/main/java/org/example/team6backend/document/service/DocumentService.java
  • src/main/java/org/example/team6backend/incident/controller/IncidentController.java
  • src/main/java/org/example/team6backend/incident/dto/IncidentRequest.java
  • src/main/java/org/example/team6backend/notification/controller/NotificationController.java
  • src/main/java/org/example/team6backend/user/service/UserService.java
  • src/main/resources/static/admin.html
  • src/main/resources/static/createincident.html
  • src/main/resources/static/dashboard.html
  • src/main/resources/static/incidents.html
  • src/main/resources/static/index.html
  • src/main/resources/static/profile.html
  • src/main/resources/static/viewincident.html
  • src/test/java/org/example/team6backend/notification/controller/NotificationControllerTest.java

📝 Walkthrough

Walkthrough

Refactors controllers with Lombok dependency injection and structured logging while standardizing endpoint responses to ResponseEntity. Converts frontend from server-side Thymeleaf rendering to static HTML with client-side API calls. Updates endpoint behaviors (201 status codes, response body changes), refactors security authorization rules, adds document deletion endpoint, and enhances UserService cascade deletion logic using native SQL.

Changes

Cohort / File(s) Summary
Controllers - Lombok & Response Standardization
src/main/java/org/example/team6backend/.../controller/{ActivityLogController, CommentController, NotificationController}.java
Added @RequiredArgsConstructor and @Slf4j annotations, replacing explicit constructors and adding structured request logging. Updated method return types to ResponseEntity with ResponseEntity.ok(...) wrappers and appropriate HTTP status codes (e.g., CommentController.createComment now returns 201 CREATED with CommentResponse body).
DocumentController
src/main/java/org/example/team6backend/document/controller/DocumentController.java
Changed base mapping from "/api/documents" to "/documents", added Lombok annotations. Updated uploadFile to return 201 CREATED with List<DocumentDTO>. Replaced downloadFile endpoint with new deleteFile endpoint returning 204 NO_CONTENT. Added logging and document metadata extraction logic.
IncidentController
src/main/java/org/example/team6backend/incident/controller/IncidentController.java
Added @RequiredArgsConstructor and @Slf4j. Introduced new multipart file upload endpoint (POST /api/incidents with MULTIPART_FORM_DATA). Standardized all endpoints to return ResponseEntity with 201 CREATED for create operations. Added structured logging throughout.
DocumentDTO, Repository & Service
src/main/java/org/example/team6backend/document/{dto/DocumentDTO.java, repository/DocumentRepository.java, service/DocumentService.java}
DocumentDTO updated with new fields contentType, fileSize. DocumentRepository adds findByIncidentId(Long) query. DocumentService adds @Transactional to uploadFile, reorders deletion logic (database before Minio), adds getById and getDocumentsByIncidentId methods.
IncidentRequest
src/main/java/org/example/team6backend/incident/dto/IncidentRequest.java
Whitespace/formatting adjustment only; no signature changes.
SecurityConfig
src/main/java/org/example/team6backend/config/SecurityConfig.java
Refactored authorization rules from legacy matcher/role sequencing to authorizeHttpRequests chain. Updated public endpoints ("/index.html", "/css/**", "/js/**", "/images/**"), added role-based rules for "/api/incidents/**", "/api/admin/**", added authentication for new protected routes ("/comments/**", "/activity/**", "/documents/**"). Updated CSRF ignore configuration.
UserService
src/main/java/org/example/team6backend/user/service/UserService.java
Enhanced deleteUser with cascade deletion logic using injected EntityManager and native SQL statements to nullify incident/comment references and delete dependent activity logs and notifications before user deletion. Added debug logging per native operation.
NotificationControllerTest
src/test/java/org/example/team6backend/notification/controller/NotificationControllerTest.java
Updated test assertions to verify ResponseEntity returns with HttpStatus.OK and validated response bodies. Added test for empty notification list scenario.
Frontend - Thymeleaf to Client-Side Migration
src/main/resources/static/{admin.html, createincident.html, dashboard.html, incidents.html, index.html, profile.html, viewincident.html}
Converted all frontend pages from server-side Thymeleaf rendering to static HTML with client-side logic. Pages now fetch user info from /api/users/me endpoint, dynamically populate user-specific UI elements, and handle role-based navigation. Simplified HTML/CSS (removed Thymeleaf bindings, server-side conditionals, gradients), updated JavaScript to use modern DOM APIs and fetch() for data loading. Removed role-switching dev utilities and inactive/pending account UI.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Poem

🐰 Hops through the refactor with glee,
Lombok brings clarity, controllers run free,
From server to client, the pages now dance,
ResponseEntity gives all a second chance,
With cascade deletions and security bright,
This rabbit says "code compiles just right!" ✨

✨ 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 refactor/rest-api-fetch-js

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.

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