refactor and documentation
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||
"git.oblat.lv/alex/triggerssmith/internal/server"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
@@ -41,16 +42,26 @@ func MustRoute(config *config.Config) func(chi.Router) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary Get block
|
||||
// @Tags block
|
||||
// @Produce json
|
||||
// @Param blockPath path string true "Block Path" example(menu)
|
||||
// @Success 200 {object} Block
|
||||
// @Failure 403 {object} server.ProblemDetails
|
||||
// @Failure 404 {object} server.ProblemDetails
|
||||
// @Failure 500 {object} server.ProblemDetails
|
||||
// @Router /api/block/{blockPath} [get]
|
||||
func (h *blockHandler) handleBlock(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.cfg.Server.BlockConfig.Enabled {
|
||||
http.Error(w, "Block serving is disabled", http.StatusForbidden)
|
||||
server.WriteProblem(w, http.StatusForbidden, "/errors/block/block-serving-disabled", "Block serving is disabled", "Block serving is disabled", r)
|
||||
return
|
||||
}
|
||||
|
||||
blockPath := r.URL.Path[len("/api/block/"):]
|
||||
block, err := LoadBlock(blockPath, h.cfg)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
slog.Error("failed to load block", slog.String("path", blockPath), slog.String("err", err.Error()))
|
||||
server.WriteProblem(w, http.StatusInternalServerError, "/errors/internal-server-error", "Internal Server Error", "failed to load block", r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user