diff --git a/internal/handlers/library.go b/internal/handlers/library.go index b3cf96a..01ad375 100644 --- a/internal/handlers/library.go +++ b/internal/handlers/library.go @@ -4,6 +4,7 @@ import ( "bookmann/internal/database" "bookmann/internal/services" "net/http" + "os" "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" @@ -173,6 +174,14 @@ func (h *LibraryHandler) AddLibraryFolder(c echo.Context) error { return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()}) } + // Validate that folder path exists and is accessible + if _, err := os.Stat(req.FolderPath); os.IsNotExist(err) { + return c.JSON(http.StatusBadRequest, map[string]string{"error": "folder path does not exist"}) + } + if err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"error": "folder is not accessible"}) + } + folder, err := h.libraryService.AddLibraryFolder( c.Request().Context(), libraryID,