Pull origin build-auth-sms into refactor-supplier

This commit is contained in:
Sinh 2022-11-03 11:09:36 +07:00
commit b345cd5395
16 changed files with 375 additions and 37 deletions

View File

@ -0,0 +1,79 @@
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"
)
// SupplierPermission ...
type SupplierPermission struct{}
// GetSupplierPermission ...
func GetSupplierPermission() SupplierPermission {
return SupplierPermission{}
}
func (s SupplierPermission) GetListPermission(p model.GetListPermissionRequest) (*model.GetListPermissionResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierPermission.GetList, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.GetListPermissionResponse `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 SupplierPermission) CreatePermission(p model.CreatePermissionRequest) (*model.CreatePermissionResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierPermission.Create, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreatePermissionResponse `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 SupplierPermission) UpdatePermission(p model.UpdatePermissionRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierPermission.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
}

View File

@ -16,8 +16,28 @@ func GetSupplierRole() SupplierRole {
return SupplierRole{} return SupplierRole{}
} }
func (s SupplierRole) GetListRole(p model.GetListRoleRequest) (*model.GetListRoleResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierRole.GetList, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.GetListRoleResponse `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) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) { func (s SupplierRole) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p)) msg, err := natsio.GetServer().Request(subject.SupplierRole.Create, toBytes(p))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,3 +76,24 @@ func (s SupplierRole) UpdateRole(p model.UpdateRoleRequest) error {
return nil return nil
} }
func (s SupplierRole) DetailRole(p model.DetailRoleRequest) (*model.RoleBrief, error) {
msg, err := natsio.GetServer().Request(subject.SupplierRole.Detail, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.RoleBrief `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

@ -16,6 +16,48 @@ func GetSupplierUser() SupplierUser {
return SupplierUser{} return SupplierUser{}
} }
func (s SupplierUser) LoginUser(p model.LoginUserRequest) (*model.LoginUserResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.LoginUser, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.LoginUserResponse `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) GetListUser(p model.GetListUserRequest) (*model.GetListUserResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.GetListUser, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.GetListUserResponse `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) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) { func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p)) msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil { if err != nil {
@ -99,7 +141,7 @@ func (s SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error
} }
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error { func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p)) msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStatus, toBytes(p))
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1 @@
package model

View File

@ -0,0 +1 @@
package model

View File

@ -0,0 +1,24 @@
package model
type GetListPermissionRequest struct {
Page int `json:"page"`
Limit int `json:"limit"`
Group string `json:"group"`
}
type DetailPermissionRequest struct {
ID string `json:"_id"`
}
type CreatePermissionRequest struct {
Name string `json:"name"`
Code string `json:"code"`
Group string `json:"group"`
}
type UpdatePermissionRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Group string `json:"group"`
}

View File

@ -0,0 +1,26 @@
package model
type GetListPermissionResponse struct {
Permissions []PermissionBrief `json:"permissions"`
Total int64 `json:"total"`
}
type PermissionBrief struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Group string `json:"group"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type CreatePermissionResponse struct {
ID string `json:"_id"`
}
type PermissionShort struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Group string `json:"group"`
}

View File

@ -33,3 +33,9 @@ type SupplierAll struct {
type SupplierCashflowCreateResponse struct { type SupplierCashflowCreateResponse struct {
ID string `json:"id"` ID string `json:"id"`
} }
type SupplierShort struct {
ID string `json:"_id"`
Name string `json:"name"`
Logo interface{} `json:"logo"`
}

View File

@ -1,14 +1,29 @@
package model package model
type GetListRoleRequest struct {
Page int `json:"page"`
Limit int `json:"limit"`
Type string `json:"type"`
SupplierID string `json:"supplierId"`
}
type DetailRoleRequest struct {
ID string `json:"_id"`
}
type CreateRoleRequest struct { type CreateRoleRequest struct {
Name string `json:"name"` Name string `json:"name"`
Code string `json:"code"` Code string `json:"code"`
Type string `json:"type"` Type string `json:"type"`
SupplierID string `json:"supplierId"`
Permissions []string `json:"permissions"`
} }
type UpdateRoleRequest struct { type UpdateRoleRequest 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"`
Type string `json:"type"` Type string `json:"type"`
SupplierID string `json:"supplierId"`
Permissions []string `json:"permissions"`
} }

View File

