reface to openteam
This commit is contained in:
83
internal/dto/team/team.go
Normal file
83
internal/dto/team/team.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"opencatd-open/internal/model"
|
||||
"opencatd-open/internal/utils"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
ID int64 `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 ApiKeyInfo 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 ApiKeyInfo) HasNameUpdate() bool {
|
||||
return k.Name != ""
|
||||
}
|
||||
|
||||
func (k ApiKeyInfo) HasKeyUpdate() bool {
|
||||
return k.Key != ""
|
||||
}
|
||||
|
||||
func (k ApiKeyInfo) HasStatusUpdate() bool {
|
||||
return k.Status != nil
|
||||
}
|
||||
|
||||
func (k ApiKeyInfo) HasApiTypeUpdate() bool {
|
||||
return k.ApiType != ""
|
||||
}
|
||||
|
||||
// 辅助函数:统一处理字段更新
|
||||
func (update *ApiKeyInfo) UpdateFields(existing *model.ApiKey) *model.ApiKey {
|
||||
result := &model.ApiKey{
|
||||
ID: existing.ID,
|
||||
Name: existing.Name, // 默认保持原值
|
||||
ApiType: existing.ApiType, // 默认保持原值
|
||||
ApiKey: existing.ApiKey, // 默认保持原值
|
||||
Active: existing.Active, // 默认保持原值
|
||||
}
|
||||
|
||||
if update.HasNameUpdate() {
|
||||
result.Name = utils.ToPtr(update.Name)
|
||||
}
|
||||
if update.HasKeyUpdate() {
|
||||
result.ApiKey = utils.ToPtr(update.Key)
|
||||
}
|
||||
if update.HasStatusUpdate() {
|
||||
result.Active = update.Status
|
||||
}
|
||||
if update.HasApiTypeUpdate() {
|
||||
result.ApiType = utils.ToPtr(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