
- Add CertificateRepository with CRUD operations - Implement CertificateAuthorityRepository for CA management - Add CertificateRequestRepository for CSR handling - Include UserRepository and OrganizationRepository - Implement proper error handling and validation - Add support for soft deletes and relationships - Include query optimization and filtering capabilities
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package repositories
|
|
|
|
import (
|
|
"git.secnex.io/secnex/certman/models"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type OrganizationRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewOrganizationRepository creates a new organization repository
|
|
func NewOrganizationRepository(db *gorm.DB) *OrganizationRepository {
|
|
return &OrganizationRepository{db: db}
|
|
}
|
|
|
|
// GetByID returns an organization by their ID
|
|
func (r *OrganizationRepository) GetByID(id string) (models.Organization, error) {
|
|
var organization models.Organization
|
|
if err := r.db.Where("id = ?", id).First(&organization).Error; err != nil {
|
|
return models.Organization{}, err
|
|
}
|
|
return organization, nil
|
|
}
|
|
|
|
// GetAll returns all organizations
|
|
func (r *OrganizationRepository) GetAll() ([]models.Organization, error) {
|
|
var organizations []models.Organization
|
|
if err := r.db.Find(&organizations).Error; err != nil {
|
|
return []models.Organization{}, err
|
|
}
|
|
return organizations, nil
|
|
}
|
|
|
|
// Create creates a new organization
|
|
func (r *OrganizationRepository) Create(organization models.Organization) (models.Organization, error) {
|
|
if err := r.db.Create(&organization).Error; err != nil {
|
|
return models.Organization{}, err
|
|
}
|
|
return organization, nil
|
|
}
|
|
|
|
// Update updates an organization
|
|
func (r *OrganizationRepository) Update(organization models.Organization) error {
|
|
return r.db.Save(&organization).Error
|
|
}
|
|
|
|
// Delete deletes an organization by their ID
|
|
func (r *OrganizationRepository) Delete(id string) error {
|
|
return r.db.Delete(&models.Organization{}, id).Error
|
|
}
|
|
|
|
// HardDelete deletes an organization by their ID
|
|
func (r *OrganizationRepository) HardDelete(organization models.Organization) error {
|
|
return r.db.Unscoped().Delete(&organization).Error
|
|
}
|