diff --git a/internal/handler/routes_authenticated.go b/internal/handler/routes_authenticated.go index 31dd39e..b127f80 100644 --- a/internal/handler/routes_authenticated.go +++ b/internal/handler/routes_authenticated.go @@ -72,6 +72,9 @@ func registerAuthenticatedRoutes(api *gin.RouterGroup, cfg *config.Config, svc * authed.GET("/favourites", listFavouritesHandler(svc)) authed.POST("/favourites/:id", toggleFavouriteHandler(svc)) + // Storage breakdown. + authed.GET("/storage", storageBreakdownHandler(svc)) + authed.GET("/playlists", listPlaylistsHandler(svc)) authed.POST("/playlists", createPlaylistHandler(svc)) authed.GET("/playlists/:id", getPlaylistHandler(svc)) @@ -112,8 +115,6 @@ func registerAuthenticatedRoutes(api *gin.RouterGroup, cfg *config.Config, svc * authed.DELETE("/files", middleware.AdminRequired(), deleteFileHandler(svc)) authed.POST("/files/transfer", middleware.AdminRequired(), transferFileHandler(svc)) -// // Disk usage breakdown. - // DLNA discovery + cast. authed.GET("/dlna/devices", dlnaListHandler(svc)) authed.POST("/dlna/cast", dlnaCastHandler(svc)) diff --git a/internal/handler/storage.go b/internal/handler/storage.go new file mode 100644 index 0000000..8697587 --- /dev/null +++ b/internal/handler/storage.go @@ -0,0 +1,20 @@ +package handler + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "github.com/ShukeBta/MediaStationGo/internal/service" +) + +func storageBreakdownHandler(svc *service.Container) gin.HandlerFunc { + return func(c *gin.Context) { + breakdown, err := svc.Storage.Compute(c.Request.Context()) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, breakdown) + } +} diff --git a/internal/handler/storage_test.go b/internal/handler/storage_test.go new file mode 100644 index 0000000..6aa4240 --- /dev/null +++ b/internal/handler/storage_test.go @@ -0,0 +1,27 @@ +package handler + +import ( + "testing" + + "github.com/gin-gonic/gin" + "go.uber.org/zap" + + "github.com/ShukeBta/MediaStationGo/internal/config" + "github.com/ShukeBta/MediaStationGo/internal/service" +) + +func TestStorageRouteIsRegistered(t *testing.T) { + gin.SetMode(gin.TestMode) + + router := gin.New() + Register(router, &config.Config{ + Secrets: config.SecretsConfig{JWTSecret: "test-secret"}, + }, zap.NewNop(), &service.Container{Log: zap.NewNop()}) + + for _, route := range router.Routes() { + if route.Method == "GET" && route.Path == "/api/storage" { + return + } + } + t.Fatal("GET /api/storage route is not registered") +}