admin-push-notification-supplier #90
			
				
			
		
		
		
	| 
						 | 
					@ -0,0 +1,41 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Segment ...
 | 
				
			||||||
 | 
					type Segment struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetSegment ...
 | 
				
			||||||
 | 
					func GetSegment() Segment {
 | 
				
			||||||
 | 
						return Segment{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetListSegmentInfoByIds ...
 | 
				
			||||||
 | 
					func (s Segment) GetListSegmentInfoByIds(p model.GetListSegmentRequest) (*model.ResponseListSegmentInfo, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.Segment.GetListSegmentInfo, toBytes(p))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.ResponseListSegmentInfo `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,41 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"git.selly.red/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Staff ...
 | 
				
			||||||
 | 
					type Staff struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetStaff() Staff {
 | 
				
			||||||
 | 
						return Staff{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetListStaffInfoByIds ...
 | 
				
			||||||
 | 
					func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var r struct {
 | 
				
			||||||
 | 
							Data  *model.ResponseListStaffInfo `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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetListSegmentRequest ...
 | 
				
			||||||
 | 
					type GetListSegmentRequest struct {
 | 
				
			||||||
 | 
						SegmentIds []string `json:"segmentIds"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseSegmentInfo ...
 | 
				
			||||||
 | 
					type ResponseSegmentInfo struct {
 | 
				
			||||||
 | 
						ID   string `json:"_id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseListSegmentInfo ...
 | 
				
			||||||
 | 
					type ResponseListSegmentInfo struct {
 | 
				
			||||||
 | 
						Segments []ResponseSegmentInfo `json:"segments"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetListStaffRequest ...
 | 
				
			||||||
 | 
					type GetListStaffRequest struct {
 | 
				
			||||||
 | 
						StaffIds []string `json:"staffIds"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseListStaffInfo ...
 | 
				
			||||||
 | 
					type ResponseListStaffInfo struct {
 | 
				
			||||||
 | 
						Staffs []ResponseStaffInfo `json:"staffs"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ResponseStaffInfo ...
 | 
				
			||||||
 | 
					type ResponseStaffInfo struct {
 | 
				
			||||||
 | 
						ID   string `json:"_id"`
 | 
				
			||||||
 | 
						Name string `json:"name"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,8 @@ var prefixes = struct {
 | 
				
			||||||
	Seller        string
 | 
						Seller        string
 | 
				
			||||||
	SupplierUser  string
 | 
						SupplierUser  string
 | 
				
			||||||
	SupplierRole  string
 | 
						SupplierRole  string
 | 
				
			||||||
 | 
						Staff         string
 | 
				
			||||||
 | 
						Segment       string
 | 
				
			||||||
}{
 | 
					}{
 | 
				
			||||||
	Communication: "communication",
 | 
						Communication: "communication",
 | 
				
			||||||
	Order:         "order",
 | 
						Order:         "order",
 | 
				
			||||||
| 
						 | 
					@ -22,4 +24,6 @@ var prefixes = struct {
 | 
				
			||||||
	Seller:        "seller",
 | 
						Seller:        "seller",
 | 
				
			||||||
	SupplierUser:  "supplier_user",
 | 
						SupplierUser:  "supplier_user",
 | 
				
			||||||
	SupplierRole:  "supplier_role",
 | 
						SupplierRole:  "supplier_role",
 | 
				
			||||||
 | 
						Staff:         "staff",
 | 
				
			||||||
 | 
						Segment:       "segment",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getSegmentValue ...
 | 
				
			||||||
 | 
					func getSegmentValue(val string) string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s.%s", prefixes.Segment, val)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Segment ...
 | 
				
			||||||
 | 
					var Segment = struct {
 | 
				
			||||||
 | 
						GetListSegmentInfo string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						GetListSegmentInfo: getSegmentValue("get_list_segment_info"),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getStaffValue(val string) string {
 | 
				
			||||||
 | 
						return fmt.Sprintf("%s.%s", prefixes.Staff, val)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Staff ...
 | 
				
			||||||
 | 
					var Staff = struct {
 | 
				
			||||||
 | 
						GetListStaffInfo string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						GetListStaffInfo: getStaffValue("get_list_staff_info"),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue