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/del.go

41 lines
821 B
Go

6 months ago
//
// del.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 deleteOpts struct {
ID string `parse:"path"`
}
var _ = Router.Delete("/:id", deleteAccess)
func deleteAccess(x *vigo.X) (any, error) {
6 months ago
// 解析路径参数
opts := &deleteOpts{}
if err := x.Parse(opts); err != nil {
return nil, err
}
// 查找记录
var access models.Access
if err := cfg.DB().Where("id = ?", opts.ID).First(&access).Error; err != nil {
return nil, vigo.NewError("未找到资源").WithCode(404)
6 months ago
}
// 删除记录
if err := cfg.DB().Delete(&access).Error; err != nil {
return nil, err
}
return map[string]string{"message": "删除成功"}, nil
}