feat(ebooks): add ISBN normalization and graceful library requirement handling
- Increase ISBN column from VARCHAR(13) to VARCHAR(17) to support ISBN-13 with hyphens - Add normalize_isbn() database function to automatically remove hyphens and spaces - Create trigger to auto-normalize ISBNs on INSERT/UPDATE operations - Update all Ebook and MediaItem queries to use ISBN normalization - Add GetEbookLibraryID query to check for existing ebook libraries - Add graceful error handling when no ebook library exists - Return helpful error message: 'no ebook library found. Please create an ebook library first' - Create comprehensive tests for ISBN normalization and library selection - Add Bruno test files for various ISBN formats and error scenarios - Update documentation with ISBN normalization details
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
meta {
|
||||
name: Create Ebook with Various ISBN Formats
|
||||
type: http
|
||||
seq: 9
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{base_url}}/api/ebooks
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"title": "Ebook with ISBN-13 (with hyphens)",
|
||||
"author": "Test Author",
|
||||
"isbn": "978-0-12345-678-9",
|
||||
"description": "Testing ISBN normalization with hyphens",
|
||||
"file_path": "/path/to/ebook1.epub",
|
||||
"file_size": 1048576,
|
||||
"mime_type": "application/epub+zip"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Create Ebook with ISBN-13 (with hyphens)
|
||||
|
||||
**Expected Behavior:** ISBN should be normalized to `9780123456789`
|
||||
|
||||
This test demonstrates that ISBNs with hyphens are automatically normalized.
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
meta {
|
||||
name: Create Ebook with ISBN (with spaces)
|
||||
type: http
|
||||
seq: 10
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{base_url}}/api/ebooks
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"title": "Ebook with ISBN-13 (with spaces)",
|
||||
"author": "Test Author",
|
||||
"isbn": "978 0123456789",
|
||||
"description": "Testing ISBN normalization with spaces",
|
||||
"file_path": "/path/to/ebook2.epub",
|
||||
"file_size": 1048576,
|
||||
"mime_type": "application/epub+zip"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Create Ebook with ISBN-13 (with spaces)
|
||||
|
||||
**Expected Behavior:** ISBN should be normalized to `9780123456789`
|
||||
|
||||
This test demonstrates that ISBNs with spaces are automatically normalized.
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
meta {
|
||||
name: Create Ebook - No Library Error
|
||||
type: http
|
||||
seq: 11
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{base_url}}/api/ebooks
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"title": "Test Ebook",
|
||||
"isbn": "9780123456789",
|
||||
"description": "Testing error when no library exists",
|
||||
"file_path": "/path/to/ebook.epub",
|
||||
"file_size": 1048576,
|
||||
"mime_type": "application/epub+zip"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Create Ebook - No Library Error
|
||||
|
||||
**Expected Behavior:** Should return 400 Bad Request with error message: "no ebook library found. Please create an ebook library first"
|
||||
|
||||
This test demonstrates the graceful error handling when attempting to create an ebook without first creating an ebook library.
|
||||
|
||||
**Setup Required:**
|
||||
- Ensure NO ebook library exists in the database
|
||||
- Run as admin user
|
||||
|
||||
**Expected Response:**
|
||||
```json
|
||||
{
|
||||
"error": "no ebook library found. Please create an ebook library first"
|
||||
}
|
||||
```
|
||||
}
|
||||
@@ -14,7 +14,7 @@ body:json {
|
||||
{
|
||||
"title": "Sample Ebook Title",
|
||||
"author": "Author Name",
|
||||
"isbn": "978-0123456789",
|
||||
"isbn": "9780123456789",
|
||||
"description": "A sample ebook description",
|
||||
"file_path": "/path/to/ebook.epub",
|
||||
"file_size": 1048576,
|
||||
@@ -37,19 +37,19 @@ settings {
|
||||
|
||||
docs {
|
||||
## Create Ebook
|
||||
|
||||
|
||||
Creates a new ebook entry in the database.
|
||||
|
||||
|
||||
**Method:** POST
|
||||
|
||||
|
||||
**Endpoint:** /api/ebooks
|
||||
|
||||
|
||||
**Authentication:** Required (Admin only)
|
||||
|
||||
|
||||
**Request Body:** JSON object with:
|
||||
- `title` (string, required): Ebook title (1-500 characters)
|
||||
- `author` (string, optional): Author name
|
||||
- `isbn` (string, optional): ISBN number
|
||||
- `isbn` (string, optional): ISBN number (will be normalized to remove hyphens and spaces)
|
||||
- `description` (string, optional): Ebook description
|
||||
- `file_path` (string, required): Path to ebook file
|
||||
- `file_size` (integer, required): File size in bytes
|
||||
@@ -62,19 +62,26 @@ docs {
|
||||
- `date_published` (string, optional): Publication date (YYYY-MM-DD)
|
||||
- `publisher` (string, optional): Publisher name
|
||||
- `contributors` (string, optional): Contributors list
|
||||
|
||||
|
||||
**Response:** Complete ebook object with all fields
|
||||
|
||||
|
||||
**Status Codes:**
|
||||
- 201: Ebook created successfully
|
||||
- 400: Bad request (invalid data)
|
||||
- 400: Bad request (invalid data, or no ebook library exists)
|
||||
- 401: Unauthorized
|
||||
- 403: Forbidden (admin access required)
|
||||
- 500: Internal server error
|
||||
|
||||
|
||||
**Features:**
|
||||
- Admin-only endpoint for creating ebooks
|
||||
- Full validation of required fields
|
||||
- Supports all ebook metadata fields
|
||||
- ISBN normalization: automatically removes hyphens and spaces (e.g., "978-0-12345-678-9" becomes "9780123456789")
|
||||
- Requires an existing ebook library to create ebooks
|
||||
- Associates ebook with creating admin user
|
||||
|
||||
**ISBN Formats Supported:**
|
||||
- ISBN-13: `9780123456789` or `978-0-12345-678-9` or `978-0123456789`
|
||||
- ISBN-10: `0123456789` or `0-12345-678-9`
|
||||
- All formats are automatically normalized (hyphens and spaces removed)
|
||||
}
|
||||
Reference in New Issue
Block a user