supplier-setup-product #138
			
				
			
		
		
		
	|  | @ -0,0 +1,52 @@ | |||
| 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" | ||||
| ) | ||||
| 
 | ||||
| // Product ...
 | ||||
| type Product struct{} | ||||
| 
 | ||||
| // GetProduct ...
 | ||||
| func GetProduct() Product { | ||||
| 	return Product{} | ||||
| } | ||||
| 
 | ||||
| func (c Product) ApplyRequest(p model.ProductApplyRequestPayload) error { | ||||
| 	msg, err := natsio.GetServer().Request(subject.Product.ApplyRequest, toBytes(p)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var r struct { | ||||
| 		Error string `json:"error"` | ||||
| 	} | ||||
| 	if err = json.Unmarshal(msg.Data, &r); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if r.Error != "" { | ||||
| 		return errors.New(r.Error) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (c Product) ProcessApplyRequest(p model.ProductApplyRequestPayload) error { | ||||
| 	msg, err := natsio.GetServer().Request(subject.Product.ProcessApplyRequest, toBytes(p)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var r struct { | ||||
| 		Error string `json:"error"` | ||||
| 	} | ||||
| 	if err = json.Unmarshal(msg.Data, &r); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if r.Error != "" { | ||||
| 		return errors.New(r.Error) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | @ -0,0 +1,35 @@ | |||
| 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" | ||||
| ) | ||||
| 
 | ||||
| // Queue ...
 | ||||
| type Queue struct{} | ||||
| 
 | ||||
| // GetQueue ...
 | ||||
| func GetQueue() Queue { | ||||
| 	return Queue{} | ||||
| } | ||||
| 
 | ||||
| func (c Queue) ScheduleTask(p model.QueueScheduleTaskRequest) error { | ||||
| 	msg, err := natsio.GetServer().Request(subject.Queue.ScheduleTask, toBytes(p)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var r struct { | ||||
| 		Error string `json:"error"` | ||||
| 	} | ||||
| 	if err = json.Unmarshal(msg.Data, &r); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if r.Error != "" { | ||||
| 		return errors.New(r.Error) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | @ -0,0 +1,5 @@ | |||
| package model | ||||
| 
 | ||||
| type ProductApplyRequestPayload struct { | ||||
| 	RequestID string `json:"requestId"` | ||||
| } | ||||
|  | @ -0,0 +1,8 @@ | |||
| package model | ||||
| 
 | ||||
| type QueueScheduleTaskRequest struct { | ||||
| 	ID          string `json:"id"` | ||||
| 	NatsSubject string `json:"natsSubject"` | ||||
| 	Data        string `json:"data"` | ||||
| 	StartAt     int64  `json:"startAt"` // unix
 | ||||
| } | ||||
|  | @ -101,6 +101,7 @@ type GetWarehousesRequest struct { | |||
| 	Status       string   `json:"status"` | ||||
| 	Supplier     string   `json:"supplier"` | ||||
| 	BusinessType string   `json:"businessType"` | ||||
| 	IDs          []string `json:"ids"` | ||||
| 
 | ||||
| 	Page  int64 `json:"page"` | ||||
| 	Limit int64 `json:"limit"` | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ var prefixes = struct { | |||
| 	SocialPost    string | ||||
| 	Staff         string | ||||
| 	Segment       string | ||||
| 	Product       string | ||||
| 	Queue         string | ||||
| 	Campaign      string | ||||
| 	Affiliate     string | ||||
| }{ | ||||
|  | @ -30,6 +32,8 @@ var prefixes = struct { | |||
| 	SocialPost:    "social_post", | ||||
| 	Staff:         "staff", | ||||
| 	Segment:       "segment", | ||||
| 	Product:       "product", | ||||
| 	Queue:         "queue", | ||||
| 	Campaign:      "campaign", | ||||
| 	Affiliate:     "affiliate", | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,16 @@ | |||
| package subject | ||||
| 
 | ||||
| import "fmt" | ||||
| 
 | ||||
| // getSegmentValue ...
 | ||||
| func getProductValue(val string) string { | ||||
| 	return fmt.Sprintf("%s.%s", prefixes.Product, val) | ||||
| } | ||||
| 
 | ||||
| var Product = struct { | ||||
| 	ApplyRequest        string | ||||
| 	ProcessApplyRequest string | ||||
| }{ | ||||
| 	ApplyRequest:        getProductValue("apply_request"), | ||||
| 	ProcessApplyRequest: getProductValue("process_apply_request"), | ||||
| } | ||||
|  | @ -0,0 +1,13 @@ | |||
| package subject | ||||
| 
 | ||||
| import "fmt" | ||||
| 
 | ||||
| func getQueueValue(val string) string { | ||||
| 	return fmt.Sprintf("%s.%s", prefixes.Queue, val) | ||||
| } | ||||
| 
 | ||||
| var Queue = struct { | ||||
| 	ScheduleTask string | ||||
| }{ | ||||
| 	ScheduleTask: getQueueValue("schedule_task"), | ||||
| } | ||||
		Loading…
	
		Reference in New Issue