fix: correct user context type extraction in CreateLibrary handler
- Use c.Get("user").(database.Users) instead of c.Get("user_id").(string)
- Extract userUUID from user.ID.Bytes ([16]byte)
- Properly convert to pgtype.UUID for service layer
- Remove unnecessary uuid.Parse call
This fixes 500 Internal Server Error when creating libraries via API.
The JWT middleware sets user as database.Users struct, not string.
Related to Bruno Create Library request testing.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user