This commit is contained in:
2026-06-18 21:16:02 +08:00
parent 9685d34187
commit 3a5a0d0028
36 changed files with 1566 additions and 66 deletions

View File

@@ -0,0 +1,71 @@
package dto
import (
"time"
"tyapi-server/internal/domains/api/entities"
)
type QueryWhitelistEntryRequest struct {
UserID string `json:"user_id" validate:"required"`
Name string `json:"name" validate:"required,min=1,max=100"`
IDCard string `json:"id_card" validate:"required"`
APICodes []string `json:"api_codes" validate:"required,min=1,dive,required"`
Remark string `json:"remark" validate:"max=500"`
}
type QueryWhitelistEntryUpdateRequest struct {
Name string `json:"name" validate:"omitempty,min=1,max=100"`
IDCard string `json:"id_card" validate:"omitempty"`
APICodes []string `json:"api_codes" validate:"omitempty,min=1,dive,required"`
Remark string `json:"remark" validate:"max=500"`
}
type QueryWhitelistStatusRequest struct {
Status string `json:"status" validate:"required,oneof=enabled disabled"`
}
type QueryWhitelistEntryResponse struct {
ID string `json:"id"`
UserID string `json:"user_id"`
IsGlobal bool `json:"is_global"`
Name string `json:"name"`
IDCardMasked string `json:"id_card_masked"`
APICodes []string `json:"api_codes"`
Status string `json:"status"`
Remark string `json:"remark"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type QueryWhitelistListResponse struct {
Items []QueryWhitelistEntryResponse `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
Size int `json:"page_size"`
}
type QueryWhitelistImportLegacyResponse struct {
Imported int `json:"imported"`
Skipped int `json:"skipped"`
Total int `json:"total"`
}
func NewQueryWhitelistEntryResponse(entry *entities.QueryWhitelistEntry) QueryWhitelistEntryResponse {
apiCodes := []string(entry.APICodes)
if apiCodes == nil {
apiCodes = []string{}
}
return QueryWhitelistEntryResponse{
ID: entry.ID,
UserID: entry.UserID,
IsGlobal: entry.IsGlobal(),
Name: entry.Name,
IDCardMasked: entry.IDCardMasked,
APICodes: apiCodes,
Status: entry.Status,
Remark: entry.Remark,
CreatedAt: entry.CreatedAt,
UpdatedAt: entry.UpdatedAt,
}
}