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:
@@ -89,10 +89,10 @@ func toIPBanView(ban *model.IPBan) IPBanView {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param ban body CreateIPBanRequest true "IP Ban Info"
|
||||
// @Success 201 {object} IPBanView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 409 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 201 {object} ResponseEnvelope{data=IPBanView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 409 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/ip-bans [post]
|
||||
func (h *IPBanHandler) Create(c *gin.Context) {
|
||||
var req CreateIPBanRequest
|
||||
@@ -139,8 +139,8 @@ func (h *IPBanHandler) Create(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param status query string false "Filter by status (active, expired)"
|
||||
// @Success 200 {array} IPBanView
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=[]IPBanView}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/ip-bans [get]
|
||||
func (h *IPBanHandler) List(c *gin.Context) {
|
||||
status := c.Query("status")
|
||||
@@ -167,9 +167,9 @@ func (h *IPBanHandler) List(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "IP Ban ID"
|
||||
// @Success 200 {object} IPBanView
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=IPBanView}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/ip-bans/{id} [get]
|
||||
func (h *IPBanHandler) Get(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
@@ -200,11 +200,11 @@ func (h *IPBanHandler) Get(c *gin.Context) {
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "IP Ban ID"
|
||||
// @Param ban body UpdateIPBanRequest true "IP Ban Update"
|
||||
// @Success 200 {object} IPBanView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 409 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=IPBanView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 409 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/ip-bans/{id} [put]
|
||||
func (h *IPBanHandler) Update(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
@@ -250,8 +250,8 @@ func (h *IPBanHandler) Update(c *gin.Context) {
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "IP Ban ID"
|
||||
// @Success 204
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/ip-bans/{id} [delete]
|
||||
func (h *IPBanHandler) Delete(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user