mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-14 01:17:52 +00:00
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
This commit is contained in:
@@ -2,18 +2,43 @@ package dto
|
||||
|
||||
import "time"
|
||||
|
||||
// APIKeyDTO defines inbound payload for API key creation/update.
|
||||
type APIKeyDTO struct {
|
||||
GroupID uint `json:"group_id"`
|
||||
APIKey string `json:"api_key"`
|
||||
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"`
|
||||
Status string `json:"status"`
|
||||
AutoBan *bool `json:"auto_ban,omitempty"`
|
||||
BanReason string `json:"ban_reason,omitempty"`
|
||||
BanUntil time.Time `json:"ban_until,omitempty"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user