mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
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
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ez-api/ez-api/internal/dto"
|
|
"github.com/ez-api/ez-api/internal/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Ensure dto types are referenced for swagger generation
|
|
var (
|
|
_ dto.LogWebhookConfigResponse
|
|
_ dto.UpdateLogWebhookConfigRequest
|
|
)
|
|
|
|
// GetLogWebhookConfig godoc
|
|
// @Summary Get log webhook config
|
|
// @Description Returns current webhook notification config
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Security AdminAuth
|
|
// @Success 200 {object} ResponseEnvelope{data=dto.LogWebhookConfigResponse}
|
|
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
|
// @Router /admin/logs/webhook [get]
|
|
func (h *Handler) GetLogWebhookConfig(c *gin.Context) {
|
|
if h == nil || h.logWebhook == nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "webhook service not configured"})
|
|
return
|
|
}
|
|
cfg, err := h.logWebhook.GetConfig(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to read webhook config", "details": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, cfg)
|
|
}
|
|
|
|
// UpdateLogWebhookConfig godoc
|
|
// @Summary Update log webhook config
|
|
// @Description Updates webhook notification config
|
|
// @Tags admin
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security AdminAuth
|
|
// @Param request body dto.UpdateLogWebhookConfigRequest true "Webhook config"
|
|
// @Success 200 {object} ResponseEnvelope{data=dto.LogWebhookConfigResponse}
|
|
// @Failure 400 {object} ResponseEnvelope{data=MapData}
|
|
// @Failure 500 {object} ResponseEnvelope{data=MapData}
|
|
// @Router /admin/logs/webhook [put]
|
|
func (h *Handler) UpdateLogWebhookConfig(c *gin.Context) {
|
|
if h == nil || h.logWebhook == nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "webhook service not configured"})
|
|
return
|
|
}
|
|
var req service.LogWebhookConfig
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
cfg, err := h.logWebhook.SetConfig(c.Request.Context(), req)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, cfg)
|
|
}
|