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.
50 lines
993 B
Go
50 lines
993 B
Go
|
1 week ago
|
//
|
||
|
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
||
|
|
// 2025-03-04 16:08:06
|
||
|
|
// Distributed under terms of the MIT license.
|
||
|
|
//
|
||
|
|
|
||
|
|
package settings
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/veypi/vbase/models"
|
||
|
|
"github.com/veypi/vigo"
|
||
|
|
)
|
||
|
|
|
||
|
|
// UpdateItem 更新项
|
||
|
|
type UpdateItem struct {
|
||
|
|
Key string `json:"key"`
|
||
|
|
Value string `json:"value"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateRequest 更新请求
|
||
|
|
type UpdateRequest struct {
|
||
|
|
Settings []UpdateItem `json:"settings"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateResponse 更新响应
|
||
|
|
type UpdateResponse struct {
|
||
|
|
Updated int `json:"updated"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// update 批量更新设置
|
||
|
|
func update(x *vigo.X, req *UpdateRequest) (*UpdateResponse, error) {
|
||
|
|
// 获取当前用户ID
|
||
|
|
userID := ""
|
||
|
|
if u := x.Get("user_id"); u != nil {
|
||
|
|
userID = u.(string)
|
||
|
|
}
|
||
|
|
|
||
|
|
updated := 0
|
||
|
|
for _, item := range req.Settings {
|
||
|
|
if err := models.SetSetting(item.Key, item.Value, userID); err != nil {
|
||
|
|
return nil, vigo.ErrInternalServer.WithString("failed to update " + item.Key)
|
||
|
|
}
|
||
|
|
updated++
|
||
|
|
}
|
||
|
|
|
||
|
|
return &UpdateResponse{
|
||
|
|
Updated: updated,
|
||
|
|
}, nil
|
||
|
|
}
|