Convert tags and contributors columns from comma-separated strings to PostgreSQL TEXT[] arrays for better data normalization and query performance. Database Changes: - schema.sql: Change tags/contributors from TEXT to TEXT[] - schema.sql: Add GIN indexes for fast array searches - queries.sql: Update search queries to use ANY() operator - queries.sql: Update fuzzy search with unnest() for arrays Generated Code (sqlc): - models.go: Auto-generated with []string types for tags/contributors - queries.sql.go: Auto-generated with proper array handling Handler Changes: - media.go: Update request structs to use []string for tags/contributors - media.go: Remove pgtype.Text wrapping, use direct array assignment - media.go: Add tag normalization in CreateMediaItemHandler - collections.go: Update tags evaluation to join arrays for comparison - collections.go: Add strings import for Join() function Service Changes: - ebook_scanner.go: Update EbookMetadata struct to use []string - ebook_scanner.go: Remove string Join(), assign arrays directly - collection_service.go: Update tags rule evaluation to join arrays - collection_service.go: Add strings import New Utilities: - internal/utils/tags.go: Create NormalizeTags(), JoinTags(), SplitTags() - Normalizes tags by trimming, lowercasing, removing duplicates/empties API Documentation: - bruno/media-items/Create Media Item.bru: Update examples to use arrays - bruno/media-items/Update Media Item.bru: Update examples to use arrays - Update docs: tags/contributors now array of string Breaking Change: - JSON format changes from "tags": "tag1,tag2" to "tags": ["tag1", "tag2"] - Tests already use array format (no changes needed) Benefits: - GIN indexes enable faster array searches - Normalization prevents data quality issues (case, duplicates) - Array operations use PostgreSQL native operators (ANY, &&, unnest) - Better separation of concerns (no string parsing in application)
104 lines
2.3 KiB
Plaintext
104 lines
2.3 KiB
Plaintext
meta {
|
|
name: Update Media Item
|
|
type: http
|
|
seq: 2
|
|
}
|
|
|
|
put {
|
|
url: {{base_url}}/api/media-items/{{media_item_id}}
|
|
body: json
|
|
auth: inherit
|
|
}
|
|
|
|
headers {
|
|
Content-Type: application/json
|
|
}
|
|
|
|
body:json {
|
|
"title": "Updated Media Item Title",
|
|
"author": "Updated Author Name",
|
|
"isbn": "978-9876543210",
|
|
"description": "Updated description",
|
|
"cover_image_path": "/updated/path/to/cover.jpg",
|
|
"series": "Updated Series Name",
|
|
"series_number": 2,
|
|
"tags": ["updated", "fiction", "adventure"],
|
|
"asin": "B09XYZ789",
|
|
"date_published": "2023-02-20",
|
|
"publisher": "Updated Publisher",
|
|
"contributors": ["Updated Contributor"],
|
|
"language": "en",
|
|
"edition": "Updated Edition",
|
|
"page_count": 400,
|
|
"genre": "Updated Genre",
|
|
"copyright_year": 2023,
|
|
"goodreads_id": "7890123",
|
|
"openlibrary_id": "OL789012M",
|
|
"google_books_id": "GB789012"
|
|
}
|
|
|
|
tests {
|
|
test_update_media_item_success(status, headers, body) {
|
|
if (status !== 200) {
|
|
throw new Error("Expected status 200, got " + status);
|
|
}
|
|
|
|
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 updated media item object in response");
|
|
}
|
|
|
|
if (!data.id || !data.updated_at) {
|
|
throw new Error("Media item response missing update confirmation");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
vars:pre-request {
|
|
mediaItemId: "550e8400-e29b-41d4-a716-446655440000"
|
|
}
|
|
|
|
settings {
|
|
encodeUrl: true
|
|
timeout: 0
|
|
}
|
|
|
|
docs {
|
|
## Update Media Item
|
|
|
|
Updates an existing media item's metadata.
|
|
|
|
**Method:** PUT
|
|
|
|
**Endpoint:** /api/media-items/{id}
|
|
|
|
**Authentication:** Required (Bearer token, admin only)
|
|
|
|
**Path Parameters:**
|
|
- `id` (string): Media item UUID
|
|
|
|
**Request Body:** All media item fields (same as Create)
|
|
|
|
**Response:** Updated media item object
|
|
|
|
**Status Codes:**
|
|
- 200: Media item updated successfully
|
|
- 400: Invalid request data
|
|
- 401: Unauthorized
|
|
- 403: Forbidden (admin access required)
|
|
- 404: Media item not found
|
|
- 500: Internal server error
|
|
|
|
**Examples:**
|
|
- Update media item: `PUT /api/media-items/550e8400-e29b-41d4-a716-446655440000`
|
|
|
|
**Note:** Admin access required - only users with admin role can update media items.
|
|
} |