同步前后端联调与文档更新
This commit is contained in:
74
backend/internal/httpapi/handlers/admin_pipeline_handler.go
Normal file
74
backend/internal/httpapi/handlers/admin_pipeline_handler.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"cmr-backend/internal/apperr"
|
||||
"cmr-backend/internal/httpx"
|
||||
"cmr-backend/internal/service"
|
||||
)
|
||||
|
||||
type AdminPipelineHandler struct {
|
||||
service *service.AdminPipelineService
|
||||
}
|
||||
|
||||
func NewAdminPipelineHandler(service *service.AdminPipelineService) *AdminPipelineHandler {
|
||||
return &AdminPipelineHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *AdminPipelineHandler) GetEventPipeline(w http.ResponseWriter, r *http.Request) {
|
||||
limit := 20
|
||||
if raw := r.URL.Query().Get("limit"); raw != "" {
|
||||
if parsed, err := strconv.Atoi(raw); err == nil {
|
||||
limit = parsed
|
||||
}
|
||||
}
|
||||
result, err := h.service.GetEventPipeline(r.Context(), r.PathValue("eventPublicID"), limit)
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
|
||||
func (h *AdminPipelineHandler) BuildSource(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := h.service.BuildSource(r.Context(), r.PathValue("sourceID"))
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
|
||||
func (h *AdminPipelineHandler) GetBuild(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := h.service.GetBuild(r.Context(), r.PathValue("buildID"))
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
|
||||
func (h *AdminPipelineHandler) PublishBuild(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := h.service.PublishBuild(r.Context(), r.PathValue("buildID"))
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
|
||||
func (h *AdminPipelineHandler) RollbackRelease(w http.ResponseWriter, r *http.Request) {
|
||||
var req service.AdminRollbackReleaseInput
|
||||
if err := httpx.DecodeJSON(r, &req); err != nil {
|
||||
httpx.WriteError(w, apperr.New(http.StatusBadRequest, "invalid_json", "invalid request body: "+err.Error()))
|
||||
return
|
||||
}
|
||||
result, err := h.service.RollbackRelease(r.Context(), r.PathValue("eventPublicID"), req)
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
Reference in New Issue
Block a user