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.
42 lines
834 B
Go
42 lines
834 B
Go
//
|
|
// crud.go
|
|
// Copyright (C) 2025 veypi <i@veypi.com>
|
|
// 2025-05-06 15:12
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package role
|
|
|
|
import (
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
"github.com/vyes-ai/vigo"
|
|
)
|
|
|
|
type patchOpts struct {
|
|
ID string `json:"id" parse:"path"`
|
|
Status *string `json:"status" parse:"json"`
|
|
}
|
|
|
|
var _ = Router.Patch("/:id", userRolePatch)
|
|
|
|
func userRolePatch(x *vigo.X) (any, error) {
|
|
opts := &patchOpts{}
|
|
err := x.Parse(opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
data := &models.UserRole{}
|
|
err = cfg.DB().Where("id = ?", opts.ID).First(data).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
optsMap := make(map[string]interface{})
|
|
if opts.Status != nil {
|
|
optsMap["status"] = opts.Status
|
|
}
|
|
err = cfg.DB().Model(data).Updates(optsMap).Error
|
|
|
|
return data, err
|
|
}
|