Files
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

77 lines
1.9 KiB
Go

package contactlinks
import (
"context"
"github.com/google/uuid"
)
type Service struct {
repo Repository
}
func NewService(repo Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) List(ctx context.Context, activeOnly bool) ([]*ContactLink, error) {
return s.repo.List(ctx, activeOnly)
}
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*ContactLink, error) {
return s.repo.FindByID(ctx, id)
}
func (s *Service) Create(ctx context.Context, label, url, iconKey string, iconMediaID *uuid.UUID, color string, position int, isActive bool) (*ContactLink, error) {
link := &ContactLink{
ID: uuid.New(),
Label: label,
URL: url,
IconKey: iconKey,
IconMediaID: iconMediaID,
Color: color,
Position: position,
IsActive: isActive,
}
if err := s.repo.Create(ctx, link); err != nil {
return nil, err
}
return link, nil
}
func (s *Service) Update(ctx context.Context, id uuid.UUID, label, url, iconKey string, iconMediaID *uuid.UUID, color string, position int, isActive bool) (*ContactLink, error) {
link, err := s.repo.FindByID(ctx, id)
if err != nil {
return nil, err
}
link.Label = label
link.URL = url
link.IconKey = iconKey
link.IconMediaID = iconMediaID
link.Color = color
link.Position = position
link.IsActive = isActive
if err := s.repo.Update(ctx, link); err != nil {
return nil, err
}
return link, nil
}
func (s *Service) Delete(ctx context.Context, id uuid.UUID) error {
return s.repo.Delete(ctx, id)
}
// UpdatePosition lets the admin reorder the displayed list without
// resending the full contact link payload.
func (s *Service) UpdatePosition(ctx context.Context, id uuid.UUID, position int) (*ContactLink, error) {
link, err := s.repo.FindByID(ctx, id)
if err != nil {
return nil, err
}
link.Position = position
if err := s.repo.Update(ctx, link); err != nil {
return nil, err
}
return link, nil
}