Files
ez-api/internal/dto/api_key.go
zenfun 2098bc4abe refactor(api): standardize DTOs and update swagger
Decouple API contract from internal models by introducing dedicated DTOs for requests and responses.
- Add Response DTOs for all resources (API Keys, Bindings, Models, Namespaces, etc.)
- Update Swagger annotations to use DTOs with field examples instead of internal models
- Refactor handlers to bind and return DTO structures
- Consolidate request/response definitions in the dto package
2026-01-10 02:05:55 +08:00

45 lines
2.1 KiB
Go

package dto
import "time"
// APIKeyResponse represents an API key in API responses.
// @Description API key response
type APIKeyResponse struct {
ID uint `json:"id" example:"1"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
GroupID uint `json:"group_id" example:"1"`
APIKey string `json:"api_key" example:"sk-xxx..."`
AccessToken string `json:"access_token,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
AccountID string `json:"account_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Weight int `json:"weight" example:"1"`
Status string `json:"status" example:"active"`
AutoBan bool `json:"auto_ban" example:"true"`
BanReason string `json:"ban_reason,omitempty"`
BanUntil *time.Time `json:"ban_until,omitempty"`
TotalRequests int64 `json:"total_requests" example:"1000"`
SuccessRequests int64 `json:"success_requests" example:"950"`
FailureRequests int64 `json:"failure_requests" example:"50"`
SuccessRate float64 `json:"success_rate" example:"0.95"`
FailureRate float64 `json:"failure_rate" example:"0.05"`
}
// APIKeyDTO defines inbound payload for API key creation/update.
// @Description API key create/update request
type APIKeyDTO struct {
GroupID uint `json:"group_id" example:"1"`
APIKey string `json:"api_key" example:"sk-xxx..."`
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
AccountID string `json:"account_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Weight int `json:"weight,omitempty" example:"1"`
Status string `json:"status" example:"active"`
AutoBan *bool `json:"auto_ban,omitempty" example:"true"`
BanReason string `json:"ban_reason,omitempty"`
BanUntil *time.Time `json:"ban_until,omitempty"`
}