seller by id
This commit is contained in:
		
							parent
							
								
									738089755a
								
							
						
					
					
						commit
						40533e1805
					
				| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Seller ...
 | 
				
			||||||
 | 
					type Seller struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetSeller ...
 | 
				
			||||||
 | 
					func GetSeller() Seller {
 | 
				
			||||||
 | 
						return Seller{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetSellerInfoByID ...
 | 
				
			||||||
 | 
					func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.ResponseSellerInfo, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.Seller.GetSellerInfoByID, toBytes(p))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.ResponseSellerInfo `json:"data"`
 | 
				
			||||||
 | 
							Error string                    `json:"error"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := json.Unmarshal(msg.Data, &r); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if r.Error != "" {
 | 
				
			||||||
 | 
							return nil, errors.New(r.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.Data, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "go.mongodb.org/mongo-driver/bson/primitive"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetSellerByIDRequest ...
 | 
				
			||||||
 | 
					type GetSellerByIDRequest struct {
 | 
				
			||||||
 | 
						SellerID primitive.ObjectID `json:"sellerId"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseSellerInfo ...
 | 
				
			||||||
 | 
					type ResponseSellerInfo struct {
 | 
				
			||||||
 | 
						ID   string `json:"id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
						Code string `json:"code"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -6,10 +6,12 @@ var prefixes = struct {
 | 
				
			||||||
	Warehouse     string
 | 
						Warehouse     string
 | 
				
			||||||
	Location      string
 | 
						Location      string
 | 
				
			||||||
	Supplier      string
 | 
						Supplier      string
 | 
				
			||||||
 | 
						Seller        string
 | 
				
			||||||
}{
 | 
					}{
 | 
				
			||||||
	Communication: "communication",
 | 
						Communication: "communication",
 | 
				
			||||||
	Order:         "order",
 | 
						Order:         "order",
 | 
				
			||||||
	Warehouse:     "warehouse",
 | 
						Warehouse:     "warehouse",
 | 
				
			||||||
	Location:      "location",
 | 
						Location:      "location",
 | 
				
			||||||
	Supplier:      "supplier",
 | 
						Supplier:      "supplier",
 | 
				
			||||||
 | 
						Seller:        "seller",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getSellerValue(val string) string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s.%s", prefixes.Seller, val)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Seller ...
 | 
				
			||||||
 | 
					var Seller = struct {
 | 
				
			||||||
 | 
						GetSellerInfoByID string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						GetSellerInfoByID: getSellerValue("get_seller_info_by_id"),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue