feature/update-warehouse-into-supplier #44
			
				
			
		
		
		
	| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Bank ...
 | 
				
			||||||
 | 
					type Bank struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetBank ...
 | 
				
			||||||
 | 
					func GetBank() Bank {
 | 
				
			||||||
 | 
						return Bank{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s Bank) GetBankInfoByID(bankID model.BankRequestPayload) (*model.BankBrief, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.BankBrief `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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -79,3 +79,24 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.Data, nil
 | 
						return r.Data, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.SupplierAll `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,6 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BankRequestPayload ...
 | 
				
			||||||
 | 
					type BankRequestPayload struct {
 | 
				
			||||||
 | 
						ID string `json:"_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BankBrief ...
 | 
				
			||||||
 | 
					type BankBrief struct {
 | 
				
			||||||
 | 
						ID string `json:"_id"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getBankValue(val string) string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s.%s", prefixes.Bank, val)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Bank = struct {
 | 
				
			||||||
 | 
						GetBankById string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						GetBankById: getBankValue("get_bank_by_id"),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ var prefixes = struct {
 | 
				
			||||||
	Order         string
 | 
						Order         string
 | 
				
			||||||
	Warehouse     string
 | 
						Warehouse     string
 | 
				
			||||||
	Location      string
 | 
						Location      string
 | 
				
			||||||
 | 
						Bank          string
 | 
				
			||||||
	Supplier      string
 | 
						Supplier      string
 | 
				
			||||||
}{
 | 
					}{
 | 
				
			||||||
	Communication: "communication",
 | 
						Communication: "communication",
 | 
				
			||||||
| 
						 | 
					@ -12,4 +13,5 @@ var prefixes = struct {
 | 
				
			||||||
	Warehouse:     "warehouse",
 | 
						Warehouse:     "warehouse",
 | 
				
			||||||
	Location:      "location",
 | 
						Location:      "location",
 | 
				
			||||||
	Supplier:      "supplier",
 | 
						Supplier:      "supplier",
 | 
				
			||||||
 | 
						Bank:          "bank",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue