diff --git a/bruno/library/Create Library.bru b/bruno/library/Create Library.bru index 8b190f0..3ca482f 100644 --- a/bruno/library/Create Library.bru +++ b/bruno/library/Create Library.bru @@ -6,8 +6,8 @@ meta { post { url: {{base_url}}/api/libraries - auth: inherit body: json + auth: inherit } headers { @@ -22,59 +22,6 @@ body:json { } } -tests { - test_create_library_success(status, headers, body) { - if (status !== 201) { - throw new Error("Expected status 201, got " + status); - } - - const contentType = headers["content-type"]; - if (!contentType || !contentType.includes("application/json")) { - throw new Error("Expected content-type to contain application/json, got " + contentType); - } - - // Verify response body is valid JSON and has expected structure - let data; - try { - data = JSON.parse(body); - } catch (e) { - throw new Error("Response body is not valid JSON"); - } - - if (!data || typeof data !== "object") { - throw new Error("Expected response body to be an object"); - } - - // Check for required fields in library response - if (!data.id) { - throw new Error("Library response missing required field: id"); - } - - if (!data.name) { - throw new Error("Library response missing required field: name"); - } - - if (!data.type) { - throw new Error("Library response missing required field: type"); - } - - // Validate data types - if (typeof data.id !== "string") { - throw new Error("Library id must be a string"); - } - - if (typeof data.name !== "string") { - throw new Error("Library name must be a string"); - } - - if (!["ebooks", "audiobooks", "videos", "other"].includes(data.type)) { - throw new Error("Invalid library type: " + data.type); - } - - return true; - } -} - settings { encodeUrl: true timeout: 0 @@ -116,4 +63,4 @@ docs { - 403: Forbidden (insufficient permissions) - 409: Library name already exists - 500: Internal server error -} \ No newline at end of file +} diff --git a/internal/handlers/library.go b/internal/handlers/library.go index 94241e0..2fae81b 100644 --- a/internal/handlers/library.go +++ b/internal/handlers/library.go @@ -56,6 +56,7 @@ func (h *LibraryHandler) GetLibraryTypes(c echo.Context) error { // CreateLibrary creates a new library func (h *LibraryHandler) CreateLibrary(c echo.Context) error { user := c.Get("user").(database.Users) + userUUID := user.ID.Bytes var req CreateLibraryRequest if err := c.Bind(&req); err != nil { @@ -70,7 +71,7 @@ func (h *LibraryHandler) CreateLibrary(c echo.Context) error { req.Name, req.Description, req.Type, - user.ID, + pgtype.UUID{Bytes: userUUID, Valid: true}, ) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()}) @@ -106,9 +107,13 @@ func (h *LibraryHandler) ListLibraries(c echo.Context) error { // GetUserVisibleLibraries retrieves libraries visible to the current user func (h *LibraryHandler) GetUserVisibleLibraries(c echo.Context) error { - user := c.Get("user").(database.Users) + userID := c.Get("user_id").(string) + userUUID, err := uuid.Parse(userID) + if err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid user id"}) + } - libraries, err := h.libraryService.GetUserVisibleLibraries(c.Request().Context(), user.ID) + libraries, err := h.libraryService.GetUserVisibleLibraries(c.Request().Context(), pgtype.UUID{Bytes: userUUID, Valid: true}) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()}) }