seller by id

This commit is contained in:
Nguyen Minh 2022-09-15 14:09:54 +07:00
parent 738089755a
commit 40533e1805
5 changed files with 72 additions and 0 deletions

40
client/seller.go Normal file
View File

@ -0,0 +1,40 @@
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// Seller ...
type Seller struct{}
// GetSeller ...
func GetSeller() Seller {
return Seller{}
}
// GetSellerInfoByID ...
func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.ResponseSellerInfo, error) {
msg, err := natsio.GetServer().Request(subject.Seller.GetSellerInfoByID, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseSellerInfo `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
}

8
model/seller_request.go Normal file
View File

@ -0,0 +1,8 @@
package model
import "go.mongodb.org/mongo-driver/bson/primitive"
// GetSellerByIDRequest ...
type GetSellerByIDRequest struct {
SellerID primitive.ObjectID `json:"sellerId"`
}

8
model/seller_response.go Normal file
View File

@ -0,0 +1,8 @@
package model
// ResponseSellerInfo ...
type ResponseSellerInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Code string `json:"code"`
}

View File

@ -6,10 +6,12 @@ var prefixes = struct {
Warehouse string Warehouse string
Location string Location string
Supplier string Supplier string
Seller string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
Warehouse: "warehouse", Warehouse: "warehouse",
Location: "location", Location: "location",
Supplier: "supplier", Supplier: "supplier",
Seller: "seller",
} }

14
subject/seller.go Normal file
View File

@ -0,0 +1,14 @@
package subject
import "fmt"
func getSellerValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Seller, val)
}
// Seller ...
var Seller = struct {
GetSellerInfoByID string
}{
GetSellerInfoByID: getSellerValue("get_seller_info_by_id"),
}