-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/view incident #71
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
9 commits
Select commit
Hold shift + click to select a range
6927618
Added navigation from incidents list to incident details page.
HerrKanin 4f210fe
now possible to view all incidents on /incidents and then view a spec…
HerrKanin 414a62a
add comments with user and timestamp to incident view
HerrKanin 5366dba
Spotless fix
HerrKanin e2bf431
Merge branch 'main' into feature/view-incident
HerrKanin c096da7
fixed duplicated code in pagecontroller
HerrKanin 4df1fff
fix: Critical XSS vulnerability: User input rendered via innerHTML wi…
HerrKanin d5c3505
Feedback from coderabbit fixed Restore the per-incident authorization…
HerrKanin 9a4bd89
added activity log for incident created and comments
HerrKanin 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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/example/team6backend/activity/controller/ActivityLogController.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,30 @@ | ||
| package org.example.team6backend.activity.controller; | ||
|
|
||
| import org.example.team6backend.activity.dto.ActivityLogResponse; | ||
| import org.example.team6backend.activity.service.ActivityLogService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/activity") | ||
| public class ActivityLogController { | ||
|
|
||
| private final ActivityLogService activityLogService; | ||
|
|
||
| public ActivityLogController(ActivityLogService activityLogService) { | ||
| this.activityLogService = activityLogService; | ||
| } | ||
|
|
||
| @GetMapping("/incident/{incidentId}") | ||
| public ResponseEntity<List<ActivityLogResponse>> getActivityByIncidentId(@PathVariable Long incidentId) { | ||
| List<ActivityLogResponse> activityLogs = activityLogService.getByIncidentId(incidentId).stream() | ||
| .map(ActivityLogResponse::fromEntity).toList(); | ||
|
|
||
| return ResponseEntity.ok(activityLogs); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/example/team6backend/activity/dto/ActivityLogResponse.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,53 @@ | ||
| package org.example.team6backend.activity.dto; | ||
|
|
||
| import org.example.team6backend.activity.entity.ActivityLog; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| public class ActivityLogResponse { | ||
|
|
||
| private String action; | ||
| private String description; | ||
| private LocalDateTime createdAt; | ||
| private String userName; | ||
|
|
||
| public static ActivityLogResponse fromEntity(ActivityLog activityLog) { | ||
| ActivityLogResponse response = new ActivityLogResponse(); | ||
| response.setAction(activityLog.getAction()); | ||
| response.setDescription(activityLog.getDescription()); | ||
| response.setCreatedAt(activityLog.getCreatedAt()); | ||
| response.setUserName(activityLog.getUser() != null ? activityLog.getUser().getName() : "Unknow user"); | ||
| return response; | ||
| } | ||
|
|
||
| public String getAction() { | ||
| return action; | ||
| } | ||
|
|
||
| public void setAction(String action) { | ||
| this.action = action; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public LocalDateTime getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| public void setCreatedAt(LocalDateTime createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
|
|
||
| public String getUserName() { | ||
| return userName; | ||
| } | ||
|
|
||
| public void setUserName(String userName) { | ||
| this.userName = userName; | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
src/main/java/org/example/team6backend/activity/entity/ActivityLog.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,81 @@ | ||
| package org.example.team6backend.activity.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import org.example.team6backend.incident.entity.Incident; | ||
| import org.example.team6backend.user.entity.AppUser; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Table(name = "activity_log") | ||
| public class ActivityLog { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private String action; | ||
| private String description; | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "incident_id", nullable = false) | ||
| private Incident incident; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "user_id", nullable = false) | ||
| private AppUser user; | ||
|
|
||
| @PrePersist | ||
| void onCreated() { | ||
| createdAt = LocalDateTime.now(); | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getAction() { | ||
| return action; | ||
| } | ||
|
|
||
| public void setAction(String action) { | ||
| this.action = action; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public LocalDateTime getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| public void setCreatedAt(LocalDateTime createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
|
|
||
| public Incident getIncident() { | ||
| return incident; | ||
| } | ||
|
|
||
| public void setIncident(Incident incident) { | ||
| this.incident = incident; | ||
| } | ||
|
|
||
| public AppUser getUser() { | ||
| return user; | ||
| } | ||
|
|
||
| public void setUser(AppUser user) { | ||
| this.user = user; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/example/team6backend/activity/repository/ActivityLogRepository.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,10 @@ | ||
| package org.example.team6backend.activity.repository; | ||
|
|
||
| import org.example.team6backend.activity.entity.ActivityLog; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ActivityLogRepository extends JpaRepository<ActivityLog, Long> { | ||
| List<ActivityLog> findByIncidentIdOrderByCreatedAtDesc(Long incidentId); | ||
| } |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/example/team6backend/activity/service/ActivityLogService.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,33 @@ | ||
| package org.example.team6backend.activity.service; | ||
|
|
||
| import org.example.team6backend.activity.entity.ActivityLog; | ||
| import org.example.team6backend.activity.repository.ActivityLogRepository; | ||
| import org.example.team6backend.incident.entity.Incident; | ||
| import org.example.team6backend.user.entity.AppUser; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class ActivityLogService { | ||
|
|
||
| private final ActivityLogRepository activityLogRepository; | ||
|
|
||
| public ActivityLogService(ActivityLogRepository activityLogRepository) { | ||
| this.activityLogRepository = activityLogRepository; | ||
| } | ||
|
|
||
| public ActivityLog log(String action, String description, Incident incident, AppUser user) { | ||
| ActivityLog activityLog = new ActivityLog(); | ||
| activityLog.setAction(action); | ||
| activityLog.setDescription(description); | ||
| activityLog.setIncident(incident); | ||
| activityLog.setUser(user); | ||
|
|
||
| return activityLogRepository.save(activityLog); | ||
| } | ||
|
|
||
| public List<ActivityLog> getByIncidentId(Long incidentId) { | ||
| return activityLogRepository.findByIncidentIdOrderByCreatedAtDesc(incidentId); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Handle validation errors and null
incidentIdgracefully.Two concerns with the redirect flow:
Validation errors: If
@Validfails (e.g., empty message), Spring throwsMethodArgumentNotValidException, likely showing a Whitelabel error page without a global handler.Null safety: If
request.getIncidentId()is null (malformed form submission), the string concatenation on line 33 would produceredirect:/incidents/null.🛡️ Suggested improvement
You'd also need to import
org.springframework.validation.BindingResult.🤖 Prompt for AI Agents