mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(api): wrap JSON responses in envelope
Add response envelope middleware to standardize JSON responses as
`{code,data,message}` with consistent business codes across endpoints.
Update Swagger annotations and tests to reflect the new response shape.
BREAKING CHANGE: API responses are now wrapped in a response envelope; clients must read payloads from `data` and handle `code`/`message` fields.
This commit is contained in:
@@ -19,9 +19,9 @@ import (
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param binding body dto.BindingDTO true "Binding Info"
|
||||
// @Success 201 {object} model.Binding
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 201 {object} ResponseEnvelope{data=model.Binding}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/bindings [post]
|
||||
func (h *Handler) CreateBinding(c *gin.Context) {
|
||||
var req dto.BindingDTO
|
||||
@@ -84,8 +84,8 @@ func (h *Handler) CreateBinding(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 namespace/public_model"
|
||||
// @Success 200 {array} model.Binding
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=[]model.Binding}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/bindings [get]
|
||||
func (h *Handler) ListBindings(c *gin.Context) {
|
||||
var out []model.Binding
|
||||
@@ -109,10 +109,10 @@ func (h *Handler) ListBindings(c *gin.Context) {
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Binding ID"
|
||||
// @Param binding body dto.BindingDTO true "Binding Info"
|
||||
// @Success 200 {object} model.Binding
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=model.Binding}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/bindings/{id} [put]
|
||||
func (h *Handler) UpdateBinding(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
@@ -180,10 +180,10 @@ func (h *Handler) UpdateBinding(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Binding ID"
|
||||
// @Success 200 {object} model.Binding
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=model.Binding}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/bindings/{id} [get]
|
||||
func (h *Handler) GetBinding(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
@@ -207,10 +207,10 @@ func (h *Handler) GetBinding(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Binding ID"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/bindings/{id} [delete]
|
||||
func (h *Handler) DeleteBinding(c *gin.Context) {
|
||||
idParam := c.Param("id")
|
||||
|
||||
Reference in New Issue
Block a user