service_createaction.go 785 B

123456789101112131415161718192021222324252627
  1. package menu
  2. import (
  3. "github.com/xinliangnote/go-gin-api/internal/pkg/core"
  4. "github.com/xinliangnote/go-gin-api/internal/repository/mysql/menu_action"
  5. )
  6. type CreateMenuActionData struct {
  7. MenuId int32 `json:"menu_id"` // 菜单栏ID
  8. Method string `json:"method"` // 请求方法
  9. API string `json:"api"` // 请求地址
  10. }
  11. func (s *service) CreateAction(ctx core.Context, menuActionData *CreateMenuActionData) (id int32, err error) {
  12. model := menu_action.NewModel()
  13. model.MenuId = menuActionData.MenuId
  14. model.Method = menuActionData.Method
  15. model.Api = menuActionData.API
  16. model.CreatedUser = ctx.SessionUserInfo().UserName
  17. model.IsDeleted = -1
  18. id, err = model.Create(s.db.GetDbW().WithContext(ctx.RequestContext()))
  19. if err != nil {
  20. return 0, err
  21. }
  22. return
  23. }