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.
|
|
|
|
package resource
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/vyes-ai/vigo"
|
|
|
|
|
"github.com/veypi/OneAuth/cfg"
|
|
|
|
|
"github.com/veypi/OneAuth/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Router.Post("/", createResource)
|
|
|
|
|
|
|
|
|
|
type createOpts struct {
|
|
|
|
|
AppID string `json:"app_id" parse:"path"`
|
|
|
|
|
Name string `json:"name" parse:"json"`
|
|
|
|
|
Des string `json:"des" parse:"json"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createResource(x *vigo.X) (any, error) {
|
|
|
|
|
// 解析参数
|
|
|
|
|
opts := &createOpts{}
|
|
|
|
|
if err := x.Parse(opts); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建资源对象
|
|
|
|
|
resource := &models.Resource{
|
|
|
|
|
AppID: opts.AppID,
|
|
|
|
|
Name: opts.Name,
|
|
|
|
|
Des: opts.Des,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存到数据库
|
|
|
|
|
if err := cfg.DB().Create(resource).Error; err != nil {
|
|
|
|
|
return nil, vigo.NewError("failed to create resource").WithCode(500)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resource, nil
|
|
|
|
|
}
|