From 0d3c931c8772f6933ca1c6e785f03c056fc69b5e Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 4 Nov 2022 10:28:09 +0700 Subject: [PATCH] define nats func - supplier balance --- client/notification.go | 31 +++++++++++++++++++++++++++++++ model/notification_request.go | 7 +++++++ model/notification_response.go | 1 + subject/config.go | 2 ++ subject/notification.go | 13 +++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 client/notification.go create mode 100644 model/notification_request.go create mode 100644 model/notification_response.go create mode 100644 subject/notification.go diff --git a/client/notification.go b/client/notification.go new file mode 100644 index 0000000..66c4b52 --- /dev/null +++ b/client/notification.go @@ -0,0 +1,31 @@ +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" +) + +func GetNotification() Notification { + return Notification{} +} + +type Notification struct{} + +func (n Notification) SupplierChangeBalanceRequestApproved(p model.NotificationSupplierChangeBalanceRequestApprovedReq) error { + msg, err := natsio.GetServer().Request(subject.Notification.SupplierChangeBalanceRequestApproved, toBytes(p)) + if err != nil { + return err + } + var r model.CommonResponseData + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} diff --git a/model/notification_request.go b/model/notification_request.go new file mode 100644 index 0000000..bbef9c4 --- /dev/null +++ b/model/notification_request.go @@ -0,0 +1,7 @@ +package model + +type NotificationSupplierChangeBalanceRequestApprovedReq struct { + SupplierID string `json:"supplierId"` + Cash float64 `json:"cash"` + Reason string `json:"reason"` +} diff --git a/model/notification_response.go b/model/notification_response.go new file mode 100644 index 0000000..8b53790 --- /dev/null +++ b/model/notification_response.go @@ -0,0 +1 @@ +package model diff --git a/subject/config.go b/subject/config.go index 4bd7454..cbb0f1d 100644 --- a/subject/config.go +++ b/subject/config.go @@ -8,6 +8,7 @@ var prefixes = struct { Location string Bank string Supplier string + Notification string Seller string SupplierUser string SupplierRole string @@ -20,6 +21,7 @@ var prefixes = struct { Warehouse: "warehouse", Location: "location", Supplier: "supplier", + Notification: "notification", Bank: "bank", Seller: "seller", SupplierUser: "supplier_user", diff --git a/subject/notification.go b/subject/notification.go new file mode 100644 index 0000000..317655f --- /dev/null +++ b/subject/notification.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getNotificationValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Notification, val) +} + +var Notification = struct { + SupplierChangeBalanceRequestApproved string +}{ + SupplierChangeBalanceRequestApproved: getNotificationValue("supplier_change_balance_request_approved"), +}