11package handler
22
33import (
4+ "errors"
5+ "os"
6+
47 "github.com/gofiber/fiber/v2"
58 "github.com/highcard-dev/daemon/internal/core/ports"
69)
@@ -19,13 +22,20 @@ func NewUiHandler(uiService ports.UiServiceInterface) *UiHandler {
1922// @ID getPublicUIIndex
2023// @Tags ui, druid, daemon
2124// @Accept */*
22- // @Produce html
23- // @Success 200
25+ // @Produce json
26+ // @Success 200 {array} string "List of files in public UI directory"
27+ // @Failure 404 {object} map[string]string "Public UI directory not found"
28+ // @Failure 500 {object} map[string]string "Internal server error with details"
2429// @Router /public/index [get]
2530func (uh * UiHandler ) PublicIndex (ctx * fiber.Ctx ) error {
2631 files , err := uh .uiService .GetIndex ("public" )
2732 if err != nil {
28- return ctx .Status (500 ).SendString ("Failed to retrieve public UI index" )
33+ if errors .Is (err , os .ErrNotExist ) {
34+ return ctx .Status (fiber .StatusNotFound ).SendString ("Public UI directory not found" )
35+ }
36+ return ctx .Status (500 ).JSON (fiber.Map {
37+ "error" : err .Error (),
38+ })
2939 }
3040 return ctx .JSON (files )
3141}
@@ -34,13 +44,20 @@ func (uh *UiHandler) PublicIndex(ctx *fiber.Ctx) error {
3444// @ID getPrivateUIIndex
3545// @Tags ui, druid, daemon
3646// @Accept */*
37- // @Produce html
38- // @Success 200
47+ // @Produce json
48+ // @Success 200 {array} string "List of files in private UI directory"
49+ // @Failure 404 {object} map[string]string "Private UI directory not found"
50+ // @Failure 500 {object} map[string]string "Internal server error with details"
3951// @Router /private/index [get]
4052func (uh * UiHandler ) PrivateIndex (ctx * fiber.Ctx ) error {
4153 files , err := uh .uiService .GetIndex ("private" )
4254 if err != nil {
43- return ctx .Status (500 ).SendString ("Failed to retrieve private UI index" )
55+ if errors .Is (err , os .ErrNotExist ) {
56+ return ctx .Status (fiber .StatusNotFound ).SendString ("Private UI directory not found" )
57+ }
58+ return ctx .Status (500 ).JSON (fiber.Map {
59+ "error" : err .Error (),
60+ })
4461 }
4562 return ctx .JSON (files )
4663}
0 commit comments