mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +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:
@@ -4,16 +4,11 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/ez-api/ez-api/internal/dto"
|
||||
"github.com/ez-api/ez-api/internal/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type NamespaceRequest struct {
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CreateNamespace godoc
|
||||
// @Summary Create namespace
|
||||
// @Description Create a namespace for bindings
|
||||
@@ -21,13 +16,13 @@ type NamespaceRequest struct {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param namespace body NamespaceRequest true "Namespace payload"
|
||||
// @Success 201 {object} ResponseEnvelope{data=model.Namespace}
|
||||
// @Param namespace body dto.NamespaceDTO true "Namespace payload"
|
||||
// @Success 201 {object} ResponseEnvelope{data=dto.NamespaceResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=MapData}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
||||
// @Router /admin/namespaces [post]
|
||||
func (h *Handler) CreateNamespace(c *gin.Context) {
|
||||
var req NamespaceRequest
|
||||
var req dto.NamespaceDTO
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -64,7 +59,7 @@ func (h *Handler) CreateNamespace(c *gin.Context) {
|
||||
// @Param page query int false "page (1-based)"
|
||||
// @Param limit query int false "limit (default 50, max 200)"
|
||||
// @Param search query string false "search by name/description"
|
||||
// @Success 200 {object} ResponseEnvelope{data=[]model.Namespace}
|
||||
// @Success 200 {object} ResponseEnvelope{data=[]dto.NamespaceResponse}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
||||
// @Router /admin/namespaces [get]
|
||||
func (h *Handler) ListNamespaces(c *gin.Context) {
|
||||
@@ -87,7 +82,7 @@ func (h *Handler) ListNamespaces(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Success 200 {object} ResponseEnvelope{data=model.Namespace}
|
||||
// @Success 200 {object} ResponseEnvelope{data=dto.NamespaceResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=MapData}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=MapData}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
||||
@@ -118,9 +113,9 @@ type UpdateNamespaceRequest struct {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Param namespace body UpdateNamespaceRequest true "Update payload"
|
||||
// @Success 200 {object} ResponseEnvelope{data=model.Namespace}
|
||||
// @Success 200 {object} ResponseEnvelope{data=dto.NamespaceResponse}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=MapData}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=MapData}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
||||
|
||||
Reference in New Issue
Block a user