From 46539db23609d8cf226fc77f0d36c2645f008613 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 9 Dec 2022 10:05:41 +0700 Subject: [PATCH 1/3] update get warehouse condition --- model/warehouse_request.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index b6cecb1..56adb1b 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -97,10 +97,11 @@ type SupplierIsClosed struct { // GetWarehousesRequest ... type GetWarehousesRequest struct { - Keyword string `json:"keyword"` - Status string `json:"status"` - Supplier string `json:"supplier"` - BusinessType string `json:"businessType"` + Keyword string `json:"keyword"` + Status string `json:"status"` + Supplier string `json:"supplier"` + BusinessType string `json:"businessType"` + IDs []string `json:"ids"` Page int64 `json:"page"` Limit int64 `json:"limit"` From b19fea04c8b9d76c66f1b3028d32af1ab3fceb1c Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 26 Dec 2022 14:08:14 +0700 Subject: [PATCH 2/3] define nats product --- client/product.go | 35 +++++++++++++++++++++++++++++++++++ model/product_request.go | 5 +++++ subject/config.go | 2 ++ subject/product.go | 14 ++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 client/product.go create mode 100644 model/product_request.go create mode 100644 subject/product.go diff --git a/client/product.go b/client/product.go new file mode 100644 index 0000000..340ba21 --- /dev/null +++ b/client/product.go @@ -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" +) + +// 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 +} diff --git a/model/product_request.go b/model/product_request.go new file mode 100644 index 0000000..1adbec5 --- /dev/null +++ b/model/product_request.go @@ -0,0 +1,5 @@ +package model + +type ProductApplyRequestPayload struct { + RequestID string `json:"requestId"` +} diff --git a/subject/config.go b/subject/config.go index 1954121..483f963 100644 --- a/subject/config.go +++ b/subject/config.go @@ -14,6 +14,7 @@ var prefixes = struct { SocialPost string Staff string Segment string + Product string Campaign string Affiliate string }{ @@ -30,6 +31,7 @@ var prefixes = struct { SocialPost: "social_post", Staff: "staff", Segment: "segment", + Product: "product", Campaign: "campaign", Affiliate: "affiliate", } diff --git a/subject/product.go b/subject/product.go new file mode 100644 index 0000000..3911ecb --- /dev/null +++ b/subject/product.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +// getSegmentValue ... +func getProductValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Product, val) +} + +var Product = struct { + ApplyRequest string +}{ + ApplyRequest: getProductValue("apply_request"), +} From e66596baf6b9270ec7df4502ccfd43a6c25116eb Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 26 Dec 2022 15:12:48 +0700 Subject: [PATCH 3/3] define nats queue --- model/queue_request.go | 8 ++++++++ subject/config.go | 2 ++ subject/queue.go | 13 +++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 model/queue_request.go create mode 100644 subject/queue.go diff --git a/model/queue_request.go b/model/queue_request.go new file mode 100644 index 0000000..87b7410 --- /dev/null +++ b/model/queue_request.go @@ -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 +} diff --git a/subject/config.go b/subject/config.go index 483f963..0ba5952 100644 --- a/subject/config.go +++ b/subject/config.go @@ -15,6 +15,7 @@ var prefixes = struct { Staff string Segment string Product string + Queue string Campaign string Affiliate string }{ @@ -32,6 +33,7 @@ var prefixes = struct { Staff: "staff", Segment: "segment", Product: "product", + Queue: "queue", Campaign: "campaign", Affiliate: "affiliate", } diff --git a/subject/queue.go b/subject/queue.go new file mode 100644 index 0000000..87a84ef --- /dev/null +++ b/subject/queue.go @@ -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"), +}