feat: add app entity and repository
This commit is contained in:
81
src/main/java/net/siegeln/cameleer/saas/app/AppEntity.java
Normal file
81
src/main/java/net/siegeln/cameleer/saas/app/AppEntity.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package net.siegeln.cameleer.saas.app;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "apps")
|
||||
public class AppEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private UUID id;
|
||||
|
||||
@Column(name = "environment_id", nullable = false)
|
||||
private UUID environmentId;
|
||||
|
||||
@Column(nullable = false, length = 100)
|
||||
private String slug;
|
||||
|
||||
@Column(name = "display_name", nullable = false)
|
||||
private String displayName;
|
||||
|
||||
@Column(name = "jar_storage_path", length = 500)
|
||||
private String jarStoragePath;
|
||||
|
||||
@Column(name = "jar_checksum", length = 64)
|
||||
private String jarChecksum;
|
||||
|
||||
@Column(name = "jar_original_filename")
|
||||
private String jarOriginalFilename;
|
||||
|
||||
@Column(name = "jar_size_bytes")
|
||||
private Long jarSizeBytes;
|
||||
|
||||
@Column(name = "current_deployment_id")
|
||||
private UUID currentDeploymentId;
|
||||
|
||||
@Column(name = "previous_deployment_id")
|
||||
private UUID previousDeploymentId;
|
||||
|
||||
@Column(name = "created_at", nullable = false)
|
||||
private Instant createdAt;
|
||||
|
||||
@Column(name = "updated_at", nullable = false)
|
||||
private Instant updatedAt;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = Instant.now();
|
||||
updatedAt = Instant.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = Instant.now();
|
||||
}
|
||||
|
||||
public UUID getId() { return id; }
|
||||
public void setId(UUID id) { this.id = id; }
|
||||
public UUID getEnvironmentId() { return environmentId; }
|
||||
public void setEnvironmentId(UUID environmentId) { this.environmentId = environmentId; }
|
||||
public String getSlug() { return slug; }
|
||||
public void setSlug(String slug) { this.slug = slug; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||
public String getJarStoragePath() { return jarStoragePath; }
|
||||
public void setJarStoragePath(String jarStoragePath) { this.jarStoragePath = jarStoragePath; }
|
||||
public String getJarChecksum() { return jarChecksum; }
|
||||
public void setJarChecksum(String jarChecksum) { this.jarChecksum = jarChecksum; }
|
||||
public String getJarOriginalFilename() { return jarOriginalFilename; }
|
||||
public void setJarOriginalFilename(String jarOriginalFilename) { this.jarOriginalFilename = jarOriginalFilename; }
|
||||
public Long getJarSizeBytes() { return jarSizeBytes; }
|
||||
public void setJarSizeBytes(Long jarSizeBytes) { this.jarSizeBytes = jarSizeBytes; }
|
||||
public UUID getCurrentDeploymentId() { return currentDeploymentId; }
|
||||
public void setCurrentDeploymentId(UUID currentDeploymentId) { this.currentDeploymentId = currentDeploymentId; }
|
||||
public UUID getPreviousDeploymentId() { return previousDeploymentId; }
|
||||
public void setPreviousDeploymentId(UUID previousDeploymentId) { this.previousDeploymentId = previousDeploymentId; }
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public Instant getUpdatedAt() { return updatedAt; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.siegeln.cameleer.saas.app;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface AppRepository extends JpaRepository<AppEntity, UUID> {
|
||||
|
||||
List<AppEntity> findByEnvironmentId(UUID environmentId);
|
||||
|
||||
Optional<AppEntity> findByEnvironmentIdAndSlug(UUID environmentId, String slug);
|
||||
|
||||
boolean existsByEnvironmentIdAndSlug(UUID environmentId, String slug);
|
||||
|
||||
@Query("SELECT COUNT(a) FROM AppEntity a JOIN EnvironmentEntity e ON a.environmentId = e.id WHERE e.tenantId = :tenantId")
|
||||
long countByTenantId(UUID tenantId);
|
||||
|
||||
long countByEnvironmentId(UUID environmentId);
|
||||
}
|
||||
Reference in New Issue
Block a user