|
|
|
|
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@app_id"`
|
|
|
|
|
UserID string `parse:"path@user_id"`
|
|
|
|
|
Status *string `json:"status" parse:"json"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ = Router.Patch("/{user_id}", "更新应用用户", updateAppUser)
|
|
|
|
|
|
|
|
|
|
func updateAppUser(x *vigo.X, opts *updateOpts) (any, error) {
|
|
|
|
|
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
|
|
|
|
|
}
|