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/supplier.go b/client/supplier.go index 1ed20d0..9b53826 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 { @@ -101,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/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/supplier_request.go b/model/supplier_request.go index 5a19924..18034af 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -38,3 +38,17 @@ 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"` + Status string `json:"status"` // active,inactive +} + +type SupplierCountReq struct { + Segment string `json:"segment"` + IDs []string `json:"ids"` + Status string `json:"status"` // active,inactive +} 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/config.go b/subject/config.go index 2a2f743..f05d685 100644 --- a/subject/config.go +++ b/subject/config.go @@ -13,6 +13,7 @@ var prefixes = struct { SupplierRole string SocialPost string Staff string + Segment string }{ Communication: "communication", Order: "order", @@ -26,4 +27,5 @@ var prefixes = struct { SupplierRole: "supplier_role", SocialPost: "social_post", 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/supplier.go b/subject/supplier.go index 17ca8d0..edc797f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,12 @@ var Supplier = struct { GetListSupplierInfo string 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"), }