feat(docker): Add Dockerfile and compose file
This commit is contained in:
41
app/repositories/domain.go
Normal file
41
app/repositories/domain.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/gogwapi/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DomainRepository interface {
|
||||
Create(domain *models.Domain) error
|
||||
Get(id string) (*models.Domain, error)
|
||||
Update(domain *models.Domain) error
|
||||
Delete(id string) error
|
||||
}
|
||||
|
||||
type domainRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewDomainRepository(db *gorm.DB) DomainRepository {
|
||||
return &domainRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *domainRepository) Create(domain *models.Domain) error {
|
||||
return r.db.Create(domain).Error
|
||||
}
|
||||
|
||||
func (r *domainRepository) Get(name string) (*models.Domain, error) {
|
||||
var domain models.Domain
|
||||
if err := r.db.Where("name = ?", name).First(&domain).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &domain, nil
|
||||
}
|
||||
|
||||
func (r *domainRepository) Update(domain *models.Domain) error {
|
||||
return r.db.Save(domain).Error
|
||||
}
|
||||
|
||||
func (r *domainRepository) Delete(id string) error {
|
||||
return r.db.Delete(&models.Domain{}, id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user