Customer Order
This commit is contained in:
@@ -2,7 +2,9 @@ package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"furtuna-be/config"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/repository"
|
||||
@@ -15,14 +17,16 @@ const (
|
||||
)
|
||||
|
||||
type DiscoveryService struct {
|
||||
repo repository.SiteRepository
|
||||
cfg config.Discovery
|
||||
repo repository.SiteRepository
|
||||
cfg config.Discovery
|
||||
product repository.Product
|
||||
}
|
||||
|
||||
func NewDiscoveryService(repo repository.SiteRepository, cfg config.Discovery) *DiscoveryService {
|
||||
func NewDiscoveryService(repo repository.SiteRepository, cfg config.Discovery, product repository.Product) *DiscoveryService {
|
||||
return &DiscoveryService{
|
||||
repo: repo,
|
||||
cfg: cfg,
|
||||
repo: repo,
|
||||
cfg: cfg,
|
||||
product: product,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,3 +123,43 @@ func (s *DiscoveryService) Search(ctx context.Context, search *entity.DiscoveryS
|
||||
|
||||
return response, total, nil
|
||||
}
|
||||
|
||||
func (s *DiscoveryService) GetByID(ctx context.Context, id int64) (*entity.Site, error) {
|
||||
site, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if site.Status == "Inactive" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return site.ToSite(), nil
|
||||
}
|
||||
|
||||
func (s *DiscoveryService) GetProductsByID(ctx context.Context, id int64) ([]*entity.Product, error) {
|
||||
site, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if site.Status == "Inactive" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
product, err := s.product.GetProductsBySiteID(ctx, site.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return product.ToProductList(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user