You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/api/app/access/create.go

52 lines
1.0 KiB
Go

6 months ago
//
// create.go
// Copyright (C) 2024 veypi <i@veypi.com>
// Distributed under terms of the MIT license.
//
package access
import (
3 months ago
"github.com/vyes-ai/vigo"
6 months ago
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/models"
6 months ago
)
type createOpts struct {
AppID string `json:"app_id"`
UserID *string `json:"user_id"`
RoleID *string `json:"role_id"`
ResourceID *string `json:"resource_id"`
Name string `json:"name"`
TID string `json:"tid"`
Level uint `json:"level"`
}
var _ = Router.Post("/", createAccess)
func createAccess(x *vigo.X) (any, error) {
6 months ago
// 解析请求参数
opts := &createOpts{}
if err := x.Parse(opts); err != nil {
return nil, err
}
// 创建新记录
access := models.Access{
AppID: opts.AppID,
UserID: opts.UserID,
RoleID: opts.RoleID,
ResourceID: opts.ResourceID,
Name: opts.Name,
TID: opts.TID,
Level: opts.Level,
}
// 保存到数据库
if err := cfg.DB().Create(&access).Error; err != nil {
return nil, err
}
return &access, nil
}