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.
41 lines
889 B
Go
41 lines
889 B
Go
package app_user
|
|
|
|
import (
|
|
"github.com/vyes-ai/vigo"
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
)
|
|
|
|
type updateOpts struct {
|
|
AppID string `parse:"path"`
|
|
UserID string `parse:"path"`
|
|
Status *string `json:"status"`
|
|
}
|
|
|
|
var _ = Router.Patch("/:user_id", updateAppUser)
|
|
|
|
func updateAppUser(x *vigo.X) (any, error) {
|
|
opts := &updateOpts{}
|
|
if err := x.Parse(opts); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
appUser := &models.AppUser{}
|
|
if err := cfg.DB().Where("app_id = ? AND user_id = ?", opts.AppID, opts.UserID).First(appUser).Error; err != nil {
|
|
return nil, vigo.NewError("app_user not found").WithCode(404)
|
|
}
|
|
|
|
updates := map[string]interface{}{}
|
|
if opts.Status != nil {
|
|
updates["status"] = *opts.Status
|
|
}
|
|
|
|
if len(updates) > 0 {
|
|
if err := cfg.DB().Model(appUser).Updates(updates).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return appUser, nil
|
|
}
|