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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<artifactId>spring-boot-docker-compose</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.vet1177.dto.request.comment;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.UUID;

public record CreateCommentRequest(

@NotNull(message = "Ärende måste anges")
UUID recordId,

@NotBlank(message = "Kommentar får inte vara tom")
@Size(max = 5000, message = "Kommentar får max vara 5000 tecken")
String body

) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.vet1177.dto.request.comment;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record UpdateCommentRequest(

@NotBlank(message = "Kommentar får inte vara tom")
@Size(max = 5000, message = "Kommentar får max vara 5000 tecken")
String body

) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.example.vet1177.dto.response.comment;

import org.example.vet1177.entities.Comment;
import java.time.Instant;
import java.util.UUID;

public record CommentResponse(
UUID id,
UUID recordId,
UUID authorId,
String authorName,
String body,
Instant createdAt,
Instant updatedAt
) {
public static CommentResponse from(Comment comment) {
return new CommentResponse(
comment.getId(),
comment.getMedicalRecord().getId(),
comment.getAuthor().getId(),
comment.getAuthor().getName(),
comment.getBody(),
comment.getCreatedAt(),
comment.getUpdatedAt()
);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/example/vet1177/entities/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class Comment {
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.REMOVE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "record_id", nullable = false)
private MedicalRecord medicalRecord;

@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.REMOVE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id", nullable = false)
private User author;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.vet1177.repository;

import org.example.vet1177.entities.Comment;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -11,9 +12,11 @@
public interface CommentRepository extends JpaRepository<Comment, UUID> {

// Alla kommentarer för ett ärende — sorterat äldst först
@EntityGraph(attributePaths = {"medicalRecord", "author"})
List<Comment> findByMedicalRecordIdOrderByCreatedAtAsc(UUID recordId);

// Alla kommentarer skrivna av en specifik användare
@EntityGraph(attributePaths = {"medicalRecord", "author"})
List<Comment> findByAuthorId(UUID authorId);

// Antal kommentarer på ett ärende
Expand Down