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.
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
2 months ago
|
package access
|
||
|
|
||
|
import (
|
||
|
"github.com/veypi/OneBD/rest"
|
||
|
"oa/cfg"
|
||
|
M "oa/models"
|
||
|
)
|
||
|
|
||
|
func useAccess(r rest.Router) {
|
||
|
r.Get("/", accessList)
|
||
|
r.Post("/", accessPost)
|
||
|
}
|
||
|
func accessList(x *rest.X) (any, error) {
|
||
|
opts := &M.AccessList{}
|
||
|
err := x.Parse(opts)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
data := make([]*M.Access, 0, 10)
|
||
|
|
||
|
query := cfg.DB()
|
||
|
if opts.CreatedAt != nil {
|
||
|
query = query.Where("created_at > ?", opts.CreatedAt)
|
||
|
}
|
||
|
if opts.UpdatedAt != nil {
|
||
|
query = query.Where("updated_at > ?", opts.UpdatedAt)
|
||
|
}
|
||
|
query = query.Where("app_id LIKE ?", opts.AppID)
|
||
|
if opts.UserID != nil {
|
||
|
query = query.Where("user_id LIKE ?", opts.UserID)
|
||
|
}
|
||
|
if opts.RoleID != nil {
|
||
|
query = query.Where("role_id LIKE ?", opts.RoleID)
|
||
|
}
|
||
|
if opts.Name != nil {
|
||
|
query = query.Where("name LIKE ?", opts.Name)
|
||
|
}
|
||
|
err = query.Find(&data).Error
|
||
|
|
||
|
return data, err
|
||
|
}
|
||
|
func accessPost(x *rest.X) (any, error) {
|
||
|
opts := &M.AccessPost{}
|
||
|
err := x.Parse(opts)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
data := &M.Access{}
|
||
|
|
||
|
data.AppID = opts.AppID
|
||
|
data.UserID = opts.UserID
|
||
|
data.RoleID = opts.RoleID
|
||
|
data.Name = opts.Name
|
||
|
data.TID = opts.TID
|
||
|
data.Level = opts.Level
|
||
|
err = cfg.DB().Create(data).Error
|
||
|
|
||
|
return data, err
|
||
|
}
|