34 lines
586 B
Go
34 lines
586 B
Go
package gifts
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var ErrNotFound = errors.New("gift not found")
|
|
|
|
type Service struct {
|
|
store Store
|
|
}
|
|
|
|
func NewService(store Store) *Service {
|
|
return &Service{store: store}
|
|
}
|
|
|
|
func (s *Service) GetPublicGift(ctx context.Context, slug string) (PublicGift, error) {
|
|
if slug == "" {
|
|
return PublicGift{}, ErrNotFound
|
|
}
|
|
|
|
gift, err := s.store.GetPublicBySlug(ctx, slug)
|
|
if err != nil {
|
|
if errors.Is(err, ErrNotFound) {
|
|
return PublicGift{}, ErrNotFound
|
|
}
|
|
return PublicGift{}, fmt.Errorf("get public gift: %w", err)
|
|
}
|
|
|
|
return gift, nil
|
|
}
|