Merge branch 'master' of git.selly.red:Selly-Modules/natsio into integrate-onpoint

This commit is contained in:
Sinh 2022-11-02 09:39:52 +07:00
commit 4d8a64364f
12 changed files with 359 additions and 19 deletions

View File

@ -79,7 +79,6 @@ func (s Seller) GetListSellerInfoSupportChatByIDs(p model.GetListSellerSupportCh
if err := json.Unmarshal(msg.Data, &r); err != nil { if err := json.Unmarshal(msg.Data, &r); err != nil {
return nil, err return nil, err
} }
if r.Error != "" { if r.Error != "" {
return nil, errors.New(r.Error) return nil, errors.New(r.Error)

58
client/supplier_role.go Normal file
View File

@ -0,0 +1,58 @@
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"
)
// SupplierRole ...
type SupplierRole struct{}
// GetSupplierRole ...
func GetSupplierRole() SupplierRole {
return SupplierRole{}
}
func (s SupplierRole) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateRoleResponse `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
}
func (s SupplierRole) UpdateRole(p model.UpdateRoleRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierRole.Update, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

140
client/supplier_user.go Normal file
View File

@ -0,0 +1,140 @@
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"
)
// SupplierUser ...
type SupplierUser struct{}
// GetSupplierUser ...
func GetSupplierUser() SupplierUser {
return SupplierUser{}
}
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateOwnerResponse `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
}
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateOwnerRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateOwner, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateStaffRequest) (*model.CreateStaffResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateStaff, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateStaffResponse `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
}
func (s SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetPasswordResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.ResetPassword, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResetPasswordResponse `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
}

View File

@ -21,16 +21,25 @@ type ResponseListSellerInfoSupportChat struct {
// ResponseSellerInfoSupportChat ... // ResponseSellerInfoSupportChat ...
type ResponseSellerInfoSupportChat struct { type ResponseSellerInfoSupportChat struct {
ID string `json:"_id"` ID string `json:"_id"`
Name string `json:"name"` Name string `json:"name"`
Code string `json:"code"` Code string `json:"code"`
Membership SellerMembershipInfo `json:"membership"` Membership SellerMembershipInfo `json:"membership"`
Info SellerContactInfo `json:"info"` Info SellerContactInfo `json:"info"`
Team *TeamInfo `json:"team,omitempty"` Team *TeamInfo `json:"team,omitempty"`
Statistic SellerStatistic `json:"statistic"` Statistic SellerStatistic `json:"statistic"`
TrackingTime *SellerTrackingTime `json:"trackingTime"` TrackingTime *SellerTrackingTime `json:"trackingTime"`
Invitee *InviteeInfo `json:"invitee"` Invitee *InviteeInfo `json:"invitee"`
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
PlanPackage *SellerPlanPackageInfo `json:"planPackage"`
}
// SellerPlanPackageInfo ...
type SellerPlanPackageInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
Level int `json:"level"`
CreatedAt time.Time `json:"createdAt"`
} }
// SellerTrackingTime ... // SellerTrackingTime ...

View File

@ -0,0 +1,14 @@
package model
type CreateRoleRequest struct {
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
}
type UpdateRoleRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
}

View File

@ -0,0 +1,5 @@
package model
type CreateRoleResponse struct {
ID string `json:"_id"`
}

View File

@ -0,0 +1,51 @@
package model
type CreateOwnerRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
SupplierID string `json:"supplierId"`
RoleID string `json:"roleId"`
Password string `json:"password"`
}
type UpdateOwnerRequest struct {
ID string `json:"_id"`
SupplierID string `json:"supplierId"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
RoleID string `json:"roleId"`
}
type CreateStaffRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
SupplierID string `json:"supplierId"`
RoleID string `json:"roleId"`
Password string `json:"password"`
Warehouses []string `json:"warehouses"`
}
type UpdateStaffRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
SupplierID string `json:"supplierId"`
RoleID string `json:"roleId"`
Password string `json:"password"`
SupplierUserWarehouseID string `json:"supplierUserWarehouseId"`
Warehouses []string `json:"warehouses"`
}
type UpdateStatusRequest struct {
ID string `json:"_id"`
Status string `json:"status"`
}
type ResetPasswordRequest struct {
ID string `json:"_id"`
Password string `json:"password"`
}

View File

@ -0,0 +1,13 @@
package model
type CreateOwnerResponse struct {
ID string `json:"_id"`
}
type CreateStaffResponse struct {
ID string `json:"_id"`
}
type ResetPasswordResponse struct {
Password string `json:"password"`
}

View File

@ -18,14 +18,21 @@ type OutboundRequestResponse struct {
// WarehouseConfiguration ... // WarehouseConfiguration ...
type WarehouseConfiguration struct { type WarehouseConfiguration struct {
Warehouse string `json:"warehouse"` Warehouse string `json:"warehouse"`
DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"` DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"`
Supplier WarehouseSupplier `json:"supplier"` Supplier WarehouseSupplier `json:"supplier"`
Order WarehouseOrder `json:"order"` Order WarehouseOrder `json:"order"`
Partner WarehousePartner `json:"partner"` Partner WarehousePartner `json:"partner"`
Delivery WarehouseDelivery `json:"delivery"` Delivery WarehouseDelivery `json:"delivery"`
Other WarehouseOther `json:"other"` Other WarehouseOther `json:"other"`
Food WarehouseFood `json:"food"` Food WarehouseFood `json:"food"`
AutoConfirmOrder WarehouseOrderConfirm `json:"autoConfirmOrder"`
}
// WarehouseOrderConfirm ...
type WarehouseOrderConfirm struct {
IsEnable bool `json:"isEnable"`
ConfirmDelayInSeconds int64 `json:"confirmDelayInSeconds"`
} }
// WarehouseFood ... // WarehouseFood ...

View File

@ -9,6 +9,8 @@ var prefixes = struct {
Bank string Bank string
Supplier string Supplier string
Seller string Seller string
SupplierUser string
SupplierRole string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -18,4 +20,6 @@ var prefixes = struct {
Supplier: "supplier", Supplier: "supplier",
Bank: "bank", Bank: "bank",
Seller: "seller", Seller: "seller",
SupplierUser: "supplier_user",
SupplierRole: "supplier_role",
} }

15
subject/supplier_role.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
func getRoleValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.SupplierRole, val)
}
var SupplierRole = struct {
Create string
Update string
}{
Create: getRoleValue("create"),
Update: getRoleValue("update"),
}

25
subject/supplier_user.go Normal file
View File

@ -0,0 +1,25 @@
package subject
import "fmt"
func getSupplierUserValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.SupplierUser, val)
}
var SupplierUser = struct {
// Users
CreateOwner string
UpdateOwner string
CreateStaff string
UpdateStaff string
UpdateStatus string
ResetPassword string
}{
// Users
CreateOwner: getSupplierUserValue("create_owner"),
UpdateOwner: getSupplierUserValue("update_owner"),
CreateStaff: getSupplierUserValue("create_staff"),
UpdateStaff: getSupplierUserValue("update_staff"),
UpdateStatus: getSupplierUserValue("update_status"),
ResetPassword: getSupplierUserValue("reset_password"),
}