rename BookService CRUD overrides to domain-specific methods
The create, update, and delete methods had incompatible signatures resulting in typecheck errors. Renamed to create_book, update_book, and delete_books.
This commit is contained in:
@@ -85,7 +85,7 @@ class BookController(Controller):
|
||||
|
||||
"""
|
||||
|
||||
result = await books_service.create(data, library)
|
||||
result = await books_service.create_book(data, library)
|
||||
book = await books_service.get(result.id)
|
||||
return books_service.to_schema(book, schema_type=s.BookRead)
|
||||
|
||||
@@ -213,7 +213,7 @@ class BookController(Controller):
|
||||
Returns:
|
||||
The updated book as a BookRead schema.
|
||||
"""
|
||||
await books_service.update(book_id, data, library)
|
||||
await books_service.update_book(book_id, data, library)
|
||||
book = await books_service.get(book_id)
|
||||
return books_service.to_schema(book, schema_type=s.BookRead)
|
||||
|
||||
@@ -244,7 +244,7 @@ class BookController(Controller):
|
||||
The updated book as a BookRead schema.
|
||||
"""
|
||||
|
||||
await books_service.update(book_id, {"cover_image": data}, library)
|
||||
await books_service.update_book(book_id, {"cover_image": data}, library)
|
||||
updated_book = await books_service.get(book_id)
|
||||
return books_service.to_schema(updated_book, schema_type=s.BookRead)
|
||||
|
||||
@@ -386,7 +386,7 @@ class BookController(Controller):
|
||||
|
||||
"""
|
||||
|
||||
await books_service.delete(book_ids, library, delete_files=delete_files)
|
||||
await books_service.delete_books(book_ids, library, delete_files=delete_files)
|
||||
|
||||
@post(path="/progress/{book_id:int}")
|
||||
async def update_progress(
|
||||
|
||||
@@ -17,6 +17,7 @@ from advanced_alchemy.service import (
|
||||
SQLAlchemyAsyncRepositoryService,
|
||||
ModelDictT,
|
||||
is_dict,
|
||||
schema_dump
|
||||
)
|
||||
from advanced_alchemy.repository import SQLAlchemyAsyncRepository
|
||||
from advanced_alchemy.filters import CollectionFilter
|
||||
@@ -67,7 +68,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
|
||||
|
||||
|
||||
async def create(self, data: ModelDictT[Book], library: Library, **kwargs) -> Book:
|
||||
async def create_book(self, data: ModelDictT[Book], library: Library, **kwargs) -> Book:
|
||||
"""
|
||||
Create a new book entity.
|
||||
|
||||
@@ -83,9 +84,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
Returns:
|
||||
The created Book entity.
|
||||
"""
|
||||
if not is_dict(data):
|
||||
data = data.model_dump()
|
||||
|
||||
data = schema_dump(data)
|
||||
await self._parse_metadata_from_files(data)
|
||||
|
||||
await self._save_cover_image(data)
|
||||
@@ -126,7 +125,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
books[filepath].append(file)
|
||||
|
||||
return [
|
||||
await self.create(
|
||||
await self.create_book(
|
||||
{"files": [file for file in files], "library_id": library.id},
|
||||
library,
|
||||
**kwargs,
|
||||
@@ -211,7 +210,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
|
||||
return books
|
||||
|
||||
async def delete(
|
||||
async def delete_books(
|
||||
self,
|
||||
book_ids: list[int],
|
||||
library: Library,
|
||||
@@ -309,7 +308,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
break
|
||||
yield chunk
|
||||
|
||||
async def update(
|
||||
async def update_book(
|
||||
self, book_id: int, update_data: ModelDictT[Book], library: Library
|
||||
) -> Book:
|
||||
"""
|
||||
@@ -370,7 +369,7 @@ class BookService(SQLAlchemyAsyncRepositoryService[Book]):
|
||||
data["files"] = files
|
||||
await self._save_book_files(library, data)
|
||||
book.files.extend(data["files"])
|
||||
await self.update(book.id, {"files": [file for file in book.files]}, library)
|
||||
await self.update_book(book.id, {"files": [file for file in book.files]}, library)
|
||||
|
||||
async def remove_files(
|
||||
self, book_id: int, file_ids: list[int], delete_files: bool, library: Library
|
||||
|
||||
Reference in New Issue
Block a user