Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.example.team6backend.activity.dto;

import org.example.team6backend.activity.entity.ActivityLog;
import java.time.LocalDateTime;

import java.time.Instant;

public class ActivityLogResponse {

private String action;
private String description;
private LocalDateTime createdAt;
private Instant createdAt;
private String userName;

public static ActivityLogResponse fromEntity(ActivityLog activityLog) {
Expand Down Expand Up @@ -35,11 +36,11 @@ public void setDescription(String description) {
this.description = description;
}

public LocalDateTime getCreatedAt() {
public Instant getCreatedAt() {
return createdAt;
}

public void setCreatedAt(LocalDateTime createdAt) {
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.example.team6backend.incident.entity.Incident;
import org.example.team6backend.user.entity.AppUser;

import java.time.LocalDateTime;
import java.time.Instant;

@Entity
@Table(name = "activity_log")
Expand All @@ -16,7 +16,7 @@ public class ActivityLog {

private String action;
private String description;
private LocalDateTime createdAt;
private Instant createdAt;

@ManyToOne
@JoinColumn(name = "incident_id", nullable = false)
Expand All @@ -28,7 +28,7 @@ public class ActivityLog {

@PrePersist
void onCreated() {
createdAt = LocalDateTime.now();
createdAt = Instant.now();
}

public Long getId() {
Expand All @@ -55,11 +55,11 @@ public void setDescription(String description) {
this.description = description;
}

public LocalDateTime getCreatedAt() {
public Instant getCreatedAt() {
return createdAt;
}

public void setCreatedAt(LocalDateTime createdAt) {
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.Valid;
import org.example.team6backend.comment.dto.CommentRequest;
import org.example.team6backend.comment.entity.Comment;
import org.example.team6backend.comment.dto.CommentResponse;
import org.example.team6backend.comment.service.CommentService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -22,8 +22,10 @@ public CommentController(CommentService commentService) {

@GetMapping("/incident/{incidentId}")
@ResponseBody
public ResponseEntity<List<Comment>> getCommentByIncidentId(@PathVariable Long incidentId) {
List<Comment> comments = commentService.getCommentByIncidentId(incidentId);
public ResponseEntity<List<CommentResponse>> getCommentByIncidentId(@PathVariable Long incidentId) {
List<CommentResponse> comments = commentService.getCommentByIncidentId(incidentId).stream()
.map(CommentResponse::fromEntity).toList();

return ResponseEntity.ok(comments);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.example.team6backend.comment.dto;

import org.example.team6backend.comment.entity.Comment;

import java.time.Instant;

public record CommentResponse(String id, String message, Instant createdAt, CommentUserResponse user

) {
public static CommentResponse fromEntity(Comment comment) {
return new CommentResponse(comment.getId(), comment.getMessage(), comment.getCreatedAt(),
comment.getUser() != null
? new CommentUserResponse(comment.getUser().getId(), comment.getUser().getName(),
comment.getUser().getEmail())
: null);
}

public record CommentUserResponse(String id, String name, String email) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.example.team6backend.incident.entity.Incident;
import org.example.team6backend.user.entity.AppUser;

import java.time.LocalDateTime;
import java.time.Instant;

@Entity
@Table(name = "comment")
Expand All @@ -30,11 +30,11 @@ public class Comment {
private AppUser user;

@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;
private Instant createdAt;

@PrePersist
protected void onCreated() {
createdAt = LocalDateTime.now();
createdAt = Instant.now();
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.example.team6backend.exception;
import java.time.LocalDateTime;
import java.time.Instant;

public class ErrorResponse {

private int status;
private String message;
private LocalDateTime timestamp;
private Instant timestamp;

public ErrorResponse(int status, String message, LocalDateTime timestamp) {
public ErrorResponse(int status, String message, Instant timestamp) {
this.status = status;
this.message = message;
this.timestamp = timestamp;
Expand All @@ -19,7 +19,7 @@ public int getStatus() {
public String getMessage() {
return message;
}
public LocalDateTime getTimestamp() {
public Instant getTimestamp() {
return timestamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.time.LocalDateTime;
import java.time.Instant;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ErrorResponse> handleAccessDeniedException(AccessDeniedException ex) {
ErrorResponse error = new ErrorResponse(HttpStatus.FORBIDDEN.value(),
"You do not have permission to access this resource!", LocalDateTime.now());
"You do not have permission to access this resource!", Instant.now());
return new ResponseEntity<>(error, HttpStatus.FORBIDDEN);
}

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFound(ResourceNotFoundException ex) {
ErrorResponse error = new ErrorResponse(HttpStatus.NOT_FOUND.value(), ex.getMessage(), LocalDateTime.now());
ErrorResponse error = new ErrorResponse(HttpStatus.NOT_FOUND.value(), ex.getMessage(), Instant.now());
return new ResponseEntity<>(error, HttpStatus.NOT_FOUND);
}

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<ErrorResponse> handleIllegalArgument(IllegalArgumentException ex) {
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), LocalDateTime.now());
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), Instant.now());
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(IllegalStateException.class)
public ResponseEntity<ErrorResponse> handleIllegalState(IllegalStateException ex) {
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), LocalDateTime.now());
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), Instant.now());
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGeneral(Exception ex) {
ex.printStackTrace();
ErrorResponse error = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Something went wrong!",
LocalDateTime.now());
Instant.now());
return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.example.team6backend.incident.entity.IncidentStatus;
import org.hibernate.Hibernate;

import java.time.LocalDateTime;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -21,7 +21,7 @@ public class IncidentResponse {
private IncidentCategory incidentCategory;
private String createdBy;
private String assignedTo;
private LocalDateTime createdAt;
private Instant createdAt;
private boolean hasDocuments;
private List<DocumentDTO> documents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import jakarta.persistence.*;
import org.example.team6backend.document.entity.Document;
import org.example.team6backend.user.entity.AppUser;
import java.time.LocalDateTime;

import java.time.Instant;
import java.util.List;

@Entity
Expand Down Expand Up @@ -36,23 +37,23 @@ public class Incident {
private AppUser assignedTo;

@Column(name = "created_at")
private LocalDateTime createdAt;
private Instant createdAt;

@Column(name = "updated_at")
private LocalDateTime updatedAt;
private Instant updatedAt;

@OneToMany(mappedBy = "incident", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Document> documents;

@PrePersist
protected void onCreate() {
createdAt = LocalDateTime.now();
updatedAt = LocalDateTime.now();
createdAt = Instant.now();
updatedAt = Instant.now();
}

@PreUpdate
protected void onUpdate() {
updatedAt = LocalDateTime.now();
updatedAt = Instant.now();
}

public Long getId() {
Expand Down Expand Up @@ -87,11 +88,11 @@ public AppUser getAssignedTo() {
return assignedTo;
}

public LocalDateTime getCreatedAt() {
public Instant getCreatedAt() {
return createdAt;
}

public LocalDateTime getUpdatedAt() {
public Instant getUpdatedAt() {
return updatedAt;
}

Expand Down Expand Up @@ -131,11 +132,11 @@ public void setAssignedTo(AppUser assignedTo) {
this.assignedTo = assignedTo;
}

public void setCreatedAt(LocalDateTime createdAt) {
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

public void setUpdatedAt(LocalDateTime updatedAt) {
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -74,8 +75,8 @@ public Incident createIncident(IncidentRequest incidentRequest, List<MultipartFi
incident.setIncidentCategory(incidentRequest.getIncidentCategory());
incident.setCreatedBy(user);
incident.setIncidentStatus(IncidentStatus.OPEN);
incident.setCreatedAt(LocalDateTime.now());
incident.setUpdatedAt(LocalDateTime.now());
incident.setCreatedAt(Instant.now());
incident.setUpdatedAt(Instant.now());

Incident savedIncident = incidentRepository.save(incident);

Expand Down Expand Up @@ -172,7 +173,7 @@ public Incident assignIncidentToHandler(Long incidentId, String handlerId, AppUs

AppUser oldHandler = incident.getAssignedTo();
incident.setAssignedTo(handler);
incident.setUpdatedAt(LocalDateTime.now());
incident.setUpdatedAt(Instant.now());

if (incident.getIncidentStatus() == IncidentStatus.OPEN) {
incident.setIncidentStatus(IncidentStatus.IN_PROGRESS);
Expand Down Expand Up @@ -208,7 +209,7 @@ public Incident updateIncidentStatus(Long incidentId, IncidentStatus newStatus,
}

incident.setIncidentStatus(newStatus);
incident.setUpdatedAt(LocalDateTime.now());
incident.setUpdatedAt(Instant.now());

Incident savedIncident = incidentRepository.save(incident);

Expand Down Expand Up @@ -245,7 +246,7 @@ public Incident unassignIncident(Long incidentId, AppUser currentUser) {
}

incident.setAssignedTo(null);
incident.setUpdatedAt(LocalDateTime.now());
incident.setUpdatedAt(Instant.now());

if (incident.getIncidentStatus() == IncidentStatus.IN_PROGRESS) {
incident.setIncidentStatus(IncidentStatus.OPEN);
Expand Down Expand Up @@ -285,7 +286,7 @@ public Incident closeIncident(Long incidentId, AppUser currentUser) {
IncidentStatus oldStatus = incident.getIncidentStatus();

incident.setIncidentStatus(IncidentStatus.CLOSED);
incident.setUpdatedAt(LocalDateTime.now());
incident.setUpdatedAt(Instant.now());

Incident savedIncident = incidentRepository.save(incident);

Expand Down Expand Up @@ -325,7 +326,7 @@ public Incident resolveIncident(Long incidentId, AppUser currentUser) {

IncidentStatus oldStatus = incident.getIncidentStatus();
incident.setIncidentStatus(IncidentStatus.RESOLVED);
incident.setUpdatedAt(LocalDateTime.now());
incident.setUpdatedAt(Instant.now());

Incident savedIncident = incidentRepository.save(incident);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.example.team6backend.notification.entity.Notification;

import java.time.LocalDateTime;
import java.time.Instant;

public class NotificationResponse {

private Long id;
private String message;
private Boolean read;
private LocalDateTime createdAt;
private Instant createdAt;
private Long incidentId;

public static NotificationResponse fromEntity(Notification notification) {
Expand Down Expand Up @@ -46,11 +46,11 @@ public void setRead(Boolean read) {
this.read = read;
}

public LocalDateTime getCreatedAt() {
public Instant getCreatedAt() {
return createdAt;
}

public void setCreatedAt(LocalDateTime createdAt) {
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

Expand Down
Loading
Loading