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)
125 lines
3.4 KiB
Plaintext
125 lines
3.4 KiB
Plaintext
meta {
|
|
name: Create Media Item
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
post {
|
|
url: {{base_url}}/api/media-items
|
|
body: json
|
|
auth: inherit
|
|
}
|
|
|
|
headers {
|
|
Content-Type: application/json
|
|
}
|
|
|
|
body:json {
|
|
"library_id": "{{library_id}}",
|
|
"title": "New Media Item",
|
|
"author": "Author Name",
|
|
"isbn": "978-0123456789",
|
|
"description": "Description of the media item",
|
|
"cover_image_path": "/path/to/cover.jpg",
|
|
"series": "Series Name",
|
|
"series_number": 1,
|
|
"tags": ["fiction", "adventure"],
|
|
"asin": "B08XYZ123",
|
|
"date_published": "2023-01-15",
|
|
"publisher": "Publisher Name",
|
|
"contributors": ["Contributor Name"],
|
|
"language": "en",
|
|
"edition": "First Edition",
|
|
"page_count": 350,
|
|
"genre": "Science Fiction",
|
|
"copyright_year": 2023,
|
|
"goodreads_id": "123456",
|
|
"openlibrary_id": "OL123456M",
|
|
"google_books_id": "GB123456"
|
|
}
|
|
|
|
tests {
|
|
test_create_media_item_success(status, headers, body) {
|
|
if (status !== 201) {
|
|
throw new Error("Expected status 201, 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 media item object in response");
|
|
}
|
|
|
|
// Verify required fields
|
|
if (!data.id || !data.title || !data.library_id) {
|
|
throw new Error("Media item missing required fields: id, title, library_id");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
vars:pre-request {
|
|
libraryId: "cc23c3a7-f8fb-451a-a78d-2a16df1b725a"
|
|
}
|
|
|
|
settings {
|
|
encodeUrl: true
|
|
timeout: 0
|
|
}
|
|
|
|
docs {
|
|
## Create Media Item
|
|
|
|
Creates a new media item in a library with full metadata.
|
|
|
|
**Method:** POST
|
|
|
|
**Endpoint:** /api/media-items
|
|
|
|
**Authentication:** Required (Bearer token, admin only)
|
|
|
|
**Request Body:**
|
|
- `library_id` (string, required): Library UUID
|
|
- `title` (string, required): Media item title
|
|
- `author` (string, optional): Author name
|
|
- `isbn` (string, optional): ISBN number
|
|
- `description` (string, optional): Description
|
|
- `cover_image_path` (string, optional): Path to cover image
|
|
- `series` (string, optional): Series name
|
|
- `series_number` (integer, optional): Number in series
|
|
- `tags` (array of string, optional): Tags or categories
|
|
- `asin` (string, optional): Amazon ASIN
|
|
- `date_published` (string, optional): Publication date
|
|
- `publisher` (string, optional): Publisher name
|
|
- `contributors` (array of string, optional): List of contributors
|
|
- `language` (string, optional): Language code (ISO 639-1)
|
|
- `edition` (string, optional): Edition information
|
|
- `page_count` (integer, optional): Total page count
|
|
- `genre` (string, optional): Genre classification
|
|
- `copyright_year` (integer, optional): Copyright year
|
|
- `goodreads_id` (string, optional): Goodreads identifier
|
|
- `openlibrary_id` (string, optional): Open Library identifier
|
|
- `google_books_id` (string, optional): Google Books identifier
|
|
|
|
**Response:** Created media item object
|
|
- All fields above plus system-generated fields
|
|
|
|
**Status Codes:**
|
|
- 201: Media item created successfully
|
|
- 400: Invalid request data
|
|
- 401: Unauthorized
|
|
- 403: Forbidden (admin access required)
|
|
- 404: Library not found
|
|
- 500: Internal server error
|
|
|
|
**Examples:**
|
|
- Create media item: `POST /api/media-items`
|
|
|
|
**Note:** Admin access required - only users with admin role can create media items.
|
|
} |