From c121d62fb45448f5c9ab42702cf130ccde82a9e0 Mon Sep 17 00:00:00 2001 From: Mika Bomm Date: Sun, 1 Sep 2024 17:29:23 +0200 Subject: [PATCH] Add interfaces for Document.java and User.java --- .../com/mixel/docusphere/entity/Document.java | 90 ++++++++++++++ .../com/mixel/docusphere/entity/User.java | 111 ++++++++++++++++++ .../repository/DocumentRepository.java | 8 ++ .../docusphere/repository/UserRepository.java | 8 ++ 4 files changed, 217 insertions(+) create mode 100644 server/src/main/java/com/mixel/docusphere/entity/Document.java create mode 100644 server/src/main/java/com/mixel/docusphere/entity/User.java create mode 100644 server/src/main/java/com/mixel/docusphere/repository/DocumentRepository.java create mode 100644 server/src/main/java/com/mixel/docusphere/repository/UserRepository.java diff --git a/server/src/main/java/com/mixel/docusphere/entity/Document.java b/server/src/main/java/com/mixel/docusphere/entity/Document.java new file mode 100644 index 0000000..a7f71c6 --- /dev/null +++ b/server/src/main/java/com/mixel/docusphere/entity/Document.java @@ -0,0 +1,90 @@ +package com.mixel.docusphere.entity; + +import jakarta.persistence.*; +import java.util.UUID; +import java.time.LocalDateTime; + +@Entity +@Table(name = "Documents") +public class Document { + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "DocumentID", updatable = false, nullable = false) + private UUID documentId; + + @Column(name = "Name", nullable = false) + private String name; + + @Column(name = "S3Path", nullable = false) + private String s3Path; + + @ManyToOne + @JoinColumn(name = "UserID", nullable = false) + private User user; + + @Column(name = "CreatedAt", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @Column(name = "UpdatedAt", nullable = false) + private LocalDateTime updatedAt; + + @PrePersist + protected void onCreate() { + createdAt = LocalDateTime.now(); + updatedAt = LocalDateTime.now(); + } + + @PreUpdate + protected void onUpdate() { + updatedAt = LocalDateTime.now(); + } + + // Getters and Setters + public UUID getDocumentId() { + return documentId; + } + + public void setDocumentId(UUID documentId) { + this.documentId = documentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getS3Path() { + return s3Path; + } + + public void setS3Path(String s3Path) { + this.s3Path = s3Path; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } +} \ No newline at end of file diff --git a/server/src/main/java/com/mixel/docusphere/entity/User.java b/server/src/main/java/com/mixel/docusphere/entity/User.java new file mode 100644 index 0000000..6950ab6 --- /dev/null +++ b/server/src/main/java/com/mixel/docusphere/entity/User.java @@ -0,0 +1,111 @@ +package com.mixel.docusphere.entity; + +import jakarta.persistence.*; +import java.time.LocalDateTime; +import java.util.UUID; + +@Entity +@Table(name = "Users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @Column(name = "UserID", updatable = false, nullable = false) + private UUID userId; + + @Column(name = "Username", nullable = false, unique = true) + private String username; + + @Column(name = "Name", nullable = false) + private String name; + + @Column(name = "Email", nullable = false, unique = true) + private String email; + + @Column(name = "PasswordHash", nullable = false) + private String passwordHash; + + @Column(name = "PasswordSalt", nullable = false) + private String passwordSalt; + + @Column(name = "CreatedAt", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @Column(name = "UpdatedAt", nullable = false) + private LocalDateTime updatedAt; + + @PrePersist + protected void onCreate() { + createdAt = LocalDateTime.now(); + updatedAt = LocalDateTime.now(); + } + + @PreUpdate + protected void onUpdate() { + updatedAt = LocalDateTime.now(); + } + + // Getters and Setters + public UUID getUserId() { + return userId; + } + + public void setUserId(UUID userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPasswordHash() { + return passwordHash; + } + + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + + public String getPasswordSalt() { + return passwordSalt; + } + + public void setPasswordSalt(String passwordSalt) { + this.passwordSalt = passwordSalt; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } +} \ No newline at end of file diff --git a/server/src/main/java/com/mixel/docusphere/repository/DocumentRepository.java b/server/src/main/java/com/mixel/docusphere/repository/DocumentRepository.java new file mode 100644 index 0000000..d3fb4db --- /dev/null +++ b/server/src/main/java/com/mixel/docusphere/repository/DocumentRepository.java @@ -0,0 +1,8 @@ +package com.mixel.docusphere.repository; + +import com.mixel.docusphere.entity.Document; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.UUID; + +public interface DocumentRepository extends JpaRepository { +} diff --git a/server/src/main/java/com/mixel/docusphere/repository/UserRepository.java b/server/src/main/java/com/mixel/docusphere/repository/UserRepository.java new file mode 100644 index 0000000..456987e --- /dev/null +++ b/server/src/main/java/com/mixel/docusphere/repository/UserRepository.java @@ -0,0 +1,8 @@ +package com.mixel.docusphere.repository; + +import com.mixel.docusphere.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.UUID; + +public interface UserRepository extends JpaRepository { +} \ No newline at end of file