@ -1,5 +1,29 @@
package model package model
type GetListRoleResponse struct {
Roles []RoleBrief `json:"roles"`
Total int64 `json:"total"`
}
type RoleBrief struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
Permissions []PermissionShort `json:"permissions"`
SupplierId string `json:"supplierId"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type CreateRoleResponse struct { type CreateRoleResponse struct {
ID string `json:"_id"` ID string `json:"_id"`
} }
type RoleShort struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
SupplierId string `json:"supplierId"`
}

View File

@ -1,5 +1,30 @@
package model package model
type LoginUserRequest struct {
Email string `json:"email"`
Password string `json:"password"`
DeviceID string `json:"deviceId"`
AppVersion string `json:"appVersion"`
UserAgent string `json:"userAgent"`
Model string `json:"model"`
Manufacturer string `json:"manufacturer"`
IP string `json:"ip"`
Language string `json:"language"`
FCMToken string `json:"FCMToken"`
AuthToken string `json:"authToken"`
OsName string `json:"osName"`
OsVersion string `json:"osVersion"`
IsMobile bool `json:"isMobile"`
}
type GetListUserRequest struct {
Page int `json:"page"`
Limit int `json:"limit"`
Status string `json:"status"`
Type string `json:"type"`
SupplierID string `json:"supplierId"`
}
type CreateOwnerRequest struct { type CreateOwnerRequest struct {
Name string `json:"name"` Name string `json:"name"`
Phone string `json:"phone"` Phone string `json:"phone"`
@ -46,6 +71,5 @@ type UpdateStatusRequest struct {
} }
type ResetPasswordRequest struct { type ResetPasswordRequest struct {
ID string `json:"_id"` ID string `json:"_id"`
Password string `json:"password"`
} }

View File

@ -1,5 +1,31 @@
package model package model
// LoginUserResponse ...
type LoginUserResponse struct {
ID string `json:"_id"`
RequireToChangePassword bool `json:"requireToChangePassword"`
SupplierID string `json:"supplierId"`
}
type GetListUserResponse struct {
SupplierUsers []SupplierUserBrief `json:"supplierUsers"`
Total int64 `json:"total"`
}
type SupplierUserBrief struct {
ID string `json:"_id"`
Role RoleShort `json:"role"`
SupplierID string `json:"supplierId"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Status string `json:"status"`
Avatar interface{} `json:"avatar"`
Type string `json:"type"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type CreateOwnerResponse struct { type CreateOwnerResponse struct {
ID string `json:"_id"` ID string `json:"_id"`
} }

View File

@ -1,27 +1,29 @@
package subject package subject
var prefixes = struct { var prefixes = struct {
Communication string Communication string
Order string Order string
News string News string
Warehouse string Warehouse string
Location string Location string
Bank string Bank string
Supplier string Supplier string
Seller string Seller string
SupplierUser string SupplierUser string
SupplierRole string SupplierRole string
Withdraw string Withdraw string
SupplierPermission string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
News: "news", News: "news",
Warehouse: "warehouse", Warehouse: "warehouse",
Location: "location", Location: "location",
Supplier: "supplier", Supplier: "supplier",
Bank: "bank", Bank: "bank",
Seller: "seller", Seller: "seller",
SupplierUser: "supplier_user", SupplierUser: "supplier_user",
SupplierRole: "supplier_role", SupplierRole: "supplier_role",
Withdraw: "withdraw", Withdraw: "withdraw",
SupplierPermission: "supplier_permission",
} }

View File

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

View File

@ -7,9 +7,15 @@ func getRoleValue(val string) string {
} }
var SupplierRole = struct { var SupplierRole = struct {
Create string GetList string
Update string Detail string
Create string
Update string
GetListBySupplierID string
}{ }{
Create: getRoleValue("create"), GetList: getRoleValue("get_list"),
Update: getRoleValue("update"), Detail: getRoleValue("detail"),
Create: getRoleValue("create"),
Update: getRoleValue("update"),
GetListBySupplierID: getRoleValue("get_list_by_supplierId"),
} }

View File

@ -8,6 +8,8 @@ func getSupplierUserValue(val string) string {
var SupplierUser = struct { var SupplierUser = struct {
// Users // Users
LoginUser string
GetListUser string
CreateOwner string CreateOwner string
UpdateOwner string UpdateOwner string
CreateStaff string CreateStaff string
@ -16,6 +18,8 @@ var SupplierUser = struct {
ResetPassword string ResetPassword string
}{ }{
// Users // Users
LoginUser: getSupplierUserValue("login_user"),
GetListUser: getSupplierUserValue("get_list_user"),
CreateOwner: getSupplierUserValue("create_owner"), CreateOwner: getSupplierUserValue("create_owner"),
UpdateOwner: getSupplierUserValue("update_owner"), UpdateOwner: getSupplierUserValue("update_owner"),
CreateStaff: getSupplierUserValue("create_staff"), CreateStaff: getSupplierUserValue("create_staff"),