team api
This commit is contained in:
22
team/dto/openai/err_resp.go
Normal file
22
team/dto/openai/err_resp.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
}
|
||||
|
||||
func WarpErrAsOpenAI(c *gin.Context, msg string, code string) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"error": Error{
|
||||
Message: msg,
|
||||
Code: code,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
83
team/dto/team/team.go
Normal file
83
team/dto/team/team.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"opencatd-open/team/consts"
|
||||
"opencatd-open/team/model"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Token string `json:"token"`
|
||||
Status *bool `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (u UserInfo) HasNameUpdate() bool {
|
||||
return u.Name != ""
|
||||
}
|
||||
|
||||
func (u UserInfo) HasTokenUpdate() bool {
|
||||
return u.Token != ""
|
||||
}
|
||||
|
||||
func (u UserInfo) HasStatusUpdate() bool {
|
||||
return u.Status != nil
|
||||
}
|
||||
|
||||
type KeyInfo struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ApiType string `json:"api_type,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty"`
|
||||
Status *bool `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// 添加辅助方法判断字段是否需要更新
|
||||
func (k KeyInfo) HasNameUpdate() bool {
|
||||
return k.Name != ""
|
||||
}
|
||||
|
||||
func (k KeyInfo) HasKeyUpdate() bool {
|
||||
return k.Key != ""
|
||||
}
|
||||
|
||||
func (k KeyInfo) HasStatusUpdate() bool {
|
||||
return k.Status != nil
|
||||
}
|
||||
|
||||
func (k KeyInfo) HasApiTypeUpdate() bool {
|
||||
return k.ApiType != ""
|
||||
}
|
||||
|
||||
// 辅助函数:统一处理字段更新
|
||||
func (update *KeyInfo) UpdateFields(existing *model.ApiKey) *model.ApiKey {
|
||||
result := &model.ApiKey{
|
||||
ID: existing.ID,
|
||||
Name: existing.Name, // 默认保持原值
|
||||
ApiType: existing.ApiType, // 默认保持原值
|
||||
ApiKey: existing.ApiKey, // 默认保持原值
|
||||
Status: existing.Status, // 默认保持原值
|
||||
}
|
||||
|
||||
if update.HasNameUpdate() {
|
||||
result.Name = update.Name
|
||||
}
|
||||
if update.HasKeyUpdate() {
|
||||
result.ApiKey = update.Key
|
||||
}
|
||||
if update.HasStatusUpdate() {
|
||||
result.Status = consts.OpenOrClose(*update.Status)
|
||||
}
|
||||
if update.HasApiTypeUpdate() {
|
||||
result.ApiType = update.ApiType
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
type UsageInfo struct {
|
||||
UserId int `json:"userId"`
|
||||
TotalUnit int `json:"totalUnit"`
|
||||
Cost string `json:"cost"`
|
||||
}
|
||||
Reference in New Issue
Block a user