mirror of https://github.com/veypi/OneAuth.git
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.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
//
|
|
// create.go
|
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package access
|
|
|
|
import (
|
|
"github.com/vyes-ai/vigo"
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
)
|
|
|
|
type createOpts struct {
|
|
AppID string `json:"app_id" parse:"json"`
|
|
UserID *string `json:"user_id" parse:"json"`
|
|
RoleID *string `json:"role_id" parse:"json"`
|
|
ResourceID *string `json:"resource_id" parse:"json"`
|
|
Name string `json:"name" parse:"json"`
|
|
TID string `json:"tid" parse:"json"`
|
|
Level uint `json:"level" parse:"json"`
|
|
}
|
|
|
|
var _ = Router.Post("/", "创建访问权限", createAccess)
|
|
|
|
func createAccess(x *vigo.X, opts *createOpts) (any, error) {
|
|
// 创建新记录
|
|
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
|
|
}
|