online-order/usecase/product/service.go

50 lines
1.1 KiB
Go

package service_product
import (
"online-order/domain"
"online-order/entity"
)
type productservice struct {
repo domain.ProductRepository
}
func NewProductService(r domain.ProductRepository) *productservice {
return &productservice{
repo: r,
}
}
func (s *productservice) List() ([]*entity.ProductDisplay, error) {
return s.repo.List()
}
func (s *productservice) ListProductPerCategory(slug string) ([]*entity.ProductDisplay, error) {
return s.repo.ListProductPerCategory(slug)
}
func (s *productservice) Create(p *entity.ProductCreateUpdate) error {
return s.repo.Create(p)
}
// Retrieve a product
func (s *productservice) GetByID(id int) (*entity.ProductDisplay, error) {
u, err := s.repo.GetByID(id)
if err != nil {
return &entity.ProductDisplay{}, entity.ErrNotFound
}
return u, nil
}
func (s *productservice) Update(p *entity.ProductCreateUpdate) error {
return s.repo.Update(p)
}
func (s *productservice) SearchProduct(identifier string) (*entity.ProductDisplay, error) {
return s.repo.SearchProduct(identifier)
}
func (s *productservice) Delete(id int) error {
return s.repo.Delete(id)
}