product.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package product
  2. import (
  3. "context"
  4. "sghgogs.com/micro/shopping-service/domain/service"
  5. pb "sghgogs.com/micro/shopping-service/proto"
  6. )
  7. type Product struct {
  8. Service service.IService
  9. }
  10. func (svc *Product) GetProductList(ctx context.Context, query *pb.GetProductListRequest, rsp *pb.GetProductListResponse) error {
  11. if list, i, err := svc.Service.GetProductList(query); err != nil {
  12. return err
  13. } else {
  14. rsp.TotalCount = i
  15. rsp.Items = list
  16. }
  17. return nil
  18. }
  19. func (svc *Product) GetProduct(ctx context.Context, query *pb.GetProductRequest, rsp *pb.GetProductResponse) error {
  20. if product, err := svc.Service.GetProduct(query); err != nil {
  21. return err
  22. } else {
  23. rsp.Data = product
  24. }
  25. return nil
  26. }
  27. func (svc *Product) CreateProduct(ctx context.Context, add *pb.CreateProductRequest, rsp *pb.CreateProductResponse) error {
  28. if err := svc.Service.CreateMultipleProducts(add); err != nil {
  29. return err
  30. }
  31. return nil
  32. }
  33. func (svc *Product) UpdateProduct(ctx context.Context, product *pb.UpdateProductRequest, rsp *pb.UpdateProductResponse) error {
  34. if err := svc.Service.UpdateProduct(product); err != nil {
  35. return err
  36. }
  37. return nil
  38. }
  39. func (svc *Product) DeleteProduct(ctx context.Context, query *pb.DeleteProductRequest, rsp *pb.DeleteProductResponse) error {
  40. if err := svc.Service.DeleteProduct(query); err != nil {
  41. return err
  42. }
  43. return nil
  44. }