Files
template-vitrine/backend/internal/modules/site/repository.go
T
2026-09-14 20:50:19 +02:00

38 lines
770 B
Go

package site
import (
"context"
"gorm.io/gorm"
)
type Repository interface {
Get(ctx context.Context) (*Settings, error)
Update(ctx context.Context, s *Settings) error
}
type gormRepository struct {
db *gorm.DB
}
func NewRepository(db *gorm.DB) Repository {
return &gormRepository{db: db}
}
func (r *gormRepository) Get(ctx context.Context) (*Settings, error) {
var s Settings
if err := r.db.WithContext(ctx).First(&s, "id = 1").Error; err != nil {
return nil, err
}
return &s, nil
}
func (r *gormRepository) Update(ctx context.Context, s *Settings) error {
s.ID = 1
return r.db.WithContext(ctx).Model(&Settings{}).Where("id = 1").Updates(map[string]any{
"name": s.Name,
"description": s.Description,
"slug": s.Slug,
}).Error
}