From 89967955ea2af42c918b213a4183f2d3a471db93 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Mon, 19 Sep 2022 11:48:30 +0700 Subject: [PATCH] get list seller by ids --- client/seller.go | 25 +++++++++++++++++++++++++ model/seller_request.go | 5 +++++ model/seller_response.go | 5 +++++ subject/seller.go | 6 ++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/client/seller.go b/client/seller.go index ec3ab83..5944bdb 100644 --- a/client/seller.go +++ b/client/seller.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio/model" "github.com/Selly-Modules/natsio/subject" @@ -38,3 +39,27 @@ func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.Response return r.Data, nil } + +// GetListSellerInfoByIDs ... +func (s Seller) GetListSellerInfoByIDs(p model.GetListSellerByIDsRequest) (*model.ResponseListSellerInfo, error) { + msg, err := natsio.GetServer().Request(subject.Seller.GetListSellerInfoByIDs, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListSellerInfo `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/seller_request.go b/model/seller_request.go index 997cd97..29732b9 100644 --- a/model/seller_request.go +++ b/model/seller_request.go @@ -6,3 +6,8 @@ import "go.mongodb.org/mongo-driver/bson/primitive" type GetSellerByIDRequest struct { SellerID primitive.ObjectID `json:"sellerId"` } + +// GetListSellerByIDsRequest ... +type GetListSellerByIDsRequest struct { + SellerIDs []primitive.ObjectID `json:"sellerIds"` +} diff --git a/model/seller_response.go b/model/seller_response.go index 6b7d698..5dd5271 100644 --- a/model/seller_response.go +++ b/model/seller_response.go @@ -6,3 +6,8 @@ type ResponseSellerInfo struct { Name string `json:"name"` Code string `json:"code"` } + +// ResponseListSellerInfo ... +type ResponseListSellerInfo struct { + Sellers []ResponseSellerInfo `json:"sellers"` +} diff --git a/subject/seller.go b/subject/seller.go index 033f993..ab3ac20 100644 --- a/subject/seller.go +++ b/subject/seller.go @@ -8,7 +8,9 @@ func getSellerValue(val string) string { // Seller ... var Seller = struct { - GetSellerInfoByID string + GetSellerInfoByID string + GetListSellerInfoByIDs string }{ - GetSellerInfoByID: getSellerValue("get_seller_info_by_id"), + GetSellerInfoByID: getSellerValue("get_seller_info_by_id"), + GetListSellerInfoByIDs: getSellerValue("get_list_seller_info_by_ids"), }