From cc48a083f2f9f4c1b063c74ae755a940b7865cba Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 13 Sep 2022 11:47:46 +0700 Subject: [PATCH 1/8] [Update] Response warehouse --- model/warehouse_response.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index 2429743..f2d60a9 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -25,6 +25,20 @@ type WarehouseConfiguration struct { Partner WarehousePartner `json:"partner"` Delivery WarehouseDelivery `json:"delivery"` Other WarehouseOther `json:"other"` + Food WarehouseFood `json:"food"` +} + +// WarehouseFood ... +type WarehouseFood struct { + ForceClosed bool `json:"forceClosed"` + IsClosed bool `json:"isClosed"` + TimeRange []TimeRange `json:"timeRange"` +} + +// TimeRange ... +type TimeRange struct { + From int64 `json:"from"` + To int64 `json:"to"` } // WarehouseOther ... @@ -109,6 +123,7 @@ type ResponseLatLng struct { type WarehouseNatsResponse struct { ID string `json:"_id"` Staff string `json:"staff"` + BusinessType string `json:"businessType"` Name string `json:"name"` SearchString string `json:"searchString"` Slug string `json:"slug"` -- 2.34.1 From 9f1f2faf9e1066b7fcf9fd76eb667e352493a5a5 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 14 Sep 2022 14:39:16 +0700 Subject: [PATCH 2/8] [Update] Response supplier --- model/supplier_response.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/model/supplier_response.go b/model/supplier_response.go index a87a29e..975a8de 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -2,8 +2,9 @@ package model // ResponseSupplierInfo ... type ResponseSupplierInfo struct { - ID string `json:"id"` - Name string `json:"name"` + ID string `json:"id"` + Name string `json:"name"` + BusinessType string `json:"businessType"` } // ResponseSupplierContract ... @@ -16,11 +17,12 @@ type ResponseSupplierContract struct { // SupplierBrief ... type SupplierBrief struct { - ID string `json:"_id"` - Name string `json:"name"` - Status string `json:"status"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` + ID string `json:"_id"` + Name string `json:"name"` + Status string `json:"status"` + BusinessType string `json:"businessType"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` } type SupplierAll struct { -- 2.34.1 From fb8a8bd471bab82311c8356d2be2fab685d2afa1 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Fri, 16 Sep 2022 14:49:53 +0700 Subject: [PATCH 3/8] [Update] Add request updateIsClosedSupplier --- client/warehouse.go | 18 ++++++++++++++++++ model/warehouse_request.go | 11 +++++++++++ subject/warehouse.go | 2 ++ 3 files changed, 31 insertions(+) diff --git a/client/warehouse.go b/client/warehouse.go index 6c04925..43b3168 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -17,6 +17,24 @@ func GetWarehouse() Warehouse { return Warehouse{} } +// UpdateIsClosedSupplier ... +func (w Warehouse) UpdateIsClosedSupplier(p model.WarehouseNatsResponse) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateIsClosedSupplier, 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 +} + // AfterCreateWarehouse ... func (w Warehouse) AfterCreateWarehouse(p model.WarehouseNatsResponse) error { msg, err := natsio.GetServer().Request(subject.Warehouse.AfterCreateWarehouse, toBytes(p)) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 543fc68..b546725 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -69,3 +69,14 @@ type SyncORStatusRequest struct { ORCode string `json:"orCode"` OrderCode string `json:"orderCode"` } + +// UpdateSupplierIsClosedRequest ... +type UpdateSupplierIsClosedRequest struct { + Suppliers []SupplierIsClosed `json:"suppliers"` +} + +// SupplierIsClosed ... +type SupplierIsClosed struct { + Supplier string `json:"supplier"` + IsClosed bool `json:"isClosed"` +} diff --git a/subject/warehouse.go b/subject/warehouse.go index 5d0a81c..a0480ae 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -20,6 +20,7 @@ var Warehouse = struct { Count string AfterUpdateWarehouse string AfterCreateWarehouse string + UpdateIsClosedSupplier string }{ AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), @@ -34,4 +35,5 @@ var Warehouse = struct { FindByCondition: getWarehouseValue("find_all_by_condition"), Distinct: getWarehouseValue("distinct"), Count: getWarehouseValue("count"), + UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), } -- 2.34.1 From 92040d0b9f453256437f88a03956e31c0835b1cd Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Fri, 16 Sep 2022 15:36:32 +0700 Subject: [PATCH 4/8] [Update] Payload --- client/warehouse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/warehouse.go b/client/warehouse.go index 43b3168..fdb70b8 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -18,7 +18,7 @@ func GetWarehouse() Warehouse { } // UpdateIsClosedSupplier ... -func (w Warehouse) UpdateIsClosedSupplier(p model.WarehouseNatsResponse) error { +func (w Warehouse) UpdateIsClosedSupplier(p model.UpdateSupplierIsClosedRequest) error { msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateIsClosedSupplier, toBytes(p)) if err != nil { return err -- 2.34.1 From 1d58e55af736b32c7526d711161ef9509d6bb83f Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 20 Sep 2022 10:28:35 +0700 Subject: [PATCH 5/8] [Update] Request news --- client/news.go | 28 ++++++++++++++++++++++++++++ model/news_request.go | 6 ++++++ model/news_response.go | 38 ++++++++++++++++++++++++++++++++++++++ subject/config.go | 2 ++ subject/news.go | 13 +++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 client/news.go create mode 100644 model/news_request.go create mode 100644 model/news_response.go create mode 100644 subject/news.go diff --git a/client/news.go b/client/news.go new file mode 100644 index 0000000..162162d --- /dev/null +++ b/client/news.go @@ -0,0 +1,28 @@ +package client + +import ( + "encoding/json" + "errors" + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// GetProductNoticesByInventory ... +func (w Warehouse) GetProductNoticesByInventory(p model.GetProductNoticesByInventoryRequest) (*model.GetProductNoticesByInventoryResponse, error) { + msg, err := natsio.GetServer().Request(subject.News.GetProductNoticesByInventory, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.GetProductNoticesByInventoryResponse `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 +} diff --git a/model/news_request.go b/model/news_request.go new file mode 100644 index 0000000..fb886e3 --- /dev/null +++ b/model/news_request.go @@ -0,0 +1,6 @@ +package model + +// GetProductNoticesByInventoryRequest .... +type GetProductNoticesByInventoryRequest struct { + InventoryIds []string `json:"inventoryIds"` +} diff --git a/model/news_response.go b/model/news_response.go new file mode 100644 index 0000000..4b496c4 --- /dev/null +++ b/model/news_response.go @@ -0,0 +1,38 @@ +package model + +// GetProductNoticesByInventoryResponse .... +type GetProductNoticesByInventoryResponse struct { + Notices []NewsAppResponse `json:"notices"` +} + +// NewsAppResponse ... +type NewsAppResponse struct { + ID string `json:"_id"` + Title string `json:"title,omitempty"` + Target *TargetNewDoc `json:"target,omitempty"` + ActionType *ActionType `json:"action"` + ShortDesc string `json:"shortDesc,omitempty"` + Type string `json:"type"` + ShortTitle string `json:"shortTitle,omitempty"` + Color string `json:"color"` + Options *NewsOptions `json:"options,omitempty"` + DisplayStyle string `json:"displayStyle"` +} + +// NewsOptions ... +type NewsOptions struct { + Category string `json:"category"` +} + +// TargetNewDoc ... +type TargetNewDoc struct { + Type string `json:"type,omitempty"` + Value string `json:"value,omitempty"` +} + +// ActionType ... +type ActionType struct { + Type string `json:"type"` + Value string `json:"value"` + Text string `json:"text,omitempty"` +} diff --git a/subject/config.go b/subject/config.go index dfeea56..259e7ba 100644 --- a/subject/config.go +++ b/subject/config.go @@ -3,12 +3,14 @@ package subject var prefixes = struct { Communication string Order string + News string Warehouse string Location string Supplier string }{ Communication: "communication", Order: "order", + News: "news", Warehouse: "warehouse", Location: "location", Supplier: "supplier", diff --git a/subject/news.go b/subject/news.go new file mode 100644 index 0000000..3e96d25 --- /dev/null +++ b/subject/news.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getNewsValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Order, val) +} + +var News = struct { + GetProductNoticesByInventory string +}{ + GetProductNoticesByInventory: getNewsValue("get_product_notices_by_inventory"), +} -- 2.34.1 From 34c61ccfcc7d2ab95cd27969f54ed0a0eb460190 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 20 Sep 2022 10:56:45 +0700 Subject: [PATCH 6/8] [Update] --- client/news.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/news.go b/client/news.go index 162162d..4167c0a 100644 --- a/client/news.go +++ b/client/news.go @@ -8,8 +8,16 @@ import ( "github.com/Selly-Modules/natsio/subject" ) +// News ... +type News struct{} + +// GetNews ... +func GetNews() News { + return News{} +} + // GetProductNoticesByInventory ... -func (w Warehouse) GetProductNoticesByInventory(p model.GetProductNoticesByInventoryRequest) (*model.GetProductNoticesByInventoryResponse, error) { +func (n News) GetProductNoticesByInventory(p model.GetProductNoticesByInventoryRequest) (*model.GetProductNoticesByInventoryResponse, error) { msg, err := natsio.GetServer().Request(subject.News.GetProductNoticesByInventory, bsonToBytes(p)) if err != nil { return nil, err -- 2.34.1 From 4452be147432ae722cf941b3b7b223ee0af0d7c0 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 20 Sep 2022 13:49:58 +0700 Subject: [PATCH 7/8] [Update] Add subjects --- subject/news.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subject/news.go b/subject/news.go index 3e96d25..bfec6cf 100644 --- a/subject/news.go +++ b/subject/news.go @@ -3,7 +3,7 @@ package subject import "fmt" func getNewsValue(val string) string { - return fmt.Sprintf("%s.%s", prefixes.Order, val) + return fmt.Sprintf("%s.%s", prefixes.News, val) } var News = struct { -- 2.34.1 From 952c09ccba634573b47c9ed6faca0004b400426d Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 20 Sep 2022 14:46:29 +0700 Subject: [PATCH 8/8] fix news to bytes --- client/news.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/news.go b/client/news.go index 4167c0a..6bacf54 100644 --- a/client/news.go +++ b/client/news.go @@ -18,7 +18,7 @@ func GetNews() News { // GetProductNoticesByInventory ... func (n News) GetProductNoticesByInventory(p model.GetProductNoticesByInventoryRequest) (*model.GetProductNoticesByInventoryResponse, error) { - msg, err := natsio.GetServer().Request(subject.News.GetProductNoticesByInventory, bsonToBytes(p)) + msg, err := natsio.GetServer().Request(subject.News.GetProductNoticesByInventory, toBytes(p)) if err != nil { return nil, err } -- 2.34.1