87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
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"`
|
||
OperationIP string `json:"operation_ip,omitempty"`
|
||
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"`
|
||
}
|
||
|
||
// QueryWhitelistPublicEncryptedRequest 公开接口外层请求(data 为 AES 密文)
|
||
type QueryWhitelistPublicEncryptedRequest struct {
|
||
Data string `json:"data" binding:"required"`
|
||
}
|
||
|
||
// QueryWhitelistPublicPayload 公开接口解密后的业务参数(不含 key/access_id,身份由请求头 + 解密成功证明)
|
||
type QueryWhitelistPublicPayload struct {
|
||
Name string `json:"name"`
|
||
IDCard string `json:"id_card"`
|
||
APICodes []string `json:"api_codes"`
|
||
Remark string `json:"remark"`
|
||
}
|
||
|
||
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,
|
||
OperationIP: entry.OperationIP,
|
||
CreatedAt: entry.CreatedAt,
|
||
UpdatedAt: entry.UpdatedAt,
|
||
}
|
||
}
|