Files
template-vitrine/backend/internal/modules/site/repository.go
T
Xor290 919c807004
ci-api / test (push) Failing after 8m7s
ci-web / test (push) Failing after 5m5s
chore: build
2026-09-20 12:18:33 +02:00

71 lines
2.2 KiB
Go

package site
import (
"context"
"gorm.io/gorm"
)
type Repository interface {
Get(ctx context.Context) (*Settings, error)
Update(ctx context.Context, s *Settings) error
UpdateAppearance(ctx context.Context, s *Settings) error
UpdateCustomerAuth(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,
"orders_enabled": s.OrdersEnabled,
}).Error
}
func (r *gormRepository) UpdateAppearance(ctx context.Context, s *Settings) error {
s.ID = 1
return r.db.WithContext(ctx).Model(&Settings{}).Where("id = 1").Updates(map[string]any{
"header_bg_color": s.HeaderBgColor,
"header_text_color": s.HeaderTextColor,
"body_bg_color": s.BodyBgColor,
"body_text_color": s.BodyTextColor,
"footer_bg_color": s.FooterBgColor,
"footer_text_color": s.FooterTextColor,
"accent_color": s.AccentColor,
"product_layout": s.ProductLayout,
"product_columns": s.ProductColumns,
"product_scroll": s.ProductScroll,
"contact_card_transparent": s.ContactCardTransparent,
"contact_card_bg_color": s.ContactCardBgColor,
"logo_media_id": s.LogoMediaID,
"hero_media_id": s.HeroMediaID,
"hero_pages": s.HeroPages,
}).Error
}
func (r *gormRepository) UpdateCustomerAuth(ctx context.Context, s *Settings) error {
s.ID = 1
return r.db.WithContext(ctx).Model(&Settings{}).Where("id = 1").Updates(map[string]any{
"customer_login_enabled": s.CustomerLoginEnabled,
"customer_registration_enabled": s.CustomerRegistrationEnabled,
"customer_verification_required": s.CustomerVerificationRequired,
"verification_contact_link_id": s.VerificationContactLinkID,
}).Error
}