From d45da3e74c6d7d02ed728c8d630c47462af6efcc Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 18 Nov 2022 10:13:41 +0700 Subject: [PATCH 1/4] nats - get supplier from old server --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 7 +++++++ subject/supplier.go | 2 ++ 3 files changed, 30 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 1ed20d0..e278f46 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -80,6 +80,27 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl return r.Data, nil } +func (s Supplier) FindAllOld(req model.SupplierFindAllReq) (*model.SupplierAll, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.FindAllOld, toBytes(req)) + 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 +} + func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) { msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID)) if err != nil { diff --git a/model/supplier_request.go b/model/supplier_request.go index 5a19924..118737d 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -38,3 +38,10 @@ type UpdateSupplierWarehousePayload struct { DistrictCode int `json:"districtCode"` WardCode int `json:"wardCode"` } + +type SupplierFindAllReq struct { + Page int64 `json:"page"` + Limit int64 `json:"limit"` + Segment string `json:"segment"` + IDs []string `json:"ids"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 17ca8d0..92af7b3 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,10 @@ var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string + FindAllOld string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), + FindAllOld: getSupplierValue("find_all_old"), } From 8248069bb86310fb30d839ff03d50553ea508530 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 23 Nov 2022 10:08:52 +0700 Subject: [PATCH 2/4] count supplier --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 5 +++++ model/supplier_response.go | 4 ++++ subject/supplier.go | 2 ++ 4 files changed, 32 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index e278f46..9b53826 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -122,6 +122,27 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod return r.Data, nil } +func (s Supplier) Count(req model.SupplierCountReq) (*model.SupplierCountRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.Count, toBytes(req)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierCountRes `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 +} + // CreateWarehouseIntoServiceSupplier ... func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p)) diff --git a/model/supplier_request.go b/model/supplier_request.go index 118737d..bbba857 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -45,3 +45,8 @@ type SupplierFindAllReq struct { Segment string `json:"segment"` IDs []string `json:"ids"` } + +type SupplierCountReq struct { + Segment string `json:"segment"` + IDs []string `json:"ids"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index 975a8de..2b9dd10 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -29,3 +29,7 @@ type SupplierAll struct { Suppliers []SupplierBrief `json:"suppliers"` Total int64 `json:"total"` } + +type SupplierCountRes struct { + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 92af7b3..edc797f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -11,9 +11,11 @@ var Supplier = struct { GetSupplierContractBySupplierID string FindAll string FindAllOld string + Count string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), FindAllOld: getSupplierValue("find_all_old"), + Count: getSupplierValue("count"), } From c47768308c66c19d120519ba5e1feaef6ff811b4 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Wed, 23 Nov 2022 10:29:50 +0700 Subject: [PATCH 3/4] add nats --- client/segmnet.go | 41 +++++++++++++++++++++++++++++++++++++++ client/staff.go | 41 +++++++++++++++++++++++++++++++++++++++ model/segment_request.go | 6 ++++++ model/segment_response.go | 12 ++++++++++++ model/staff_request.go | 6 ++++++ model/staff_response.go | 12 ++++++++++++ subject/config.go | 4 ++++ subject/segment.go | 15 ++++++++++++++ subject/staff.go | 14 +++++++++++++ 9 files changed, 151 insertions(+) create mode 100644 client/segmnet.go create mode 100644 client/staff.go create mode 100644 model/segment_request.go create mode 100644 model/segment_response.go create mode 100644 model/staff_request.go create mode 100644 model/staff_response.go create mode 100644 subject/segment.go create mode 100644 subject/staff.go diff --git a/client/segmnet.go b/client/segmnet.go new file mode 100644 index 0000000..bcc7bab --- /dev/null +++ b/client/segmnet.go @@ -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 +} diff --git a/client/staff.go b/client/staff.go new file mode 100644 index 0000000..b175f53 --- /dev/null +++ b/client/staff.go @@ -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 + +} diff --git a/model/segment_request.go b/model/segment_request.go new file mode 100644 index 0000000..138f347 --- /dev/null +++ b/model/segment_request.go @@ -0,0 +1,6 @@ +package model + +// GetListSegmentRequest ... +type GetListSegmentRequest struct { + SegmentIds []string `json:"segmentIds"` +} diff --git a/model/segment_response.go b/model/segment_response.go new file mode 100644 index 0000000..84a1571 --- /dev/null +++ b/model/segment_response.go @@ -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"` +} diff --git a/model/staff_request.go b/model/staff_request.go new file mode 100644 index 0000000..176b34e --- /dev/null +++ b/model/staff_request.go @@ -0,0 +1,6 @@ +package model + +// GetListStaffRequest ... +type GetListStaffRequest struct { + StaffIds []string `json:"staffIds"` +} diff --git a/model/staff_response.go b/model/staff_response.go new file mode 100644 index 0000000..5076d0c --- /dev/null +++ b/model/staff_response.go @@ -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"` +} diff --git a/subject/config.go b/subject/config.go index 90a014f..b3117b3 100644 --- a/subject/config.go +++ b/subject/config.go @@ -11,6 +11,8 @@ var prefixes = struct { Seller string SupplierUser string SupplierRole string + Staff string + Segment string }{ Communication: "communication", Order: "order", @@ -22,4 +24,6 @@ var prefixes = struct { Seller: "seller", SupplierUser: "supplier_user", SupplierRole: "supplier_role", + Staff: "staff", + Segment: "segment", } diff --git a/subject/segment.go b/subject/segment.go new file mode 100644 index 0000000..f6021ca --- /dev/null +++ b/subject/segment.go @@ -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"), +} diff --git a/subject/staff.go b/subject/staff.go new file mode 100644 index 0000000..4777f06 --- /dev/null +++ b/subject/staff.go @@ -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"), +} From fb87ac7911f53a6fafed85702b42439b25cd2b14 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 24 Nov 2022 09:38:10 +0700 Subject: [PATCH 4/4] update nats --- model/supplier_request.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/supplier_request.go b/model/supplier_request.go index bbba857..18034af 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -44,9 +44,11 @@ type SupplierFindAllReq struct { Limit int64 `json:"limit"` Segment string `json:"segment"` IDs []string `json:"ids"` + Status string `json:"status"` // active,inactive } type SupplierCountReq struct { Segment string `json:"segment"` IDs []string `json:"ids"` + Status string `json:"status"` // active,inactive }