nats-location-supplier #6
			
				
			
		
		
		
	| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Location ...
 | 
				
			||||||
 | 
					type Location struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetLocation ...
 | 
				
			||||||
 | 
					func GetLocation() Location {
 | 
				
			||||||
 | 
						return Location{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.GetLocationWarehouse, toBytes(payload))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.ResponseLocationAddress `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,34 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Supplier ...
 | 
				
			||||||
 | 
					type Supplier struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s Supplier) GetSupplierInfo(supplierID string) (*model.ResponseSupplierInfo, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.GetSupplierInfo, toBytes(supplierID))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.ResponseSupplierInfo `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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LocationRequestPayload ...
 | 
				
			||||||
 | 
					type LocationRequestPayload struct {
 | 
				
			||||||
 | 
						Province int `json:"province"`
 | 
				
			||||||
 | 
						District int `json:"district"`
 | 
				
			||||||
 | 
						Ward     int `json:"ward"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,31 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ResponseLocationAddress struct {
 | 
				
			||||||
 | 
						Province LocationProvince `json:"province"`
 | 
				
			||||||
 | 
						District LocationDistrict `json:"district"`
 | 
				
			||||||
 | 
						Ward     LocationWard     `json:"ward"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LocationProvince ...
 | 
				
			||||||
 | 
					type LocationProvince struct {
 | 
				
			||||||
 | 
						ID   string `json:"id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LocationDistrict ...
 | 
				
			||||||
 | 
					type LocationDistrict struct {
 | 
				
			||||||
 | 
						ID   string `json:"id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LocationWard ...
 | 
				
			||||||
 | 
					type LocationWard struct {
 | 
				
			||||||
 | 
						ID   string `json:"id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseSupplierInfo ...
 | 
				
			||||||
 | 
					type ResponseSupplierInfo struct {
 | 
				
			||||||
 | 
						ID   string `json:"id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						locationPrefix = "location_"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						GetLocationWarehouse = locationPrefix + "get_address"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						supplierPrefix = "supplier"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						GetSupplierInfo = supplierPrefix + "get_info"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue