Add DataBase interface
This commit is contained in:
parent
c023193605
commit
3d078ab2b3
135
openbookr/ABC.py
135
openbookr/ABC.py
|
@ -6,6 +6,7 @@
|
|||
|
||||
from abc import ABC, abstractmethod
|
||||
from openbookr.models import Book
|
||||
from collections.abc import Iterable
|
||||
|
||||
|
||||
class BookCreator(ABC):
|
||||
|
@ -21,3 +22,137 @@ class BookCreator(ABC):
|
|||
|
||||
def __book__(self) -> Book:
|
||||
return self.book
|
||||
|
||||
|
||||
class IDataBase(ABC):
|
||||
"""
|
||||
DataBase Interface
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def add_book(self, book: Book) -> None:
|
||||
"""
|
||||
Add book to database
|
||||
|
||||
:param book: Book model
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def get_book(self, book_id: int) -> Book:
|
||||
"""
|
||||
Returns book from database by id
|
||||
|
||||
:param book_id: Book table primary id
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def del_book(self, book_id: int) -> None:
|
||||
"""
|
||||
Removes book from database by id
|
||||
|
||||
:param book_id: Book table primary id
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def update_book(self, book_id: int, updated_book: Book) -> None:
|
||||
"""
|
||||
Replace already existing book in database
|
||||
|
||||
:param book_id: Book table primary id
|
||||
:param updated_book: New book model
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def book_list(
|
||||
self,
|
||||
author: str | None = None,
|
||||
tags: Iterable | str | None = None,
|
||||
genres: Iterable | str | None = None,
|
||||
) -> Iterable:
|
||||
"""
|
||||
Returns all book list or book list by filters
|
||||
|
||||
:param author: Author filter
|
||||
:param tags: Tags filter
|
||||
:param genres: Genre filter
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def add_genre(self, genre: str) -> None:
|
||||
"""
|
||||
Add genre to database
|
||||
|
||||
:param genre: Genre name
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def add_tag(self, tag: str) -> None:
|
||||
"""
|
||||
Add tag to database
|
||||
|
||||
:param tag: Tag name
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def del_genre(self, genre_id: int) -> None:
|
||||
"""
|
||||
Removes genre from database
|
||||
|
||||
:param genre_id: Genre table primary id
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def del_tag(self, tag_id: int) -> None:
|
||||
"""
|
||||
Removes tag from database
|
||||
|
||||
:param tag_id: Tag table primary id
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def add_author(self, author: str) -> None:
|
||||
"""
|
||||
Add author to database
|
||||
|
||||
:param author: Author name
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def del_author(self, author_id: int) -> None:
|
||||
"""
|
||||
Removes author from database
|
||||
|
||||
:param author_id: Author table primary id
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def authors(self) -> Iterable:
|
||||
"""
|
||||
Returns authors list
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def genres(self) -> Iterable:
|
||||
"""
|
||||
Returns genres list
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
async def tags(self) -> Iterable:
|
||||
"""
|
||||
Returns tags list
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
|
Loading…
Reference in New Issue