| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package role
- import (
- "git.sxidc.com/go-framework/baize/convenient/entity_crud"
- "git.sxidc.com/go-framework/baize/framework/binding"
- "git.sxidc.com/go-framework/baize/framework/core/api"
- "git.sxidc.com/go-framework/baize/framework/core/domain"
- "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
- "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
- )
- // Simple Bind参数
- type Simple struct {
- // schema
- Schema string
- // 鉴权中间件
- AuthMiddleware binding.Middleware
- }
- func (simple *Simple) Bind(binder *binding.Binder) {
- entity_crud.BindSimple(binder, &entity_crud.Simple[Info]{
- Entity: &Entity{},
- Schema: simple.Schema,
- CreateJsonBody: &CreateRoleJsonBody{},
- DeleteQueryParams: &DeleteRoleQueryParams{},
- UpdateJsonBody: &UpdateRoleJsonBody{},
- QueryQueryParams: &GetRolesQueryParams{},
- GetByIDQueryParams: &GetRoleQueryParams{},
- }, entity_crud.WithGlobalMiddlewares(simple.AuthMiddleware),
- entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
- Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
- userInfo := c.GetUserInfo()
- err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
- if err != nil {
- return nil, err
- }
- return nil, err
- },
- }), entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
- Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
- userInfo := c.GetUserInfo()
- err := domain.SetField(e, entity.FieldLastUpdateUserID, userInfo.GetID())
- if err != nil {
- return nil, err
- }
- return nil, err
- },
- }))
- }
|