-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement Attachment entity and repository #29
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
8 commits
Select commit
Hold shift + click to select a range
50d0aac
feat: implement Attachment entity and repository
johanbriger 8345334
refactor: add database-level cascade delete for medical records
johanbriger acbfd1c
refactor: add attachment collection and cascading to MedicalRecord
johanbriger 6d30689
refactor: add uploadedAttachments relation to User entity
johanbriger 519c346
refactor: enforce bidirectional invariant for User attachments(CodeRa…
johanbriger 23907a9
Final fixes from CodeRabbit Suggestions.
johanbriger c6e0488
Final fixes from CodeRabbit Suggestions part 2.
johanbriger d900ace
Merge branch 'main' into Implement-attachment-entity-and-repository
johanbriger 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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/example/vet1177/entities/Attachment.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,98 @@ | ||
| package org.example.vet1177.entities; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import org.hibernate.annotations.OnDelete; | ||
| import org.hibernate.annotations.OnDeleteAction; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| @Entity | ||
| @Table(name = "attachment") | ||
| public class Attachment { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| private UUID id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "record_id", nullable = false) | ||
| @OnDelete(action = OnDeleteAction.CASCADE) | ||
| private MedicalRecord medicalRecord; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "uploaded_by", nullable = true) | ||
| @OnDelete(action = OnDeleteAction.SET_NULL) | ||
| private User uploadedBy; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Column(name = "file_name", nullable = false, length = 500) | ||
| private String fileName; | ||
|
|
||
| // Den unika nyckeln/sökvägen i S3-bucket | ||
| @Column(name = "s3_key", nullable = false, unique = true, length = 1000) | ||
| private String s3Key; | ||
|
|
||
| @Column(name = "s3_bucket", nullable = false, length = 255) | ||
| private String s3Bucket; | ||
|
|
||
| @Column(name = "file_type", length = 100) | ||
| private String fileType; | ||
|
|
||
| @Column(name = "file_size_bytes") | ||
| private Long fileSizeBytes; | ||
|
|
||
| @Column(name = "uploaded_at", nullable = false, updatable = false) | ||
| private Instant uploadedAt; | ||
|
|
||
| public Attachment() { | ||
| } | ||
|
|
||
| @PrePersist | ||
| protected void onCreate() { | ||
| this.uploadedAt = Instant.now(); | ||
| } | ||
|
|
||
| // Getters och Setters | ||
| public UUID getId() { return id; } | ||
|
|
||
| public MedicalRecord getMedicalRecord() { return medicalRecord; } | ||
|
|
||
| public void setMedicalRecord(MedicalRecord medicalRecord) { | ||
| this.medicalRecord = medicalRecord; } | ||
|
|
||
| public User getUploadedBy() { | ||
| return uploadedBy; } | ||
|
|
||
| public void setUploadedBy(User uploadedBy) { | ||
| this.uploadedBy = uploadedBy; } | ||
|
|
||
| public String getFileName() { | ||
| return fileName; } | ||
|
|
||
| public void setFileName(String fileName) { | ||
| this.fileName = fileName; } | ||
|
|
||
| public String getS3Key() { | ||
| return s3Key; } | ||
|
|
||
| public void setS3Key(String s3Key) { | ||
| this.s3Key = s3Key; } | ||
|
|
||
| public String getS3Bucket() { | ||
| return s3Bucket; } | ||
|
|
||
| public void setS3Bucket(String s3Bucket) { | ||
| this.s3Bucket = s3Bucket; } | ||
|
|
||
| public String getFileType() { return fileType; } | ||
| public void setFileType(String fileType) { this.fileType = fileType; } | ||
|
|
||
| public Long getFileSizeBytes() { | ||
| return fileSizeBytes; } | ||
|
|
||
| public void setFileSizeBytes(Long fileSizeBytes) { | ||
| this.fileSizeBytes = fileSizeBytes; } | ||
|
|
||
| public Instant getUploadedAt() { | ||
| return uploadedAt; } | ||
| } | ||
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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/example/vet1177/repository/AttachmentRepository.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,19 @@ | ||
| package org.example.vet1177.repository; | ||
|
|
||
| import org.example.vet1177.entities.Attachment; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| @Repository | ||
| public interface AttachmentRepository extends JpaRepository<Attachment, UUID> { | ||
|
|
||
| List<Attachment> findByMedicalRecordId(UUID recordId); | ||
|
|
||
| List<Attachment> findByUploadedById(UUID userId); | ||
|
|
||
| Optional<Attachment> findByS3Key(String s3Key); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.