Develop #22

Merged
luuvansinh merged 56 commits from develop into master 2022-09-13 02:28:19 +00:00
13 changed files with 219 additions and 12 deletions
Showing only changes of commit b9a7d9648e - Show all commits

View File

@ -37,7 +37,7 @@ func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
// CancelDelivery ... // CancelDelivery ...
func (o Order) CancelDelivery(p model.OrderCancelDelivery) error { func (o Order) CancelDelivery(p model.OrderCancelDelivery) error {
msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Order.CancelDelivery, toBytes(p))
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,15 +17,36 @@ func GetSupplier() Supplier {
return Supplier{} return Supplier{}
} }
func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p))
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r struct { var r struct {
Data *model.ResponseSupplierInfo `json:"data"` Data []*model.ResponseSupplierInfo `json:"data"`
Error string `json:"error"` 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) GetSupplierContractBySupplierID(p model.GetSupplierContractRequest) (*model.ResponseSupplierContract, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierContractBySupplierID, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseSupplierContract `json:"data"`
Error string `json:"error"`
} }
if err := json.Unmarshal(msg.Data, &r); err != nil { if err := json.Unmarshal(msg.Data, &r); err != nil {

View File

@ -2,6 +2,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"go.mongodb.org/mongo-driver/bson"
"log" "log"
) )
@ -12,3 +13,9 @@ func toBytes(data interface{}) []byte {
} }
return b return b
} }
// bsonToBytes ...
func bsonToBytes(data interface{}) []byte {
b, _ := bson.Marshal(data)
return b
}

85
client/warehouse_dao.go Normal file
View File

@ -0,0 +1,85 @@
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// DistinctWithField ...
func (w Warehouse) DistinctWithField(p model.DistinctWithField) ([]interface{}, error) {
msg, err := natsio.GetServer().Request(subject.Warehouse.Distinct, bsonToBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data []interface{} `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
}
// FindOneByCondition ...
func (w Warehouse) FindOneByCondition(p model.FindOneCondition) (*model.WarehouseNatsResponse, error) {
msg, err := natsio.GetServer().Request(subject.Warehouse.FindOne, bsonToBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.WarehouseNatsResponse `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
}
// CountByCondition ...
func (w Warehouse) CountByCondition(p model.FindWithCondition) (int64, error) {
msg, err := natsio.GetServer().Request(subject.Warehouse.Count, bsonToBytes(p))
if err != nil {
return 0, err
}
var r struct {
Data int64 `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return 0, err
}
if r.Error != "" {
return 0, errors.New(r.Error)
}
return r.Data, nil
}
// FindByCondition ...
func (w Warehouse) FindByCondition(p model.FindWithCondition) ([]*model.WarehouseNatsResponse, error) {
msg, err := natsio.GetServer().Request(subject.Warehouse.FindByCondition, bsonToBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data []*model.WarehouseNatsResponse `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
}

2
go.sum
View File

@ -24,6 +24,8 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0=
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=

17
model/common_request.go Normal file
View File

@ -0,0 +1,17 @@
package model
import "go.mongodb.org/mongo-driver/mongo/options"
type FindWithCondition struct {
Conditions interface{} `json:"conditions"`
Opts []*options.FindOptions `json:"opts"`
}
type FindOneCondition struct {
Conditions interface{} `json:"conditions"`
}
type DistinctWithField struct {
Conditions interface{} `json:"conditions"`
Filed string `json:"filed"`
}

View File

@ -10,16 +10,19 @@ type ResponseLocationAddress struct {
type LocationProvince struct { type LocationProvince struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Code int `json:"code"`
} }
// LocationDistrict ... // LocationDistrict ...
type LocationDistrict struct { type LocationDistrict struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Code int `json:"code"`
} }
// LocationWard ... // LocationWard ...
type LocationWard struct { type LocationWard struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Code int `json:"code"`
} }

View File

