role

package
v0.0.0-...-eecab09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeRepository = domainerrors.ErrorCodeApplicationRole + domainerrors.ErrorCodeApplicationRole + iota
	ErrorCodeValidateInput
	ErrorCodeCast
	ErrorCodeApplyEvent
	ErrorCodePublishEvent
)

Variables

View Source
var (
	ErrValidation         = errors.New("validation failed")
	ErrCastToEntityFailed = errors.New("cast to entity failed")
)

Functions

func CustomPermission

func CustomPermission(fl validator.FieldLevel) bool

Types

type CreatedInput

type CreatedInput struct {
	Name        string `json:"name" validate:"required,lte=30,alphanum"`
	Description string `json:"description" validate:"required,lte=200"`
	Permissions string `json:"permissions" validate:"required,custom_permission"`
}

func (*CreatedInput) ToEntity

func (c *CreatedInput) ToEntity() *entity.Role

func (*CreatedInput) Validate

func (c *CreatedInput) Validate() error

type DeletedInput

type DeletedInput struct {
	ID string `json:"id" validate:"required,alphanum,len=20"`
}

func (*DeletedInput) Validate

func (i *DeletedInput) Validate() error

type DetailGotInput

type DetailGotInput struct {
	ID string `json:"id" validate:"required,alphanum,len=20"`
}

func (*DetailGotInput) Validate

func (i *DetailGotInput) Validate() error

type IService

type IService interface {
	// Command
	CreateRole(ctx context.Context, roleInfo *CreatedInput) (*Output, error)
	// AssignRole(ctx context.Context, roleInfo *AssignedInput) (*Output, error)
	UpdateRole(ctx context.Context, roleInfo *UpdatedInput) (*Output, error)
	DeleteRole(ctx context.Context, roleInfo *DeletedInput) (*Output, error)
	// // Query
	GetRoleList(ctx context.Context, roleInfo *ListGotInput) (*OutputList, error)
	GetRoleDetail(ctx context.Context, roleInfo *DetailGotInput) (*Output, error)
}

type ListGotInput

type ListGotInput struct {
	Limit      int      `json:"limit"`
	Offset     int      `json:"offset"`
	FilterName string   `json:"filterName" validate:"omitempty,oneof=name"`
	SortFields []string `json:"sortFields" validate:"dive,oneof=id name updated_at created_at"`
	Dir        string   `json:"dir" validate:"oneof=asc desc"`
}

func (*ListGotInput) ToEntity

func (i *ListGotInput) ToEntity() *entity.Role

func (*ListGotInput) ToSearchQuery

func (i *ListGotInput) ToSearchQuery() *domain.SearchQuery

func (*ListGotInput) Validate

func (i *ListGotInput) Validate() error

type Output

type Output struct {
	ID          string                    `json:"id"`
	Name        string                    `json:"name"`
	Description string                    `json:"description"`
	Permissions []string                  `json:"permissions"`
	Users       []application_user.Output `json:"users"`
	CreatedAt   time.Time                 `json:"createdAt"`
	UpdatedAt   time.Time                 `json:"updatedAt"`
	DeletedAt   time.Time                 `json:"deletedAt"`
}

func NewOutput

func NewOutput(e *entity.Role) *Output

type OutputList

type OutputList struct {
	Offset int64    `json:"offset"`
	Limit  int64    `json:"limit"`
	Total  int64    `json:"total"`
	Items  []Output `json:"items"`
}

func NewListOutput

func NewListOutput(e *domain.List) *OutputList

type ServiceImpl

type ServiceImpl struct {
	TransactionRepo domain.ITransactionRepo
	RoleRepo        repository.RoleRepository
	UserRepo        repository.UserRepository

	EventProducer event.Producer
	// contains filtered or unexported fields
}

ServiceImpl -.

func NewServiceImpl

func NewServiceImpl(roleRepo repository.RoleRepository, userRepo repository.UserRepository, transactionRepo domain.ITransactionRepo, eventProducer event.Producer, eventStore event.Store, l pwlogger.Interface) *ServiceImpl

NewServiceImpl -.

func (*ServiceImpl) CreateRole

func (u *ServiceImpl) CreateRole(ctx context.Context, roleInfo *CreatedInput) (*Output, error)

CreateRole creates a role.

func (*ServiceImpl) DeleteRole

func (u *ServiceImpl) DeleteRole(ctx context.Context, roleInfo *DeletedInput) (*Output, error)

DeleteRole deletes role.

func (*ServiceImpl) GetRoleDetail

func (u *ServiceImpl) GetRoleDetail(ctx context.Context, roleInfo *DetailGotInput) (*Output, error)

GetRoleDetail gets role detail.

func (*ServiceImpl) GetRoleList

func (u *ServiceImpl) GetRoleList(ctx context.Context, roleInfo *ListGotInput) (*OutputList, error)

GetRoleList gets role list.

func (*ServiceImpl) UpdateRole

func (u *ServiceImpl) UpdateRole(ctx context.Context, roleInfo *UpdatedInput) (*Output, error)

UpdateRole updates role.

type UpdatedInput

type UpdatedInput struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Permissions string `json:"permissions"`
}

func (*UpdatedInput) ToEntity

func (c *UpdatedInput) ToEntity() *entity.Role

func (*UpdatedInput) Validate

func (c *UpdatedInput) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL