Merge branch 'master' of github.com:Selly-Modules/natsio into get-location-warehouse

This commit is contained in:
phuanbui 2022-08-26 17:22:16 +07:00
commit cab7525f50
9 changed files with 67 additions and 30 deletions

View File

@ -18,7 +18,7 @@ func GetCommunication() Communication {
// RequestHttp ... // RequestHttp ...
func (c Communication) RequestHttp(p model.CommunicationRequestHttp) (r *model.CommunicationHttpResponse, err error) { func (c Communication) RequestHttp(p model.CommunicationRequestHttp) (r *model.CommunicationHttpResponse, err error) {
msg, err := natsio.GetServer().Request(subject.CommunicationRequestHTTP, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Communication.RequestHTTP, toBytes(p))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,7 +19,7 @@ func GetOrder() Order {
// UpdateORStatus ... // UpdateORStatus ...
func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error { func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p))
if err != nil { if err != nil {
return err return err
} }
@ -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.OrderUpdateORStatus, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p))
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,7 @@ func GetWarehouse() Warehouse {
// CreateOutboundRequest ... // CreateOutboundRequest ...
func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model.OutboundRequestResponse, error) { func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model.OutboundRequestResponse, error) {
msg, err := natsio.GetServer().Request(subject.WarehouseCreateOutboundRequest, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Warehouse.CreateOutboundRequest, toBytes(p))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -38,7 +38,7 @@ func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model
// UpdateOutboundRequestLogisticInfo ... // UpdateOutboundRequestLogisticInfo ...
func (w Warehouse) UpdateOutboundRequestLogisticInfo(p model.UpdateOutboundRequestLogisticInfoPayload) error { func (w Warehouse) UpdateOutboundRequestLogisticInfo(p model.UpdateOutboundRequestLogisticInfoPayload) error {
msg, err := natsio.GetServer().Request(subject.WarehouseUpdateOutboundRequestLogistic, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateOutboundRequestLogistic, toBytes(p))
if err != nil { if err != nil {
return err return err
} }
@ -56,7 +56,7 @@ func (w Warehouse) UpdateOutboundRequestLogisticInfo(p model.UpdateOutboundReque
// CancelOutboundRequest ... // CancelOutboundRequest ...
func (w Warehouse) CancelOutboundRequest(p model.CancelOutboundRequest) error { func (w Warehouse) CancelOutboundRequest(p model.CancelOutboundRequest) error {
msg, err := natsio.GetServer().Request(subject.WarehouseCancelOutboundRequest, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Warehouse.CancelOutboundRequest, toBytes(p))
if err != nil { if err != nil {
return err return err
} }
@ -74,7 +74,7 @@ func (w Warehouse) CancelOutboundRequest(p model.CancelOutboundRequest) error {
// GetConfigByWarehouseID ... // GetConfigByWarehouseID ...
func (w Warehouse) GetConfigByWarehouseID(warehouseID string) (*model.WarehouseConfiguration, error) { func (w Warehouse) GetConfigByWarehouseID(warehouseID string) (*model.WarehouseConfiguration, error) {
msg, err := natsio.GetServer().Request(subject.WarehouseGetConfiguration, toBytes(warehouseID)) msg, err := natsio.GetServer().Request(subject.Warehouse.GetConfiguration, toBytes(warehouseID))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -34,8 +34,8 @@ type WarehouseSupplier struct {
type WarehouseOrder struct { type WarehouseOrder struct {
MinimumValue float64 `json:"minimumValue"` MinimumValue float64 `json:"minimumValue"`
PaymentMethod WarehousePaymentMethod `json:"paymentMethod"` PaymentMethod WarehousePaymentMethod `json:"paymentMethod"`
IsLimitNumberOfPurchases bool `json:"isLimitNumberOfPurchases" json:"isLimitNumberOfPurchases"` IsLimitNumberOfPurchases bool `json:"isLimitNumberOfPurchases"`
LimitNumberOfPurchases int64 `json:"limitNumberOfPurchases" json:"limitNumberOfPurchases"` LimitNumberOfPurchases int64 `json:"limitNumberOfPurchases"`
} }
// WarehousePaymentMethod ... // WarehousePaymentMethod ...

View File

@ -3,7 +3,6 @@ package natsio
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/logrusorgru/aurora"
"github.com/nats-io/nats.go" "github.com/nats-io/nats.go"
) )
@ -49,7 +48,7 @@ func Connect(cfg Config) error {
return errors.New(msg) return errors.New(msg)
} }
fmt.Println(aurora.Green("*** CONNECTED TO NATS: " + cfg.URL)) fmt.Printf("⚡️[natsio]: connected to %s \n", cfg.URL)
// Set client // Set client
natsServer.instance = nc natsServer.instance = nc

View File

@ -1,10 +1,19 @@
package subject package subject
const communicationPrefix = "communication_" import "fmt"
const ( func getCommunicationValue(val string) string {
CommunicationRequestHTTP = communicationPrefix + "request_http" return fmt.Sprintf("%s.%s", prefixes.Communication, val)
CommunicationResponseHTTP = communicationPrefix + "response_http" }
CommunicationWebhookTNC = communicationPrefix + "webhook_tnc"
CommunicationWebhookGlobalCare = communicationPrefix + "webhook_global_care" var Communication = struct {
) RequestHTTP string
ResponseHTTP string
WebhookTNC string
WebhookGlobalCare string
}{
RequestHTTP: getCommunicationValue("request_http"),
ResponseHTTP: getCommunicationValue("response_http"),
WebhookTNC: getCommunicationValue("webhook_tnc"),
WebhookGlobalCare: getCommunicationValue("webhook_global_care"),
}

11
subject/config.go Normal file
View File

@ -0,0 +1,11 @@
package subject
var prefixes = struct {
Communication string
Order string
Warehouse string
}{
Communication: "communication",
Order: "order",
Warehouse: "warehouse",
}

View File

@ -1,8 +1,17 @@
package subject package subject
const orderPrefix = "order_" import "fmt"
const ( func getOrderValue(val string) string {
OrderUpdateORStatus = orderPrefix + "update_outbound_request_status" return fmt.Sprintf("%s.%s", prefixes.Order, val)
OrderCancelDelivery = orderPrefix + "cancel_delivery" }
)
var Order = struct {
UpdateORStatus string
CancelDelivery string
WebhookTNC string
WebhookGlobalCare string
}{
UpdateORStatus: getOrderValue("update_outbound_request_status"),
CancelDelivery: getOrderValue("cancel_delivery"),
}

View File

@ -1,10 +1,19 @@
package subject package subject
const warehousePrefix = "warehouse_" import "fmt"
const ( func getWarehouseValue(val string) string {
WarehouseCreateOutboundRequest = warehousePrefix + "create_outbound_request" return fmt.Sprintf("%s.%s", prefixes.Warehouse, val)
WarehouseUpdateOutboundRequestLogistic = warehousePrefix + "update_outbound_request_logistic_info" }
WarehouseCancelOutboundRequest = warehousePrefix + "cancel_outbound_request"
WarehouseGetConfiguration = warehousePrefix + "get_configuration" var Warehouse = struct {
) CreateOutboundRequest string
UpdateOutboundRequestLogistic string
CancelOutboundRequest string
GetConfiguration string
}{
CreateOutboundRequest: getWarehouseValue("create_outbound_request"),
UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"),
CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"),
GetConfiguration: getWarehouseValue("get_configuration"),
}