@ -6,5 +6,9 @@ import (
// GetSupplierRequest ... // GetSupplierRequest ...
type GetSupplierRequest struct { type GetSupplierRequest struct {
ID primitive.ObjectID `json:"_id"` ListID []primitive.ObjectID `json:"listID"`
}
type GetSupplierContractRequest struct {
SupplierID primitive.ObjectID `json:"supplierID"`
} }

View File

@ -5,3 +5,11 @@ type ResponseSupplierInfo struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
// ResponseSupplierContract ...
type ResponseSupplierContract struct {
ID string `json:"id"`
Supplier string `json:"supplier"`
Name string `json:"name"`
Status string `json:"status"`
}

View File

@ -1,5 +1,7 @@
package model package model
import "time"
// OutboundRequestResponse ... // OutboundRequestResponse ...
type OutboundRequestResponse struct { type OutboundRequestResponse struct {
// System code // System code
@ -47,9 +49,9 @@ type WarehousePaymentMethod struct {
// WarehouseDelivery ... // WarehouseDelivery ...
type WarehouseDelivery struct { type WarehouseDelivery struct {
DeliveryMethods []string `json:"deliveryMethods"` DeliveryMethods []string `json:"deliveryMethods"`
PriorityServiceCodes []string `json:"priorityDeliveryServiceCodes"` PriorityServiceCodes []string `json:"priorityServiceCodes"`
EnabledSources []int `json:"enabledDeliverySources"` EnabledSources []int `json:"enabledSources"`
Types []string `json:"type"` Types []string `json:"types"`
} }
// WarehousePartner ... // WarehousePartner ...
@ -67,3 +69,47 @@ type SyncORStatusResponse struct {
Status string `json:"status"` Status string `json:"status"`
DeliveryStatus string `json:"deliveryStatus"` DeliveryStatus string `json:"deliveryStatus"`
} }
// ResponseWarehouseContact ...
type ResponseWarehouseContact struct {
Name string `json:"name"`
Phone string `json:"phone"`
Address string `json:"address"`
Email string `json:"email"`
}
// ResponseWarehouseLocation ...
type ResponseWarehouseLocation struct {
Province CommonLocation `json:"province"`
District CommonLocation `json:"district"`
Ward CommonLocation `json:"ward"`
Address string `json:"address"`
LocationCoordinates ResponseLatLng `json:"locationCoordinates"`
}
type CommonLocation struct {
ID string `json:"id"`
Name string `json:"name"`
Code int `json:"code"`
}
// ResponseLatLng ...
type ResponseLatLng struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
// WarehouseNatsResponse ...
type WarehouseNatsResponse struct {
ID string `json:"_id"`
Name string `json:"name"`
SearchString string `json:"searchString"`
Slug string `json:"slug"`
Status string `json:"status"`
Supplier string `json:"supplier"`
Contact ResponseWarehouseContact `json:"contact"`
Location ResponseWarehouseLocation `json:"location"`
Configurations WarehouseConfiguration `json:"configurations"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

View File

@ -18,7 +18,11 @@ func (sv Server) Request(subject string, payload []byte) (*nats.Msg, error) {
if sv.Config.RequestTimeout > 0 { if sv.Config.RequestTimeout > 0 {
timeout = sv.Config.RequestTimeout timeout = sv.Config.RequestTimeout
} }
return sv.instance.Request(subject, payload, timeout) msg, err := sv.instance.Request(subject, payload, timeout)
if errors.Is(err, nats.ErrNoResponders) {
log.Printf("[NATS SERVER]: request - no responders for subject: %s", subject)
}
return msg, err
} }
// Reply ... // Reply ...

View File

@ -7,7 +7,9 @@ func getSupplierValue(val string) string {
} }
var Supplier = struct { var Supplier = struct {
GetSupplierInfo string GetListSupplierInfo string
GetSupplierContractBySupplierID string
}{ }{
GetSupplierInfo: getSupplierValue("get_supplier_info"), GetListSupplierInfo: getSupplierValue("get_list_supplier_info"),
GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"),
} }

View File

@ -14,6 +14,10 @@ var Warehouse = struct {
SyncORStatus string SyncORStatus string
WebhookTNC string WebhookTNC string
WebhookGlobalCare string WebhookGlobalCare string
FindOne string
FindByCondition string
Distinct string
Count string
}{ }{
CreateOutboundRequest: getWarehouseValue("create_outbound_request"), CreateOutboundRequest: getWarehouseValue("create_outbound_request"),
UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"),
@ -22,4 +26,8 @@ var Warehouse = struct {
SyncORStatus: getWarehouseValue("sync_or_status"), SyncORStatus: getWarehouseValue("sync_or_status"),
WebhookTNC: getWarehouseValue("webhook_tnc"), WebhookTNC: getWarehouseValue("webhook_tnc"),
WebhookGlobalCare: getWarehouseValue("webhook_global_care"), WebhookGlobalCare: getWarehouseValue("webhook_global_care"),
FindOne: getWarehouseValue("find_one"),
FindByCondition: getWarehouseValue("find_all_by_condition"),
Distinct: getWarehouseValue("distinct"),
Count: getWarehouseValue("count"),
} }