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:
@@ -90,8 +90,8 @@ type ListAlertsResponse struct {
|
||||
// @Param status query string false "filter by status (active, acknowledged, resolved, dismissed)"
|
||||
// @Param severity query string false "filter by severity (info, warning, critical)"
|
||||
// @Param type query string false "filter by type (rate_limit, error_spike, quota_exceeded, key_disabled, key_expired, provider_down, traffic_spike)"
|
||||
// @Success 200 {object} ListAlertsResponse
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=ListAlertsResponse}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts [get]
|
||||
func (h *AlertHandler) ListAlerts(c *gin.Context) {
|
||||
limit, offset := parseLimitOffset(c)
|
||||
@@ -140,9 +140,9 @@ func (h *AlertHandler) ListAlerts(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Alert ID"
|
||||
// @Success 200 {object} AlertView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/{id} [get]
|
||||
func (h *AlertHandler) GetAlert(c *gin.Context) {
|
||||
id, ok := parseUintParam(c, "id")
|
||||
@@ -180,9 +180,9 @@ type CreateAlertRequest struct {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param request body CreateAlertRequest true "Alert data"
|
||||
// @Success 201 {object} AlertView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 201 {object} ResponseEnvelope{data=AlertView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts [post]
|
||||
func (h *AlertHandler) CreateAlert(c *gin.Context) {
|
||||
var req CreateAlertRequest
|
||||
@@ -247,10 +247,10 @@ type AckAlertRequest struct {
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Alert ID"
|
||||
// @Param request body AckAlertRequest false "Ack data"
|
||||
// @Success 200 {object} AlertView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/{id}/ack [post]
|
||||
func (h *AlertHandler) AcknowledgeAlert(c *gin.Context) {
|
||||
id, ok := parseUintParam(c, "id")
|
||||
@@ -294,10 +294,10 @@ func (h *AlertHandler) AcknowledgeAlert(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Alert ID"
|
||||
// @Success 200 {object} AlertView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/{id}/resolve [post]
|
||||
func (h *AlertHandler) ResolveAlert(c *gin.Context) {
|
||||
id, ok := parseUintParam(c, "id")
|
||||
@@ -337,10 +337,10 @@ func (h *AlertHandler) ResolveAlert(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Alert 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/alerts/{id} [delete]
|
||||
func (h *AlertHandler) DismissAlert(c *gin.Context) {
|
||||
id, ok := parseUintParam(c, "id")
|
||||
@@ -379,8 +379,8 @@ type AlertStats struct {
|
||||
// @Tags admin
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Success 200 {object} AlertStats
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertStats}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/stats [get]
|
||||
func (h *AlertHandler) GetAlertStats(c *gin.Context) {
|
||||
var total, active, acknowledged, resolved, critical, warning, info int64
|
||||
@@ -435,8 +435,8 @@ func toAlertThresholdView(cfg model.AlertThresholdConfig) AlertThresholdView {
|
||||
// @Tags admin
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Success 200 {object} AlertThresholdView
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertThresholdView}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/thresholds [get]
|
||||
func (h *AlertHandler) GetAlertThresholds(c *gin.Context) {
|
||||
cfg, err := h.loadThresholdConfig()
|
||||
@@ -466,9 +466,9 @@ type UpdateAlertThresholdsRequest struct {
|
||||
// @Produce json
|
||||
// @Security AdminAuth
|
||||
// @Param request body UpdateAlertThresholdsRequest true "Threshold configuration"
|
||||
// @Success 200 {object} AlertThresholdView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=AlertThresholdView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /admin/alerts/thresholds [put]
|
||||
func (h *AlertHandler) UpdateAlertThresholds(c *gin.Context) {
|
||||
var req UpdateAlertThresholdsRequest
|
||||
|
||||
Reference in New Issue
Block a user