complete role crud
This commit is contained in:
@@ -1,28 +1,50 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"atom/common/request"
|
||||
"atom/common/response"
|
||||
"atom/database/models"
|
||||
"atom/modules/auth/dto"
|
||||
"atom/providers/config"
|
||||
"atom/modules/auth/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type RoleController interface {
|
||||
GetName(*gin.Context) (string, error)
|
||||
GetByFilter(*gin.Context, dto.RoleRequestFilter, request.PageFilter) (*response.PageResponse[*models.SysRole], error)
|
||||
Create(*gin.Context, dto.RoleRequestForm) error
|
||||
Delete(*gin.Context, int) error
|
||||
UpdateByID(*gin.Context, int, dto.RoleRequestForm) error
|
||||
}
|
||||
|
||||
type roleControllerImpl struct {
|
||||
conf *config.Config
|
||||
roleSvc service.RoleService
|
||||
}
|
||||
|
||||
func NewRoleController(conf *config.Config) RoleController {
|
||||
return &roleControllerImpl{conf: conf}
|
||||
func NewRoleController(
|
||||
roleSvc service.RoleService,
|
||||
) RoleController {
|
||||
return &roleControllerImpl{
|
||||
roleSvc: roleSvc,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *roleControllerImpl) GetName(ctx *gin.Context) (string, error) {
|
||||
return "Role", nil
|
||||
func (c *roleControllerImpl) GetByFilter(
|
||||
ctx *gin.Context,
|
||||
filter dto.RoleRequestFilter,
|
||||
page request.PageFilter,
|
||||
) (*response.PageResponse[*models.SysRole], error) {
|
||||
return c.roleSvc.GetByFilter(ctx, filter, page)
|
||||
}
|
||||
|
||||
func (c *roleControllerImpl) Create(ctx *gin.Context, req *dto.RoleCreateRequest) error {
|
||||
return nil
|
||||
func (c *roleControllerImpl) Create(ctx *gin.Context, req dto.RoleRequestForm) error {
|
||||
_, err := c.roleSvc.Create(ctx, req)
|
||||
return err
|
||||
}
|
||||
func (c *roleControllerImpl) UpdateByID(ctx *gin.Context, id int, req dto.RoleRequestForm) error {
|
||||
_, err := c.roleSvc.UpdateByID(ctx, uint64(id), req)
|
||||
return err
|
||||
}
|
||||
func (c *roleControllerImpl) Delete(ctx *gin.Context, id int) error {
|
||||
return c.roleSvc.DeleteByID(ctx, uint64(id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user