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:
zenfun
2026-01-10 02:05:55 +08:00
parent f52c7acbe6
commit 2098bc4abe
20 changed files with 4156 additions and 3760 deletions

View File

@@ -1,13 +1,31 @@
package dto
import "time"
// BindingResponse represents a binding in API responses.
// @Description Binding response
type BindingResponse struct {
ID uint `json:"id" example:"1"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Namespace string `json:"namespace" example:"default"`
PublicModel string `json:"public_model" example:"gpt-4"`
GroupID uint `json:"group_id" example:"1"`
Weight int `json:"weight" example:"1"`
SelectorType string `json:"selector_type" example:"exact"`
SelectorValue string `json:"selector_value" example:"gpt-4-turbo"`
Status string `json:"status" example:"active"`
}
// BindingDTO defines inbound payload for binding creation/update.
// It maps "(namespace, public_model)" to a ProviderGroup and an upstream selector.
// @Description Binding create/update request
type BindingDTO struct {
Namespace string `json:"namespace"`
PublicModel string `json:"public_model"`
GroupID uint `json:"group_id"`
Weight int `json:"weight"`
SelectorType string `json:"selector_type"`
SelectorValue string `json:"selector_value"`
Status string `json:"status"`
Namespace string `json:"namespace" example:"default"`
PublicModel string `json:"public_model" example:"gpt-4"`
GroupID uint `json:"group_id" example:"1"`
Weight int `json:"weight" example:"1"`
SelectorType string `json:"selector_type" example:"exact"`
SelectorValue string `json:"selector_value" example:"gpt-4-turbo"`
Status string `json:"status" example:"active"`
}