package service import ( "code.linberg.su/linberg/awesome-cli/awesome-back/internal/domain/entities" "code.linberg.su/linberg/awesome-cli/awesome-back/internal/domain/repositories" "code.linberg.su/linberg/awesome-cli/awesome-back/pkg/errors" ) type CoffeeService struct { repo repositories.CoffeeRepository } func NewCoffeeService(repo repositories.CoffeeRepository) *CoffeeService { return &CoffeeService{repo: repo} } func (s *CoffeeService) GetAllCoffees() ([]entities.Coffee, error) { coffees, err := s.repo.FindAll() if err != nil { return nil, errors.Wrap(err, "failed to get coffees") } return coffees, nil } func (s *CoffeeService) GetCoffeeByID(id int) (*entities.Coffee, error) { if id <= 0 { return nil, errors.NewInvalidError("invalid coffee ID") } coffee, err := s.repo.FindByID(id) if err != nil { if errors.IsNotFound(err) { return nil, errors.NewNotFoundError("coffee not found") } return nil, errors.Wrap(err, "failed to get coffee") } return coffee, nil }