mergeDev/campaign #73
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -16,8 +16,29 @@ func GetSupplierRole() 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) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.SupplierRole.Create, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -56,3 +77,24 @@ func (s SupplierRole) UpdateRole(p model.UpdateRoleRequest) error {
 | 
			
		|||
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
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"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,16 @@
 | 
			
		|||
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 {
 | 
			
		||||
	Name string `json:"name"`
 | 
			
		||||
	Code string `json:"code"`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,19 @@
 | 
			
		|||
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"`
 | 
			
		||||
	CreatedAt string `json:"createdAt"`
 | 
			
		||||
	UpdatedAt string `json:"updatedAt"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CreateRoleResponse struct {
 | 
			
		||||
	ID string `json:"_id"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ var prefixes = struct {
 | 
			
		|||
	Selly              string
 | 
			
		||||
	SupplierUser       string
 | 
			
		||||
	SupplierRole       string
 | 
			
		||||
	SupplierPermission string
 | 
			
		||||
}{
 | 
			
		||||
	Communication:      "communication",
 | 
			
		||||
	Order:              "order",
 | 
			
		||||
| 
						 | 
				
			
			@ -26,4 +27,5 @@ var prefixes = struct {
 | 
			
		|||
	Selly:              "selly",
 | 
			
		||||
	SupplierUser:       "supplier_user",
 | 
			
		||||
	SupplierRole:       "supplier_role",
 | 
			
		||||
	SupplierPermission: "supplier_permission",
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"),
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -7,9 +7,15 @@ func getRoleValue(val string) string {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
var SupplierRole = struct {
 | 
			
		||||
	GetList             string
 | 
			
		||||
	Detail              string
 | 
			
		||||
	Create              string
 | 
			
		||||
	Update              string
 | 
			
		||||
	GetListBySupplierID string
 | 
			
		||||
}{
 | 
			
		||||
	GetList:             getRoleValue("get_list"),
 | 
			
		||||
	Detail:              getRoleValue("detail"),
 | 
			
		||||
	Create:              getRoleValue("create"),
 | 
			
		||||
	Update:              getRoleValue("update"),
 | 
			
		||||
	GetListBySupplierID: getRoleValue("get_list_by_supplierId"),
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue