46 lines
979 B
Go
46 lines
979 B
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) Create(u *entity.ProductCreateUpdate) error {
|
|
return s.repo.Create(u)
|
|
}
|
|
|
|
// 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(u *entity.ProductCreateUpdate) error {
|
|
return s.repo.Update(u)
|
|
}
|
|
|
|
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)
|
|
}
|