extract SQLAlchemy model in separate python library
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
def hello() -> str:
|
||||
return "Hello from kontor-model!"
|
||||
@@ -0,0 +1,86 @@
|
||||
from typing import Any, Dict
|
||||
from kontor_model.db.models.admin import (
|
||||
Assignment,
|
||||
Token,
|
||||
Profile,
|
||||
Permission,
|
||||
MailAccount,
|
||||
Mail,
|
||||
)
|
||||
from kontor_model.db.models.bookshelf import (
|
||||
ArticleAuthor,
|
||||
BookAuthor,
|
||||
BookshelfPublisher,
|
||||
Article,
|
||||
Book,
|
||||
Author,
|
||||
)
|
||||
from kontor_model.db.models.comic import (
|
||||
Issue,
|
||||
StoryArc,
|
||||
TradePaperback,
|
||||
Volume,
|
||||
ComicWork,
|
||||
IssueWork,
|
||||
Artist,
|
||||
Comic,
|
||||
Publisher,
|
||||
WorkType,
|
||||
)
|
||||
from kontor_model.db.models.media import (
|
||||
MediaFile,
|
||||
MediaActor,
|
||||
MediaActorFile,
|
||||
MediaArticle,
|
||||
MediaVideo,
|
||||
MediaLofi,
|
||||
)
|
||||
from kontor_model.db.models.tysc import (
|
||||
Card,
|
||||
CardSet,
|
||||
Rooster,
|
||||
Team,
|
||||
FieldPosition,
|
||||
Player,
|
||||
Vendor,
|
||||
Sport,
|
||||
)
|
||||
|
||||
registry: Dict[str, Any] = {
|
||||
Sport.__tablename__: Sport,
|
||||
Player.__tablename__: Player,
|
||||
Team.__tablename__: Team,
|
||||
FieldPosition.__tablename__: FieldPosition,
|
||||
Rooster.__tablename__: Rooster,
|
||||
Vendor.__tablename__: Vendor,
|
||||
CardSet.__tablename__: CardSet,
|
||||
Card.__tablename__: Card,
|
||||
Artist.__tablename__: Artist,
|
||||
Publisher.__tablename__: Publisher,
|
||||
WorkType.__tablename__: WorkType,
|
||||
Comic.__tablename__: Comic,
|
||||
Volume.__tablename__: Volume,
|
||||
StoryArc.__tablename__: StoryArc,
|
||||
Issue.__tablename__: Issue,
|
||||
TradePaperback.__tablename__: TradePaperback,
|
||||
ComicWork.__tablename__: ComicWork,
|
||||
IssueWork.__tablename__: IssueWork,
|
||||
Article.__tablename__: Article,
|
||||
BookshelfPublisher.__tablename__: BookshelfPublisher,
|
||||
Book.__tablename__: Book,
|
||||
Author.__tablename__: Author,
|
||||
ArticleAuthor.__tablename__: ArticleAuthor,
|
||||
BookAuthor.__tablename__: BookAuthor,
|
||||
MediaArticle.__tablename__: MediaArticle,
|
||||
MediaVideo.__tablename__: MediaVideo,
|
||||
MediaLofi.__tablename__: MediaLofi,
|
||||
MediaFile.__tablename__: MediaFile,
|
||||
MediaActor.__tablename__: MediaActor,
|
||||
MediaActorFile.__tablename__: MediaActorFile,
|
||||
Profile.__tablename__: Profile,
|
||||
Permission.__tablename__: Permission,
|
||||
Assignment.__tablename__: Assignment,
|
||||
Token.__tablename__: Token,
|
||||
MailAccount.__tablename__: MailAccount,
|
||||
Mail.__tablename__: Mail
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
|
||||
from sqlalchemy.orm import relationship, mapped_column, Mapped
|
||||
|
||||
from kontor_model.db.models.base import Base, BaseMixin
|
||||
|
||||
|
||||
class Profile(Base, BaseMixin):
|
||||
__tablename__ = 'profile'
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
user_name = Column(String, nullable=False)
|
||||
email = Column(String)
|
||||
password = Column(String)
|
||||
enabled = Column(Boolean)
|
||||
assignments = relationship("Assignment")
|
||||
tokens = relationship("Token")
|
||||
|
||||
def get_full_name(self) -> str:
|
||||
full_name: str = ""
|
||||
if self.first_name is not None:
|
||||
full_name += str(self.first_name)
|
||||
if self.last_name is not None:
|
||||
if len(full_name) > 0:
|
||||
full_name += " "
|
||||
full_name += str(self.last_name)
|
||||
return full_name
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
self.user_name = import_data['user_name']
|
||||
self.email = import_data['email']
|
||||
self.password = import_data['password']
|
||||
self.enabled = import_data['enabled']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['first_name'] = self.first_name
|
||||
item['last_name'] = self.last_name
|
||||
item['user_name'] = self.user_name
|
||||
item['email'] = self.email
|
||||
item['password'] = self.password
|
||||
item['enabled'] = self.enabled
|
||||
return item
|
||||
|
||||
|
||||
class Token(Base, BaseMixin):
|
||||
__tablename__ = "token"
|
||||
token = Column(String, nullable=False, unique=True)
|
||||
name = Column(String)
|
||||
last_used_date: Mapped[datetime] = mapped_column()
|
||||
enabled = Column(Boolean)
|
||||
profile_id = Column(String, ForeignKey("profile.id"), nullable=False)
|
||||
profile = relationship("Profile", back_populates="tokens")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.token = import_data['token']
|
||||
self.name = import_data['name']
|
||||
self.last_used_date = import_data['last_used_date']
|
||||
self.enabled = import_data['enabled']
|
||||
self.profile_id = import_data['profile_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['token'] = self.token
|
||||
item['name'] = self.name
|
||||
item['last_used_date'] = self.last_used_date
|
||||
item['enabled'] = self.enabled
|
||||
item['profile_id'] = self.profile_id
|
||||
return item
|
||||
|
||||
|
||||
class Permission(Base, BaseMixin):
|
||||
__tablename__ = "permission"
|
||||
name = Column(String, nullable=False)
|
||||
assignments = relationship("Assignment")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
return item
|
||||
|
||||
class Assignment(Base, BaseMixin):
|
||||
__tablename__ = "assignment"
|
||||
profile_id = Column(String, ForeignKey("profile.id"), nullable=False)
|
||||
profile = relationship("Profile", back_populates="assignments")
|
||||
permission_id = Column(String, ForeignKey("permission.id"), nullable=False)
|
||||
permission = relationship("Permission", back_populates="assignments")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.profile_id = import_data['profile_id']
|
||||
self.permission_id = import_data['permission_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['profile_id'] = self.profile_id
|
||||
item['permission_id'] = self.permission_id
|
||||
return item
|
||||
|
||||
|
||||
class MailAccount(Base, BaseMixin):
|
||||
__tablename__ = "mail_account"
|
||||
host = Column(String)
|
||||
port = Column(Integer)
|
||||
protocol = Column(String)
|
||||
user_name = Column(String)
|
||||
password = Column(String)
|
||||
start_tls = Column(Boolean)
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.host = import_data['host']
|
||||
self.port = import_data['port']
|
||||
self.protocol = import_data['protocol']
|
||||
self.user_name = import_data['user_name']
|
||||
self.password = import_data['password']
|
||||
self.start_tls = import_data['start_tls']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['host'] = self.host
|
||||
item['port'] = self.port
|
||||
item['protocol'] = self.protocol
|
||||
item['user_name'] = self.user_name
|
||||
item['password'] = self.password
|
||||
item['start_tls'] = self.start_tls
|
||||
return item
|
||||
|
||||
|
||||
class Mail(Base, BaseMixin):
|
||||
__tablename__ = "mail"
|
||||
folder: Mapped[str] = mapped_column()
|
||||
subject: Mapped[str] = mapped_column()
|
||||
body: Mapped[str] = mapped_column()
|
||||
sent_date: Mapped[datetime] = mapped_column()
|
||||
received_date: Mapped[datetime] = mapped_column()
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.folder = import_data['folder']
|
||||
self.subject = import_data['subject']
|
||||
self.body = import_data['body']
|
||||
self.sent_date = import_data['sent_date']
|
||||
self.received_date = import_data['received_date']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['folder'] = self.folder
|
||||
item['subject'] = self.subject
|
||||
item['body'] = self.body
|
||||
item['sent_date'] = str(self.sent_date)
|
||||
item['received_date'] = str(self.received_date)
|
||||
return item
|
||||
@@ -0,0 +1,30 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import func, Column, String, Boolean
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
class BaseMixin:
|
||||
#id = Column(String, primary_key=True, default=uuid.uuid4)
|
||||
id: Mapped[str] = mapped_column(primary_key=True, default=uuid.uuid4)
|
||||
# created_date = Column(DateTime)
|
||||
created_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
# last_modified_date = Column(DateTime)
|
||||
last_modified_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
# version = Column(Integer)
|
||||
version: Mapped[int] = mapped_column(default=0)
|
||||
|
||||
|
||||
class BaseVideoMixin:
|
||||
cloud_link = Column(String, nullable=True)
|
||||
file_name = Column(String, nullable=True)
|
||||
path = Column(String)
|
||||
review = Column(Boolean)
|
||||
title = Column(String)
|
||||
url = Column(String, nullable=True)
|
||||
should_download = Column(Boolean)
|
||||
@@ -0,0 +1,159 @@
|
||||
from typing import Any, Dict
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from kontor_model.db.models.base import Base, BaseMixin
|
||||
|
||||
|
||||
class Article(Base, BaseMixin):
|
||||
__tablename__ = 'article'
|
||||
title = Column(String, unique=True)
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.title = import_data['title']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['title'] = self.title
|
||||
return item
|
||||
|
||||
|
||||
class Author(Base, BaseMixin):
|
||||
__tablename__ = 'author'
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
article_authors = relationship("ArticleAuthor")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['first_name'] = self.first_name
|
||||
item['last_name'] = self.last_name
|
||||
return item
|
||||
|
||||
|
||||
class BookshelfPublisher(Base, BaseMixin):
|
||||
__tablename__ = 'bookshelf_publisher'
|
||||
name = Column(String, unique=True)
|
||||
books = relationship("Book", back_populates="publisher")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
return item
|
||||
|
||||
|
||||
class Book(Base, BaseMixin):
|
||||
__tablename__ = 'book'
|
||||
isbn = Column(String, unique=True)
|
||||
title = Column(String)
|
||||
year = Column(Integer, nullable=False)
|
||||
publisher_id = Column(String, ForeignKey('bookshelf_publisher.id'), nullable=False)
|
||||
publisher = relationship('BookshelfPublisher', back_populates="books")
|
||||
book_authors = relationship("BookAuthor")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.isbn = import_data['isbn']
|
||||
self.title = import_data['title']
|
||||
self.year = import_data['year']
|
||||
self.publisher_id = import_data['publisher_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['isbn'] = self.isbn
|
||||
item['title'] = self.title
|
||||
item['year'] = self.year
|
||||
item['publisher_id'] = self.publisher_id
|
||||
return item
|
||||
|
||||
|
||||
class ArticleAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'article_author'
|
||||
article_id = Column(String, ForeignKey('article.id'), nullable=False)
|
||||
article = relationship('Article', back_populates="article_authors")
|
||||
author_id = Column(String, ForeignKey('author.id'), nullable=False)
|
||||
author = relationship('Author', back_populates="article_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.article_id = import_data['article_id']
|
||||
self.author_id = import_data['author_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['article_id'] = self.article_id
|
||||
item['author_id'] = self.author_id
|
||||
return item
|
||||
|
||||
|
||||
class BookAuthor(Base, BaseMixin):
|
||||
__tablename__ = 'book_author'
|
||||
author_id = Column(String, ForeignKey('author.id'), nullable=False)
|
||||
author = relationship('Author', back_populates="book_authors")
|
||||
book_id = Column(String, ForeignKey('book.id'), nullable=False)
|
||||
book = relationship('Book', back_populates="book_authors")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.author_id = import_data['author_id']
|
||||
self.book_id = import_data['book_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['author_id'] = self.author_id
|
||||
item['book_id'] = self.book_id
|
||||
return item
|
||||
@@ -0,0 +1,352 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional, Any
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean, func
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
from kontor_model.db.models.base import Base, BaseMixin
|
||||
|
||||
|
||||
class Publisher(Base):
|
||||
__tablename__ = "publisher"
|
||||
id: Mapped[str] = mapped_column(primary_key=True, default=uuid.uuid4)
|
||||
created_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
last_modified_date: Mapped[datetime] = mapped_column(default=func.now())
|
||||
version: Mapped[int] = mapped_column(default=0)
|
||||
name = Column(String, unique=True)
|
||||
weblink = Column(String, nullable=True)
|
||||
parent_publisher_id: Mapped[Optional[str]] = mapped_column(ForeignKey('publisher.id'))
|
||||
parent_publisher: Mapped[Optional['Publisher']] = relationship("Publisher", back_populates="imprints", remote_side=[id])
|
||||
imprints: Mapped[List['Publisher']] = relationship('Publisher', back_populates="parent_publisher")
|
||||
comics = relationship("Comic")
|
||||
|
||||
def __repr__(self):
|
||||
return f'Publisher({self.id} {self.name})'
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.parent_publisher_id = import_data['parent_publisher_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'name': self.name,
|
||||
'weblink': self.weblink,
|
||||
'parent_publisher_id': self.parent_publisher_id
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class Comic(Base, BaseMixin):
|
||||
__tablename__ = 'comic'
|
||||
title = Column(String, unique=True)
|
||||
publisher_id = Column(String, ForeignKey('publisher.id'), nullable=False)
|
||||
publisher = relationship("Publisher", back_populates="comics")
|
||||
current_order = Column(Boolean)
|
||||
completed = Column(Boolean)
|
||||
weblink = Column(String, nullable=True)
|
||||
issues = relationship("Issue")
|
||||
story_arcs = relationship("StoryArc")
|
||||
trade_paperbacks = relationship("TradePaperback")
|
||||
volumes = relationship("Volume")
|
||||
comic_works = relationship("ComicWork")
|
||||
|
||||
def __repr__(self):
|
||||
return f'Comic({self.id} {self.version} {self.title} {self.publisher.name})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.title = import_data['title']
|
||||
self.publisher_id = import_data['publisher_id']
|
||||
self.current_order = import_data['current_order']
|
||||
self.completed = import_data['completed']
|
||||
if 'weblink' in import_data:
|
||||
self.weblink = import_data['weblink']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'title': self.title,
|
||||
'publisher_id': self.publisher_id,
|
||||
'current_order': self.current_order,
|
||||
'completed': self.completed,
|
||||
'weblink': self.weblink
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class Volume(Base, BaseMixin):
|
||||
__tablename__ = "volume"
|
||||
name = Column(String, nullable=False)
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="volumes")
|
||||
story_arcs = relationship("StoryArc")
|
||||
issues = relationship("Issue")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.comic_id = import_data['comic_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['comic_id'] = self.comic_id
|
||||
return item
|
||||
|
||||
class TradePaperback(Base, BaseMixin):
|
||||
__tablename__ = "trade_paperback"
|
||||
name = Column(String, nullable=False)
|
||||
issue_start = Column(Integer)
|
||||
issue_end = Column(Integer)
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="trade_paperbacks")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.issue_start = import_data['issue_start']
|
||||
self.issue_end = import_data['issue_end']
|
||||
self.comic_id = import_data['comic_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['issue_start'] = self.issue_start
|
||||
item['issue_end'] = self.issue_end
|
||||
item['comic_id'] = self.comic_id
|
||||
return item
|
||||
|
||||
|
||||
class StoryArc(Base, BaseMixin):
|
||||
__tablename__ = "story_arc"
|
||||
name = Column(String, nullable=False)
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="story_arcs")
|
||||
volume_id = Column(String, ForeignKey("volume.id"), nullable=True)
|
||||
volume = relationship("Volume", back_populates="story_arcs")
|
||||
issues = relationship("Issue")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.volume_id = import_data['volume_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'name': self.name,
|
||||
'comic_id': self.comic_id,
|
||||
'volume_id': self.volume_id
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class Issue(Base, BaseMixin):
|
||||
__tablename__ = "issue"
|
||||
issue_number = Column(String)
|
||||
title = Column(String, nullable=True)
|
||||
published_on: Mapped[datetime] = mapped_column(nullable=True)
|
||||
in_stock = Column(Boolean)
|
||||
is_read = Column(Boolean)
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="issues")
|
||||
volume_id = Column(String, ForeignKey("volume.id"), nullable=True)
|
||||
volume = relationship("Volume", back_populates="issues")
|
||||
story_arc_id = Column(String, ForeignKey("story_arc.id"), nullable=True)
|
||||
story_arc = relationship("StoryArc", back_populates="issues")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.issue_number = import_data['issue_number']
|
||||
self.title = import_data['title']
|
||||
if import_data['published_on'] == 'None':
|
||||
self.published_on = None # type: ignore
|
||||
else:
|
||||
self.published_on = import_data['published_on']
|
||||
self.in_stock = import_data['in_stock']
|
||||
self.is_read = import_data['is_read']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.volume_id = import_data['volume_id']
|
||||
self.story_arc_id = import_data['story_arc_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'issue_number': self.issue_number,
|
||||
'title': self.title,
|
||||
'published_on': str(self.published_on),
|
||||
'in_stock': self.in_stock,
|
||||
'is_read': self.is_read,
|
||||
'comic_id': self.comic_id,
|
||||
'volume_id': self.volume_id,
|
||||
'story_arc_id': self.story_arc_id
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class Artist(Base, BaseMixin):
|
||||
__tablename__ = "artist"
|
||||
name = Column(String, nullable=False)
|
||||
weblink = Column(String, nullable=True)
|
||||
comic_works = relationship("ComicWork")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
if 'weblink' in import_data:
|
||||
self.weblink = import_data['weblink']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'name': self.name,
|
||||
'weblink': self.weblink
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class WorkType(Base, BaseMixin):
|
||||
__tablename__ = "worktype"
|
||||
name = Column(String, nullable=False, unique=True)
|
||||
comic_works = relationship("ComicWork")
|
||||
issue_works = relationship("IssueWork")
|
||||
|
||||
def __repr__(self):
|
||||
return f'Worktype({self.id} {self.version} {self.name} {len(self.comic_works)})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'name': self.name
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class ComicWork(Base, BaseMixin):
|
||||
__tablename__ = "comic_work"
|
||||
comic_id = Column(String, ForeignKey("comic.id"), nullable=False)
|
||||
comic = relationship("Comic", back_populates="comic_works")
|
||||
artist_id = Column(String, ForeignKey("artist.id"), nullable=False)
|
||||
artist = relationship("Artist", back_populates="comic_works")
|
||||
work_type_id = Column(String, ForeignKey("worktype.id"), nullable=False)
|
||||
work_type = relationship("WorkType", back_populates="comic_works")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.comic_id = import_data['comic_id']
|
||||
self.artist_id = import_data['artist_id']
|
||||
self.work_type_id = import_data['work_type_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'comic_id': self.comic_id,
|
||||
'artist_id': self.artist_id,
|
||||
'work_type_id': self.work_type_id
|
||||
}
|
||||
return item
|
||||
|
||||
|
||||
class IssueWork(Base, BaseMixin):
|
||||
__tablename__ = "issue_work"
|
||||
issue_id = Column(String, ForeignKey("issue.id"), nullable=False)
|
||||
issue = relationship("Issue", back_populates="issue_works")
|
||||
artist_id = Column(String, ForeignKey("artist.id"), nullable=False)
|
||||
artist = relationship("Artist", back_populates="issue_works")
|
||||
work_type_id = Column(String, ForeignKey("worktype.id"), nullable=False)
|
||||
work_type = relationship("WorkType", back_populates="issue_works")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.issue_id = import_data['issue_id']
|
||||
self.artist_id = import_data['artist_id']
|
||||
self.work_type_id = import_data['work_type_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {
|
||||
'id': self.id,
|
||||
'created_date': str(self.created_date),
|
||||
'last_modified_date': str(self.last_modified_date),
|
||||
'version': self.version,
|
||||
'issue_id': self.issue_id,
|
||||
'artist_id': self.artist_id,
|
||||
'work_type_id': self.work_type_id
|
||||
}
|
||||
return item
|
||||
@@ -0,0 +1,207 @@
|
||||
from typing import Any, Dict
|
||||
from sqlalchemy import Boolean, Column, String, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from kontor_model.db.models.base import Base, BaseMixin, BaseVideoMixin
|
||||
|
||||
|
||||
class MediaFile(Base, BaseMixin, BaseVideoMixin):
|
||||
__tablename__ = 'media_file'
|
||||
media_actor_files = relationship("MediaActorFile")
|
||||
|
||||
def __repr__(self):
|
||||
return f'MediaFile(\n\tID: {self.id}\n\tTitle: {self.title}\n\tURL: {self.url}\n\tReview: {self.review}\n\tDownload: {self.should_download}\n\tPath: {self.path}\n\tCloudlink: {self.cloud_link})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.title}({self.id})'
|
||||
|
||||
def update_title(self):
|
||||
pass
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.cloud_link = import_data['cloud_link']
|
||||
self.file_name = import_data['file_name']
|
||||
self.path = import_data['path']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
self.should_download = import_data['should_download']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['cloud_link'] = self.cloud_link
|
||||
item['file_name'] = self.file_name
|
||||
item['path'] = self.path
|
||||
item['review'] = self.review
|
||||
item['title'] = self.title
|
||||
item['url'] = self.url
|
||||
item['should_download'] = self.should_download
|
||||
return item
|
||||
|
||||
|
||||
class MediaActor(Base, BaseMixin):
|
||||
__tablename__ = 'media_actor'
|
||||
name = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
media_actor_files = relationship("MediaActorFile")
|
||||
|
||||
def __repr__(self):
|
||||
return f'MediaActor(\n\tID: {self.id}\n\tName: {self.name}\n\tURL: {self.url})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}({self.id})'
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.url = import_data['url']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['url'] = self.url
|
||||
return item
|
||||
|
||||
|
||||
class MediaActorFile(Base, BaseMixin):
|
||||
__tablename__ = 'media_actor_file'
|
||||
media_actor_id = Column(String, ForeignKey("media_actor.id"), nullable=False)
|
||||
media_actor = relationship("MediaActor", back_populates="media_actor_files")
|
||||
media_file_id = Column(String, ForeignKey("media_file.id"), nullable=True)
|
||||
media_file = relationship("MediaFile", back_populates="media_actor_files")
|
||||
|
||||
def __repr__(self):
|
||||
return f'MediaActorFile(\n\tID: {self.id}\n\tMediaActor: {self.media_actor_id}\n\tMediaFile: {self.media_file_id})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.id}: MediaActor: {self.media_actor_id} - MediaFile: {self.media_file_id}'
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.media_actor_id = import_data['media_actor_id']
|
||||
self.media_file_id = import_data['media_file_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['media_actor_id'] = self.media_actor_id
|
||||
item['media_file_id'] = self.media_file_id
|
||||
return item
|
||||
|
||||
class MediaArticle(Base, BaseMixin):
|
||||
__tablename__ = 'media_article'
|
||||
review = Column(Boolean)
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['review'] = self.review
|
||||
item['title'] = self.title
|
||||
item['url'] = self.url
|
||||
return item
|
||||
|
||||
|
||||
class MediaVideo(Base, BaseMixin):
|
||||
__tablename__ = 'media_video'
|
||||
cloud_link = Column(String)
|
||||
file_name = Column(String)
|
||||
path = Column(String)
|
||||
review = Column(Boolean)
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
should_download = Column(Boolean)
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.cloud_link = import_data['cloud_link']
|
||||
self.file_name = import_data['file_name']
|
||||
self.path = import_data['path']
|
||||
self.review = import_data['review']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
self.should_download = import_data['should_download']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['cloud_link'] = self.cloud_link
|
||||
item['file_name'] = self.file_name
|
||||
item['path'] = self.path
|
||||
item['review'] = self.review
|
||||
item['title'] = self.title
|
||||
item['url'] = self.url
|
||||
item['should_download'] = self.should_download
|
||||
return item
|
||||
|
||||
class MediaLofi(Base, BaseMixin):
|
||||
__tablename__ = 'media_lofi'
|
||||
file_name = Column(String)
|
||||
review = Column(Boolean)
|
||||
should_download = Column(Boolean)
|
||||
title = Column(String)
|
||||
url = Column(String, unique=True)
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.file_name = import_data['file_name']
|
||||
self.review = import_data['review']
|
||||
self.should_download = import_data['should_download']
|
||||
self.title = import_data['title']
|
||||
self.url = import_data['url']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['file_name'] = self.file_name
|
||||
item['review'] = self.review
|
||||
item['should_download'] = self.should_download
|
||||
item['title'] = self.title
|
||||
item['url'] = self.url
|
||||
return item
|
||||
@@ -0,0 +1,259 @@
|
||||
from typing import Dict, Any
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from kontor_model.db.models.base import Base, BaseMixin
|
||||
|
||||
|
||||
class Sport(Base, BaseMixin):
|
||||
__tablename__ = "sport"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("name"),
|
||||
)
|
||||
name = Column(String, nullable=False, index=True, unique=True)
|
||||
teams = relationship("Team")
|
||||
positions = relationship("FieldPosition")
|
||||
|
||||
def __repr__(self):
|
||||
return f"Sport(id={self.id}, name={self.name}, created_date={self.created_date})"
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
return item
|
||||
|
||||
class Team(Base, BaseMixin):
|
||||
__tablename__ = "team"
|
||||
name = Column(String, nullable=False, index=True, unique=True)
|
||||
short_name = Column(String, nullable=False, )
|
||||
sport_id = Column(String, ForeignKey("sport.id"), nullable=False)
|
||||
sport = relationship("Sport", back_populates="teams")
|
||||
roosters = relationship("Rooster")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.short_name = import_data['short_name']
|
||||
self.sport_id = import_data['sport_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['short_name'] = self.short_name
|
||||
item['sport_id'] = self.sport_id
|
||||
return item
|
||||
|
||||
class FieldPosition(Base, BaseMixin):
|
||||
__tablename__ = "field_position"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("name", "sport_id"),
|
||||
UniqueConstraint("short_name", "sport_id"),
|
||||
)
|
||||
name = Column(String, nullable=False, index=True)
|
||||
short_name = Column(String, nullable=False)
|
||||
sport_id = Column(String, ForeignKey("sport.id"), nullable=False, index=True)
|
||||
sport = relationship("Sport", back_populates="positions")
|
||||
roosters = relationship("Rooster")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.short_name = import_data['short_name']
|
||||
self.sport_id = import_data['sport_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['short_name'] = self.short_name
|
||||
item['sport_id'] = self.sport_id
|
||||
return item
|
||||
|
||||
|
||||
class Player(Base, BaseMixin):
|
||||
__tablename__ = "player"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("first_name", "last_name"),
|
||||
)
|
||||
first_name = Column(String, nullable=False, index=True)
|
||||
last_name = Column(String, nullable=False, index=True)
|
||||
roosters = relationship("Rooster")
|
||||
|
||||
def get_full_name(self) -> str:
|
||||
return f"{self.last_name}, {self.first_name}"
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.first_name = import_data['first_name']
|
||||
self.last_name = import_data['last_name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['first_name'] = self.first_name
|
||||
item['last_name'] = self.last_name
|
||||
return item
|
||||
|
||||
|
||||
class Rooster(Base, BaseMixin):
|
||||
__tablename__ = "rooster"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("year", "team_id", "player_id", "position_id"),
|
||||
)
|
||||
year = Column(Integer)
|
||||
team_id = Column(String, ForeignKey("team.id"), nullable=False, index=True)
|
||||
team = relationship("Team", back_populates="roosters")
|
||||
player_id = Column(String, ForeignKey("player.id"), nullable=False, index=True)
|
||||
player = relationship("Player", back_populates="roosters")
|
||||
position_id = Column(String, ForeignKey("field_position.id"), nullable=False, index=True)
|
||||
position = relationship("FieldPosition", back_populates="roosters")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.year = import_data['year']
|
||||
self.team_id = import_data['team_id']
|
||||
self.player_id = import_data['player_id']
|
||||
self.position_id = import_data['position_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['year'] = self.year
|
||||
item['team_id'] = self.team_id
|
||||
item['player_id'] = self.player_id
|
||||
item['position_id'] = self.position_id
|
||||
return item
|
||||
|
||||
|
||||
class Vendor(Base, BaseMixin):
|
||||
__tablename__ = "vendor"
|
||||
name = Column(String, nullable=False, unique=True, index=True)
|
||||
card_sets = relationship("CardSet")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
return item
|
||||
|
||||
|
||||
class CardSet(Base, BaseMixin):
|
||||
__tablename__ = "card_set"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("name", "vendor_id"),
|
||||
)
|
||||
name = Column(String, index=True)
|
||||
parallel_set = Column(Boolean)
|
||||
insert_set = Column(Boolean)
|
||||
vendor_id = Column(String, ForeignKey("vendor.id"), nullable=False, index=True)
|
||||
vendor = relationship("Vendor", back_populates="card_sets")
|
||||
cards = relationship("Card")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.name = import_data['name']
|
||||
self.parallel_set = import_data['parallel_set']
|
||||
self.insert_set = import_data['insert_set']
|
||||
self.vendor_id = import_data['vendor_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['name'] = self.name
|
||||
item['parallel_set'] = self.parallel_set
|
||||
item['insert_set'] = self.insert_set
|
||||
item['vendor_id'] = self.vendor_id
|
||||
return item
|
||||
|
||||
|
||||
class Card(Base, BaseMixin):
|
||||
__tablename__ = "card"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("card_number", "year", "vendor_id", "card_set_id"),
|
||||
)
|
||||
card_number = Column(Integer, index=True)
|
||||
year = Column(Integer, index=True)
|
||||
card_set_id = Column(String, ForeignKey("card_set.id"), nullable=False)
|
||||
card_set = relationship("CardSet", back_populates="cards")
|
||||
rooster_id = Column(String, ForeignKey("rooster.id"), nullable=False)
|
||||
rooster = relationship("Rooster", back_populates="cards")
|
||||
vendor_id = Column(String, ForeignKey("vendor.id"), nullable=False)
|
||||
vendor = relationship("Vendor", back_populates="cards")
|
||||
|
||||
def import_dict(self, import_data: Dict[str, Any]):
|
||||
self.id = import_data['id']
|
||||
self.created_date = import_data['created_date']
|
||||
self.last_modified_date = import_data['last_modified_date']
|
||||
self.version = import_data['version']
|
||||
self.card_number = import_data['card_number']
|
||||
self.year = import_data['year']
|
||||
self.card_set_id = import_data['card_set_id']
|
||||
self.rooster_id = import_data['rooster_id']
|
||||
self.vendor_id = import_data['vendor_id']
|
||||
|
||||
def export_dict(self) -> Dict[str, Any]:
|
||||
item: Dict[str, Any] = {}
|
||||
item['id'] = self.id
|
||||
item['created_date'] = str(self.created_date)
|
||||
item['last_modified_date'] = str(self.last_modified_date)
|
||||
item['version'] = self.version
|
||||
item['card_number'] = self.card_number
|
||||
item['year'] = self.year
|
||||
item['card_set_id'] = self.card_set_id
|
||||
item['rooster_id'] = self.rooster_id
|
||||
item['vendor_id'] = self.vendor_id
|
||||
return item
|
||||
@@ -0,0 +1,18 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.admin import Profile
|
||||
|
||||
|
||||
def get_profile_by_username(username: str, db: Session) -> Optional[Profile]:
|
||||
profile = db.query(Profile).filter(Profile.user_name == username).first()
|
||||
return profile
|
||||
|
||||
def get_profile_by_email(email: str, db: Session) -> Optional[Profile]:
|
||||
profile = db.query(Profile).filter(Profile.email == email).first()
|
||||
return profile
|
||||
|
||||
def is_database_empty(db: Session) -> bool:
|
||||
profiles = db.query(Profile).all()
|
||||
return len(profiles) == 0
|
||||
@@ -0,0 +1,54 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.comic import Artist
|
||||
from kontor_model.schema.comics.artist import AddArtist
|
||||
from kontor_model.schema.comics.artist_details import ArtistDetailResponse, ArtistWorktypeComicResponse, ArtistWorktypeIssueResponse
|
||||
from kontor_model.schema.comics.comic import ComicResponse
|
||||
from kontor_model.schema.comics.worktype import WorktypeResponse
|
||||
|
||||
|
||||
def get_artist_details(artist: Artist) -> ArtistDetailResponse:
|
||||
comic_works: List[ArtistWorktypeComicResponse] = []
|
||||
comic_works_map = {}
|
||||
for work in artist.comic_works:
|
||||
worktype_id = work.work_type.id
|
||||
if worktype_id in comic_works_map:
|
||||
comic = ComicResponse(
|
||||
id=work.comic.id,
|
||||
created_date=work.comic.created_date,
|
||||
last_modified_date=work.comic.last_modified_date,
|
||||
version=work.comic.version,
|
||||
publisher_id=work.comic.publisher_id,
|
||||
current_order=work.comic.current_order,
|
||||
weblink=work.comic.weblink,
|
||||
title=work.comic.title,
|
||||
completed=work.comic.completed
|
||||
)
|
||||
comic_works_map[worktype_id].comics.append(comic)
|
||||
else:
|
||||
comic_works_map[worktype_id] = ArtistWorktypeComicResponse(
|
||||
worktype=WorktypeResponse(id=worktype_id, name=work.work_type.name),
|
||||
comics=[ComicResponse(id=work.comic.id, title=work.comic.title, completed=work.comic.completed)]
|
||||
)
|
||||
for value in comic_works_map.values():
|
||||
comic_works.append(value)
|
||||
issue_works: List[ArtistWorktypeIssueResponse] = []
|
||||
response = ArtistDetailResponse(
|
||||
id=artist.id,
|
||||
name=str(artist.name),
|
||||
weblink=str(artist.weblink),
|
||||
comic_works=comic_works,
|
||||
issue_works=issue_works,
|
||||
)
|
||||
return response
|
||||
|
||||
def update_artist(add_artist: AddArtist, artist_id: str, db: Session) -> Optional[Artist]:
|
||||
artist: Optional[Artist] = db.get(Artist, artist_id)
|
||||
if artist is not None:
|
||||
artist.name = add_artist.name
|
||||
db.add(artist)
|
||||
db.commit()
|
||||
db.refresh(artist)
|
||||
return artist
|
||||
@@ -0,0 +1,69 @@
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.comic import Comic, Issue
|
||||
from kontor_model.schema.comics.artist import artist_to_response
|
||||
from kontor_model.schema.comics.comic import ComicSchema, comic_to_response
|
||||
from kontor_model.schema.comics.comic_details import ComicDetailsResponse, ComicWorktypeArtistResponse
|
||||
from kontor_model.schema.comics.issue import IssueResponse, issue_to_response
|
||||
from kontor_model.schema.comics.issue_details import IssueDetailsResponse
|
||||
from kontor_model.schema.comics.publisher import publisher_to_response
|
||||
from kontor_model.schema.comics.volume import VolumeResponse, volume_to_response
|
||||
from kontor_model.schema.comics.worktype import worktype_to_response
|
||||
|
||||
|
||||
def get_issue_details(issue: Issue) -> IssueDetailsResponse:
|
||||
volume = None
|
||||
if issue.volume:
|
||||
volume = volume_to_response(issue.volume)
|
||||
response = IssueDetailsResponse(
|
||||
id=issue.id,
|
||||
issue_number=str(issue.issue_number),
|
||||
in_stock=bool(issue.in_stock),
|
||||
is_read=bool(issue.is_read),
|
||||
comic=comic_to_response(issue.comic),
|
||||
volume=volume
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def update_comic(new_comic: ComicSchema, comic_id: str, db: Session) -> Optional[Comic]:
|
||||
comic: Optional[Comic] = db.get(Comic, comic_id)
|
||||
return comic
|
||||
|
||||
def get_comic_details(comic: Comic) -> ComicDetailsResponse:
|
||||
volumes: List[VolumeResponse] = []
|
||||
for volume in comic.volumes:
|
||||
volumes.append(volume_to_response(volume))
|
||||
issues: List[IssueResponse] = []
|
||||
for issue in comic.issues:
|
||||
issues.append(issue_to_response(issue))
|
||||
works: List[ComicWorktypeArtistResponse] = []
|
||||
works_map: Dict[str, ComicWorktypeArtistResponse] = {}
|
||||
for work in comic.comic_works:
|
||||
worktype_id = work.work_type.id
|
||||
if worktype_id in works_map:
|
||||
artist = artist_to_response(work.artist)
|
||||
works_map[worktype_id].artists.append(artist)
|
||||
print(f"add artist to response map: {artist} -> {works_map}")
|
||||
else:
|
||||
works_map[worktype_id] = ComicWorktypeArtistResponse(
|
||||
worktype=worktype_to_response(work.work_type),
|
||||
artists=[artist_to_response(work.artist)]
|
||||
)
|
||||
for value in works_map.values():
|
||||
works.append(value)
|
||||
response = ComicDetailsResponse(
|
||||
id=str(comic.id),
|
||||
created=str(comic.created_date),
|
||||
title=str(comic.title),
|
||||
completed=bool(comic.completed),
|
||||
current_order=bool(comic.current_order),
|
||||
weblink=str(comic.weblink),
|
||||
publisher=publisher_to_response(comic.publisher),
|
||||
issues=issues,
|
||||
volumes=volumes,
|
||||
works=works
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,52 @@
|
||||
from typing import List
|
||||
|
||||
from kontor_model.db.models.comic import Publisher
|
||||
from kontor_model.schema.comics.comic import ComicResponse
|
||||
from kontor_model.schema.comics.publisher import PublisherResponse
|
||||
from kontor_model.schema.comics.publisher_details import PublisherDetailsResponse
|
||||
|
||||
|
||||
def get_publisher_details(publisher: Publisher) -> PublisherDetailsResponse:
|
||||
imprints: List[PublisherResponse] = []
|
||||
for imprint in publisher.imprints:
|
||||
imprints.append(
|
||||
PublisherResponse(
|
||||
id=imprint.id,
|
||||
created_date=imprint.created_date,
|
||||
last_modified_date=imprint.last_modified_date,
|
||||
version=imprint.version,
|
||||
weblink=str(imprint.weblink),
|
||||
parent_publisher_id=imprint.parent_publisher_id,
|
||||
name=str(imprint.name)
|
||||
)
|
||||
)
|
||||
comics: List[ComicResponse] = []
|
||||
for comic in publisher.comics:
|
||||
comics.append(
|
||||
ComicResponse(
|
||||
id=comic.id,
|
||||
created_date=comic.created_date,
|
||||
last_modified_date=comic.last_modified_date,
|
||||
version=comic.version,
|
||||
publisher_id=comic.publisher_id,
|
||||
current_order=comic.current_order,
|
||||
weblink=comic.weblink,
|
||||
title=comic.title,
|
||||
completed=comic.completed
|
||||
)
|
||||
)
|
||||
parent_publisher: PublisherResponse | None = None
|
||||
if publisher.parent_publisher:
|
||||
parent_publisher = PublisherResponse(
|
||||
id=publisher.parent_publisher.id,
|
||||
created_date=publisher.parent_publisher.created_date,
|
||||
last_modified_date=publisher.parent_publisher.last_modified_date,
|
||||
version=publisher.parent_publisher.version,#
|
||||
weblink=str(publisher.parent_publisher.weblink),
|
||||
parent_publisher_id=publisher.parent_publisher.parent_publisher_id,
|
||||
name=str(publisher.parent_publisher.name)
|
||||
)
|
||||
response: PublisherDetailsResponse = PublisherDetailsResponse(
|
||||
id=publisher.id, name=str(publisher.name), parent_publisher=parent_publisher, imprints=imprints, comics=comics
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,30 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import AnyStr, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.comic import WorkType
|
||||
from kontor_model.schema.comics.worktype import AddWorkType
|
||||
|
||||
|
||||
def create_new_worktype(work: AddWorkType, db: Session) -> WorkType:
|
||||
worktype = WorkType()
|
||||
worktype.id = str(uuid.uuid4())
|
||||
worktype.created_date = datetime.now()
|
||||
worktype.last_modified_date = datetime.now()
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
return worktype
|
||||
|
||||
|
||||
def update_worktype(work: AddWorkType, worktype_id: AnyStr, db: Session) -> Optional[WorkType]:
|
||||
worktype: Optional[WorkType] = db.get(WorkType, worktype_id)
|
||||
if worktype is not None:
|
||||
worktype.name = work.worktype
|
||||
db.add(worktype)
|
||||
db.commit()
|
||||
db.refresh(worktype)
|
||||
return worktype
|
||||
@@ -0,0 +1,65 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.media import MediaActor
|
||||
from kontor_model.db.repository.media.actorfile import delete_mediaactorfile
|
||||
from kontor_model.schema.media.actor import MediaActorModel
|
||||
|
||||
|
||||
def create_new_mediaactor(new_actor: MediaActorModel, db: Session) -> MediaActor:
|
||||
print(f"create MediaActor with url {new_actor.url}")
|
||||
media_actor: MediaActor = MediaActor()
|
||||
media_actor.id = str(uuid.uuid4())
|
||||
if new_actor.name is not None:
|
||||
media_actor.name = new_actor.name
|
||||
media_actor.url = new_actor.url
|
||||
media_actor.created_date = datetime.now()
|
||||
media_actor.last_modified_date = datetime.now()
|
||||
media_actor.version = 0
|
||||
db.add(media_actor)
|
||||
db.commit()
|
||||
db.refresh(media_actor)
|
||||
print(f"created {media_actor}")
|
||||
return media_actor
|
||||
|
||||
def delete_mediaactor(db: Session, actor_id: str):
|
||||
print(f"delete MediaActor with id {actor_id}")
|
||||
media_actor = db.get(MediaActor, actor_id)
|
||||
if media_actor is not None:
|
||||
actor_files = media_actor.media_actor_files
|
||||
for actor_file in actor_files:
|
||||
delete_mediaactorfile(db, actorfile_id=actor_file.id)
|
||||
db.refresh(media_actor)
|
||||
db.delete(media_actor)
|
||||
db.commit()
|
||||
|
||||
def import_mediaactor(db: Session, new_actor: MediaActorModel) -> MediaActor:
|
||||
"""
|
||||
import MediaFile and set missing values with default ones.
|
||||
"""
|
||||
print("import MediaActor with %s", new_actor)
|
||||
media_actor: MediaActor = MediaActor()
|
||||
media_actor.id = new_actor.id
|
||||
if new_actor.created_date:
|
||||
media_actor.created_date = new_actor.created_date
|
||||
else:
|
||||
media_actor.created_date = datetime.now()
|
||||
if new_actor.last_modified_date:
|
||||
media_actor.last_modified_date = new_actor.last_modified_date
|
||||
else:
|
||||
media_actor.last_modified_date = datetime.now()
|
||||
media_actor.version = new_actor.version
|
||||
if new_actor.name:
|
||||
media_actor.name = new_actor.name
|
||||
else:
|
||||
media_actor.name = ""
|
||||
if new_actor.url:
|
||||
media_actor.url = new_actor.url
|
||||
else:
|
||||
media_actor.url = ""
|
||||
db.add(media_actor)
|
||||
db.commit()
|
||||
db.refresh(media_actor)
|
||||
return media_actor
|
||||
@@ -0,0 +1,63 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.media import MediaActorFile
|
||||
from kontor_model.schema.media.actorfile import MediaActorFileModel
|
||||
|
||||
|
||||
def create_new_mediaactorfile(
|
||||
db: Session, actor_id: str, file_id: str
|
||||
) -> MediaActorFile:
|
||||
"""
|
||||
Create relation for MediaFile and MediaActor
|
||||
"""
|
||||
print("create MediaActorFile with actor %s and file %s", actor_id, file_id)
|
||||
media_actor_file: MediaActorFile = MediaActorFile()
|
||||
media_actor_file.id = str(uuid.uuid4())
|
||||
media_actor_file.created_date = datetime.now()
|
||||
media_actor_file.last_modified_date = datetime.now()
|
||||
media_actor_file.version = 0
|
||||
media_actor_file.media_actor_id = actor_id
|
||||
media_actor_file.media_file_id = file_id
|
||||
db.add(media_actor_file)
|
||||
db.commit()
|
||||
db.refresh(media_actor_file)
|
||||
return media_actor_file
|
||||
|
||||
|
||||
def delete_mediaactorfile(db: Session, actorfile_id: str):
|
||||
"""
|
||||
Delete relation between MediaFile and MediaActor.
|
||||
"""
|
||||
print("delete MediaActorFile with id %s", actorfile_id)
|
||||
media_actorfile = db.get(MediaActorFile, actorfile_id)
|
||||
db.delete(media_actorfile)
|
||||
db.commit()
|
||||
|
||||
|
||||
def import_mediaactorfile(
|
||||
db: Session, new_actorfile: MediaActorFileModel
|
||||
) -> MediaActorFile:
|
||||
"""
|
||||
Import MediaFile and set missing values with default ones.
|
||||
"""
|
||||
print("import MediaActorFile with %s", new_actorfile)
|
||||
media_actor_file: MediaActorFile = MediaActorFile()
|
||||
media_actor_file.id = new_actorfile.id
|
||||
if new_actorfile.created_date:
|
||||
media_actor_file.created_date = new_actorfile.created_date
|
||||
else:
|
||||
media_actor_file.created_date = datetime.now()
|
||||
if new_actorfile.last_modified_date:
|
||||
media_actor_file.last_modified_date = new_actorfile.last_modified_date
|
||||
else:
|
||||
media_actor_file.last_modified_date = datetime.now()
|
||||
media_actor_file.version = new_actorfile.version
|
||||
media_actor_file.media_actor_id = new_actorfile.media_actor_id
|
||||
media_actor_file.media_file_id = new_actorfile.media_file_id
|
||||
db.add(media_actor_file)
|
||||
db.commit()
|
||||
db.refresh(media_actor_file)
|
||||
return media_actor_file
|
||||
@@ -0,0 +1,77 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.media import MediaFile
|
||||
from kontor_model.schema.media.file import MediaFileModel
|
||||
|
||||
|
||||
def create_new_mediafile(link: str, db: Session) -> MediaFile:
|
||||
"""
|
||||
Create MediaFile with gievne URL.
|
||||
"""
|
||||
print("create MediaFile with url {link}")
|
||||
media_file: MediaFile = MediaFile()
|
||||
media_file.id = str(uuid.uuid4())
|
||||
media_file.url = link
|
||||
media_file.created_date = datetime.now()
|
||||
media_file.last_modified_date = datetime.now()
|
||||
media_file.version = 0
|
||||
media_file.review = True
|
||||
media_file.should_download = True
|
||||
db.add(media_file)
|
||||
db.commit()
|
||||
db.refresh(media_file)
|
||||
print("created %s", media_file)
|
||||
return media_file
|
||||
|
||||
|
||||
def delete_mediafile(db: Session, media_file_id: str):
|
||||
"""
|
||||
Delete MediaFile with given ID from db.
|
||||
"""
|
||||
print("delete MediaFile with id %s", media_file_id)
|
||||
media_file = db.get(MediaFile, media_file_id)
|
||||
db.delete(media_file)
|
||||
db.commit()
|
||||
|
||||
|
||||
def import_mediafile(db: Session, new_file: MediaFileModel) -> MediaFile:
|
||||
"""
|
||||
import MediaActor and set missing values with defautl ones.
|
||||
"""
|
||||
print("import MediaFile with %s", new_file)
|
||||
media_file: MediaFile = MediaFile()
|
||||
media_file.id = new_file.id
|
||||
if new_file.created_date:
|
||||
media_file.created_date = new_file.created_date
|
||||
else:
|
||||
media_file.created_date = datetime.now()
|
||||
if new_file.last_modified_date:
|
||||
media_file.last_modified_date = new_file.last_modified_date
|
||||
else:
|
||||
media_file.last_modified_date = datetime.now()
|
||||
media_file.version = new_file.version
|
||||
if new_file.title:
|
||||
media_file.title = new_file.title
|
||||
else:
|
||||
media_file.title = ""
|
||||
if new_file.file_name:
|
||||
media_file.file_name = new_file.file_name
|
||||
else:
|
||||
media_file.file_name = ""
|
||||
if new_file.cloud_link:
|
||||
media_file.cloud_link = new_file.cloud_link
|
||||
else:
|
||||
media_file.cloud_link = ""
|
||||
if new_file.url:
|
||||
media_file.url = new_file.url
|
||||
else:
|
||||
media_file.url = ""
|
||||
media_file.review = new_file.review
|
||||
media_file.should_download = new_file.should_download
|
||||
db.add(media_file)
|
||||
db.commit()
|
||||
db.refresh(media_file)
|
||||
return media_file
|
||||
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.media import MediaLofi
|
||||
|
||||
|
||||
def create_new_lofi(url: str, db: Session) -> MediaLofi:
|
||||
print(url)
|
||||
media_lofi = MediaLofi()
|
||||
media_lofi.id = str(uuid.uuid4())
|
||||
media_lofi.url = url
|
||||
media_lofi.created_date = datetime.now()
|
||||
media_lofi.last_modified_date = datetime.now()
|
||||
media_lofi.review = True
|
||||
media_lofi.should_download = False
|
||||
db.add(media_lofi)
|
||||
db.commit()
|
||||
db.refresh(media_lofi)
|
||||
print(media_lofi)
|
||||
return media_lofi
|
||||
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.db.models.media import MediaVideo
|
||||
|
||||
|
||||
def create_new_video(url: str, db: Session) -> MediaVideo:
|
||||
print(url)
|
||||
media_video = MediaVideo()
|
||||
media_video.id = str(uuid.uuid4())
|
||||
media_video.url = url
|
||||
media_video.created_date = datetime.now()
|
||||
media_video.last_modified_date = datetime.now()
|
||||
media_video.review = True
|
||||
media_video.should_download = True
|
||||
db.add(media_video)
|
||||
db.commit()
|
||||
db.refresh(media_video)
|
||||
print(media_video)
|
||||
return media_video
|
||||
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
import uuid
|
||||
from kontor_model.db.models.admin import Assignment, Profile
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from kontor_model.schema.user.profile import ProfileModel
|
||||
|
||||
|
||||
def create_new_profile(new_profile: ProfileModel, db: Session) -> Profile:
|
||||
print(f"create Profile with username {new_profile.username}")
|
||||
profile: Profile = Profile()
|
||||
profile.id = str(uuid.uuid4())
|
||||
profile.user_name = new_profile.username
|
||||
profile.first_name = new_profile.first_name
|
||||
profile.last_name = new_profile.last_name
|
||||
profile.created_date = datetime.now()
|
||||
profile.last_modified_date = datetime.now()
|
||||
profile.version = 0
|
||||
db.add(profile)
|
||||
db.commit()
|
||||
db.refresh(profile)
|
||||
print(f"created {profile}")
|
||||
return profile
|
||||
|
||||
def delete_profile(db: Session, profile_id: str):
|
||||
print(f"delete Profile with id {profile_id}")
|
||||
profile: Optional[Profile] = db.get(Profile, profile_id)
|
||||
if profile is not None:
|
||||
assignments = profile.assignments
|
||||
for assignment in assignments:
|
||||
delete_assignment(db, assignment.id)
|
||||
db.delete(profile)
|
||||
db.commit()
|
||||
|
||||
def delete_assignment(db: Session, assignment_id: str) -> None:
|
||||
print(f"delete Assignment with id {assignment_id}")
|
||||
assignment: Optional[Assignment] = db.get(Assignment, assignment_id)
|
||||
if assignment is not None:
|
||||
db.delete(assignment)
|
||||
db.commit()
|
||||
@@ -0,0 +1,9 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class HealthCheck(BaseModel):
|
||||
"""
|
||||
Health check model
|
||||
"""
|
||||
|
||||
status: str = "ok"
|
||||
@@ -0,0 +1,8 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
email: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
@@ -0,0 +1,34 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.admin import MailAccount
|
||||
|
||||
|
||||
class MailAccountResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
host: str
|
||||
port: int
|
||||
protocol: str
|
||||
user_name: str
|
||||
password: str
|
||||
start_tls: bool
|
||||
|
||||
|
||||
def to_response(account: MailAccount) -> MailAccountResponse:
|
||||
response: MailAccountResponse = MailAccountResponse(
|
||||
id=account.id,
|
||||
created_date=account.created_date,
|
||||
last_modified_date=account.last_modified_date,
|
||||
version=account.version,
|
||||
host=str(account.host),
|
||||
port=account.port,
|
||||
protocol=str(account.protocol),
|
||||
user_name=str(account.user_name),
|
||||
password=str(account.password),
|
||||
start_tls=bool(account.start_tls),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,13 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
|
||||
|
||||
class TokenData(BaseModel):
|
||||
username: Optional[str] = None
|
||||
scopes: List[str] = []
|
||||
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import Article
|
||||
|
||||
|
||||
class ArticleResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
title: str
|
||||
|
||||
def to_response(article: Article) -> ArticleResponse:
|
||||
response: ArticleResponse = ArticleResponse(
|
||||
id=article.id,
|
||||
created_date=article.created_date,
|
||||
last_modified_date=article.last_modified_date,
|
||||
version=article.version,
|
||||
title=str(article.title)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import ArticleAuthor
|
||||
|
||||
|
||||
class ArticleAuthorResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
article_id: str
|
||||
author_id: str
|
||||
|
||||
def to_response(articleauthor: ArticleAuthor) -> ArticleAuthorResponse:
|
||||
response: ArticleAuthorResponse = ArticleAuthorResponse(
|
||||
id=articleauthor.id,
|
||||
created_date=articleauthor.created_date,
|
||||
last_modified_date=articleauthor.last_modified_date,
|
||||
version=articleauthor.version,
|
||||
article_id=str(articleauthor.article_id),
|
||||
author_id=str(articleauthor.author_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import Author
|
||||
|
||||
|
||||
class AuthorResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
first_name: str
|
||||
last_name: str
|
||||
|
||||
def to_response(author: Author) -> AuthorResponse:
|
||||
response: AuthorResponse = AuthorResponse(
|
||||
id=author.id,
|
||||
created_date=author.created_date,
|
||||
last_modified_date=author.last_modified_date,
|
||||
version=author.version,
|
||||
first_name=str(author.first_name),
|
||||
last_name=str(author.last_name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,29 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import Book
|
||||
|
||||
|
||||
class BookResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
isbn: str
|
||||
title: str
|
||||
year: int
|
||||
publisher_id: str
|
||||
|
||||
def to_response(book: Book) -> BookResponse:
|
||||
response: BookResponse = BookResponse(
|
||||
id=book.id,
|
||||
created_date=book.created_date,
|
||||
last_modified_date=book.last_modified_date,
|
||||
version=book.version,
|
||||
isbn=str(book.isbn),
|
||||
title=str(book.title),
|
||||
year=book.year,
|
||||
publisher_id=str(book.publisher_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import BookAuthor
|
||||
|
||||
|
||||
class BookAuthorResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
author_id: str
|
||||
book_id: str
|
||||
|
||||
def to_response(bookauthor: BookAuthor) -> BookAuthorResponse:
|
||||
response: BookAuthorResponse = BookAuthorResponse(
|
||||
id=bookauthor.id,
|
||||
created_date=bookauthor.created_date,
|
||||
last_modified_date=bookauthor.last_modified_date,
|
||||
version=bookauthor.version,
|
||||
author_id=str(bookauthor.author_id),
|
||||
book_id=str(bookauthor.book_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.bookshelf import BookshelfPublisher
|
||||
|
||||
|
||||
class PublisherResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
|
||||
def to_response(publisher: BookshelfPublisher) -> PublisherResponse:
|
||||
response: PublisherResponse = PublisherResponse(
|
||||
id=publisher.id,
|
||||
created_date=publisher.created_date,
|
||||
last_modified_date=publisher.last_modified_date,
|
||||
version=publisher.version,
|
||||
name=str(publisher.name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,35 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import Artist
|
||||
|
||||
|
||||
class ArtistCreation(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
|
||||
class ArtistResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
weblink: Optional[str]
|
||||
|
||||
def artist_to_response(artist: Artist) -> ArtistResponse:
|
||||
response: ArtistResponse = ArtistResponse(
|
||||
id=artist.id,
|
||||
created_date=artist.created_date,
|
||||
last_modified_date=artist.last_modified_date,
|
||||
version=artist.version,
|
||||
name=artist.name,
|
||||
weblink=artist.weblink
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
class AddArtist(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
@@ -0,0 +1,22 @@
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.schema.comics.comic import ComicResponse
|
||||
from kontor_model.schema.comics.issue_details import IssueDetailsResponse
|
||||
from kontor_model.schema.comics.worktype import WorktypeResponse
|
||||
|
||||
|
||||
class ArtistWorktypeComicResponse(BaseModel):
|
||||
worktype: WorktypeResponse
|
||||
comics: List[ComicResponse]
|
||||
|
||||
class ArtistWorktypeIssueResponse(BaseModel):
|
||||
worktype: WorktypeResponse
|
||||
issues: List[IssueDetailsResponse]
|
||||
|
||||
class ArtistDetailResponse(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
weblink: str
|
||||
comic_works: List[ArtistWorktypeComicResponse]
|
||||
issue_works: List[ArtistWorktypeIssueResponse]
|
||||
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Schema definitions for Comics.
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, AnyUrl
|
||||
|
||||
from kontor_model.db.models.comic import Comic
|
||||
|
||||
|
||||
class ComicResponse(BaseModel):
|
||||
"""
|
||||
Pydantic model for returning Comic objects.
|
||||
"""
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
title: str
|
||||
publisher_id: str
|
||||
current_order: bool
|
||||
completed: bool
|
||||
weblink: Optional[str]
|
||||
|
||||
def comic_to_response(comic: Comic) -> ComicResponse:
|
||||
response: ComicResponse = ComicResponse(
|
||||
id=comic.id,
|
||||
created_date=comic.created_date,
|
||||
last_modified_date=comic.last_modified_date,
|
||||
version=comic.version,
|
||||
title=str(comic.title),
|
||||
publisher_id=str(comic.publisher_id),
|
||||
current_order=bool(comic.current_order),
|
||||
completed=bool(comic.completed),
|
||||
weblink=str(comic.weblink)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
class ComicSchema(BaseModel):
|
||||
"""
|
||||
Pydantic model for uploading Comic object.
|
||||
"""
|
||||
id: str
|
||||
title: str
|
||||
weblink: Optional[AnyUrl]
|
||||
completed: Optional[bool]
|
||||
current_order: Optional[bool]
|
||||
@@ -0,0 +1,26 @@
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.schema.comics.artist import ArtistResponse
|
||||
from kontor_model.schema.comics.issue import IssueResponse
|
||||
from kontor_model.schema.comics.publisher import PublisherResponse
|
||||
from kontor_model.schema.comics.volume import VolumeResponse
|
||||
from kontor_model.schema.comics.worktype import WorktypeResponse
|
||||
|
||||
|
||||
class ComicWorktypeArtistResponse(BaseModel):
|
||||
worktype: WorktypeResponse
|
||||
artists: List[ArtistResponse]
|
||||
|
||||
|
||||
class ComicDetailsResponse(BaseModel):
|
||||
id: str
|
||||
created: str
|
||||
title: str
|
||||
completed : bool
|
||||
current_order : bool
|
||||
weblink: str
|
||||
publisher: PublisherResponse
|
||||
issues: List[IssueResponse]
|
||||
volumes: List[VolumeResponse]
|
||||
works: List[ComicWorktypeArtistResponse]
|
||||
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Model definitions for ComicWork.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import ComicWork
|
||||
|
||||
|
||||
class ComicWorkResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
comic_id: str
|
||||
artist_id: str
|
||||
work_type_id: str
|
||||
|
||||
|
||||
def comicwork_to_response(comicwork: ComicWork) -> ComicWorkResponse:
|
||||
response: ComicWorkResponse = ComicWorkResponse(
|
||||
id=comicwork.id,
|
||||
created_date=comicwork.created_date,
|
||||
last_modified_date=comicwork.last_modified_date,
|
||||
version=comicwork.version,
|
||||
comic_id=str(comicwork.comic_id),
|
||||
artist_id=str(comicwork.artist_id),
|
||||
work_type_id=str(comicwork.work_type_id),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,38 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import Issue
|
||||
|
||||
|
||||
class IssueResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
issue_number: str
|
||||
title: Optional[str]
|
||||
published_on: Optional[datetime]
|
||||
in_stock: bool
|
||||
is_read: bool
|
||||
comic_id: str
|
||||
volume_id: Optional[str]
|
||||
story_arc_id: Optional[str]
|
||||
|
||||
def issue_to_response(issue: Issue) -> IssueResponse:
|
||||
response: IssueResponse = IssueResponse(
|
||||
id=issue.id,
|
||||
created_date=issue.created_date,
|
||||
last_modified_date=issue.last_modified_date,
|
||||
version=issue.version,
|
||||
issue_number=str(issue.issue_number),
|
||||
title=str(issue.title),
|
||||
published_on=issue.published_on,
|
||||
in_stock=bool(issue.in_stock),
|
||||
is_read=bool(issue.is_read),
|
||||
comic_id=str(issue.comic_id),
|
||||
volume_id=str(issue.volume_id),
|
||||
story_arc_id=str(issue.story_arc_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,14 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.schema.comics.comic import ComicResponse
|
||||
from kontor_model.schema.comics.volume import VolumeResponse
|
||||
|
||||
|
||||
class IssueDetailsResponse(BaseModel):
|
||||
id: str
|
||||
issue_number: str
|
||||
in_stock: bool
|
||||
is_read: bool
|
||||
comic: ComicResponse
|
||||
volume: VolumeResponse | None
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Model definitions for IssueWork.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import IssueWork
|
||||
|
||||
|
||||
class IssueWorkResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
issue_id: str
|
||||
artist_id: str
|
||||
work_type_id: str
|
||||
|
||||
|
||||
def issuework_to_response(issuework: IssueWork) -> IssueWorkResponse:
|
||||
response: IssueWorkResponse = IssueWorkResponse(
|
||||
id=issuework.id,
|
||||
created_date=issuework.created_date,
|
||||
last_modified_date=issuework.last_modified_date,
|
||||
version=issuework.version,
|
||||
issue_id=str(issuework.issue_id),
|
||||
artist_id=str(issuework.artist_id),
|
||||
work_type_id=str(issuework.work_type_id),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import Publisher
|
||||
|
||||
|
||||
class PublisherResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
weblink: Optional[str]
|
||||
parent_publisher_id: Optional[str]
|
||||
|
||||
|
||||
def publisher_to_response(publisher: Publisher) -> PublisherResponse:
|
||||
response: PublisherResponse = PublisherResponse(
|
||||
id=publisher.id,
|
||||
created_date=publisher.created_date,
|
||||
last_modified_date=publisher.last_modified_date,
|
||||
version=publisher.version,
|
||||
name=str(publisher.name),
|
||||
weblink=str(publisher.weblink),
|
||||
parent_publisher_id=publisher.parent_publisher_id
|
||||
)
|
||||
return response
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.schema.comics.comic import ComicResponse
|
||||
from kontor_model.schema.comics.publisher import PublisherResponse
|
||||
|
||||
|
||||
class PublisherDetailsResponse(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
parent_publisher: PublisherResponse | None
|
||||
imprints: List[PublisherResponse]
|
||||
comics: List[ComicResponse]
|
||||
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import StoryArc
|
||||
|
||||
class StoryArcResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
comic_id: str
|
||||
volume_id: Optional[str]
|
||||
|
||||
class AddLink(BaseModel):
|
||||
url: str
|
||||
|
||||
def storyarc_to_response(storyarc: StoryArc) -> StoryArcResponse:
|
||||
response: StoryArcResponse = StoryArcResponse(
|
||||
id=storyarc.id,
|
||||
created_date=storyarc.created_date,
|
||||
last_modified_date=storyarc.last_modified_date,
|
||||
version=storyarc.version,
|
||||
name=str(storyarc.name),
|
||||
comic_id=str(storyarc.comic_id),
|
||||
volume_id=str(storyarc.volume_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import Volume
|
||||
|
||||
|
||||
class VolumeResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
comic_id: str
|
||||
|
||||
def volume_to_response(volume: Volume) -> VolumeResponse:
|
||||
response: VolumeResponse = VolumeResponse(
|
||||
id=volume.id,
|
||||
created_date=volume.created_date,
|
||||
last_modified_date=volume.last_modified_date,
|
||||
version=volume.version,
|
||||
name=str(volume.name),
|
||||
comic_id=str(volume.comic_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,26 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.comic import WorkType
|
||||
|
||||
class AddWorkType(BaseModel):
|
||||
worktype: str
|
||||
|
||||
class WorktypeResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
|
||||
|
||||
def worktype_to_response(worktype: WorkType) -> WorktypeResponse:
|
||||
response: WorktypeResponse = WorktypeResponse(
|
||||
id=worktype.id,
|
||||
created_date=worktype.created_date,
|
||||
last_modified_date=worktype.last_modified_date,
|
||||
version=worktype.version,
|
||||
name=str(worktype.name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,34 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.media import MediaActor
|
||||
|
||||
|
||||
class MediaActorResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: Optional[str]
|
||||
url: Optional[str]
|
||||
|
||||
def actor_to_response(actor: MediaActor) -> MediaActorResponse:
|
||||
response: MediaActorResponse = MediaActorResponse(
|
||||
id=actor.id,
|
||||
created_date=actor.created_date,
|
||||
last_modified_date=actor.last_modified_date,
|
||||
version=actor.version,
|
||||
name=str(actor.name),
|
||||
url=str(actor.url)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
class MediaActorModel(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: Optional[str]
|
||||
url: Optional[str]
|
||||
@@ -0,0 +1,35 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from kontor_model.db.models.media import MediaActorFile
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class MediaActorFileResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
media_actor_id: str
|
||||
media_file_id: Optional[str]
|
||||
|
||||
def actorfile_to_response(actorfile: MediaActorFile) -> MediaActorFileResponse:
|
||||
response: MediaActorFileResponse = MediaActorFileResponse(
|
||||
id=actorfile.id,
|
||||
created_date=actorfile.created_date,
|
||||
last_modified_date=actorfile.last_modified_date,
|
||||
version=actorfile.version,
|
||||
media_actor_id=str(actorfile.media_actor_id),
|
||||
media_file_id=str(actorfile.media_file_id)
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
class MediaActorFileModel(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
media_actor_id: str
|
||||
media_file_id: Optional[str]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.media import MediaArticle
|
||||
|
||||
class MediaArticleResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
review: bool = False
|
||||
title: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
|
||||
class AddLink(BaseModel):
|
||||
url: str
|
||||
|
||||
def to_response(video: MediaArticle) -> MediaArticleResponse:
|
||||
response: MediaArticleResponse = MediaArticleResponse(
|
||||
id=video.id,
|
||||
created_date=video.created_date,
|
||||
last_modified_date=video.last_modified_date,
|
||||
version=video.version,
|
||||
review=bool(video.review),
|
||||
title=str(video.title),
|
||||
url=str(video.url),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,81 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from kontor_model.db.models.media import MediaFile
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class MediaFileResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
title: Optional[str]
|
||||
file_name: Optional[str]
|
||||
cloud_link: Optional[str]
|
||||
url: Optional[str]
|
||||
review: bool = False
|
||||
should_download: bool = False
|
||||
|
||||
|
||||
def file_to_response(mediafile: MediaFile) -> MediaFileResponse:
|
||||
"""
|
||||
Create MediaFileResponse from model.
|
||||
"""
|
||||
response: MediaFileResponse = MediaFileResponse(
|
||||
id=mediafile.id,
|
||||
created_date=mediafile.created_date,
|
||||
last_modified_date=mediafile.last_modified_date,
|
||||
version=mediafile.version,
|
||||
title=mediafile.title,
|
||||
file_name=mediafile.file_name,
|
||||
cloud_link=mediafile.cloud_link,
|
||||
url=mediafile.url,
|
||||
review=mediafile.review,
|
||||
should_download=mediafile.should_download,
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def file_to_model(model: MediaFileResponse, mediafile: MediaFile) -> MediaFile:
|
||||
"""
|
||||
Set data of response to model.
|
||||
"""
|
||||
mediafile.file_name = model.file_name
|
||||
mediafile.cloud_link = model.cloud_link
|
||||
if model.url is not None:
|
||||
mediafile.url = model.url
|
||||
else:
|
||||
mediafile.url = ""
|
||||
if model.title is not None:
|
||||
mediafile.title = model.title
|
||||
else:
|
||||
mediafile.title = ""
|
||||
mediafile.last_modified_date = datetime.now()
|
||||
mediafile.review = model.review
|
||||
mediafile.should_download = model.should_download
|
||||
return mediafile
|
||||
|
||||
|
||||
class MediaFileModel(BaseModel):
|
||||
"""
|
||||
Pydantic model to import MediaFile.
|
||||
"""
|
||||
id: str
|
||||
created_date: Optional[datetime]
|
||||
last_modified_date: Optional[datetime]
|
||||
version: int = 0
|
||||
title: Optional[str]
|
||||
file_name: Optional[str]
|
||||
cloud_link: Optional[str]
|
||||
url: Optional[str]
|
||||
review: bool = True
|
||||
should_download: bool = True
|
||||
|
||||
|
||||
class Link(BaseModel):
|
||||
"""
|
||||
PYdantic model for uploading url.
|
||||
"""
|
||||
|
||||
url: str
|
||||
@@ -0,0 +1,33 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.media import MediaLofi
|
||||
|
||||
class MediaLofiResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
file_name: str = ""
|
||||
review: bool = False
|
||||
should_download: bool = False
|
||||
title: str = ""
|
||||
url: str = ""
|
||||
|
||||
class AddLofi(BaseModel):
|
||||
url: str
|
||||
|
||||
def lofi_to_response(lofi: MediaLofi) -> MediaLofiResponse:
|
||||
response: MediaLofiResponse = MediaLofiResponse(
|
||||
id=lofi.id,
|
||||
created_date=lofi.created_date,
|
||||
last_modified_date=lofi.last_modified_date,
|
||||
version=lofi.version,
|
||||
file_name=str(lofi.file_name),
|
||||
review=bool(lofi.review),
|
||||
should_download=bool(lofi.should_download),
|
||||
title=str(lofi.title),
|
||||
url=str(lofi.url),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,38 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.media import MediaVideo
|
||||
|
||||
class MediaVideoResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
cloud_link: Optional[str] = None
|
||||
file_name: Optional[str] = None
|
||||
path: Optional[str] = None
|
||||
review: bool = False
|
||||
title: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
should_download: bool = False
|
||||
|
||||
class AddLink(BaseModel):
|
||||
url: str
|
||||
|
||||
def video_to_response(video: MediaVideo) -> MediaVideoResponse:
|
||||
response: MediaVideoResponse = MediaVideoResponse(
|
||||
id=video.id,
|
||||
created_date=video.created_date,
|
||||
last_modified_date=video.last_modified_date,
|
||||
version=video.version,
|
||||
cloud_link=str(video.cloud_link),
|
||||
file_name=str(video.file_name),
|
||||
path=str(video.path),
|
||||
review=bool(video.review),
|
||||
title=str(video.title),
|
||||
url=str(video.url),
|
||||
should_download=bool(video.should_download)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,31 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Card
|
||||
|
||||
|
||||
class CardResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
card_number: int
|
||||
year: int
|
||||
card_set_id: str
|
||||
rooster_id: str
|
||||
vendor_id: str
|
||||
|
||||
def to_response(card: Card) -> CardResponse:
|
||||
response: CardResponse = CardResponse(
|
||||
id=card.id,
|
||||
created_date=card.created_date,
|
||||
last_modified_date=card.last_modified_date,
|
||||
version=card.version,
|
||||
card_number=card.card_number,
|
||||
year=card.year,
|
||||
card_set_id=str(card.card_set_id),
|
||||
rooster_id=str(card.rooster_id),
|
||||
vendor_id=str(card.vendor_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import CardSet
|
||||
|
||||
|
||||
class CardSetResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
parallel_set: bool
|
||||
insert_set: bool
|
||||
vendor_id: str
|
||||
|
||||
|
||||
def to_response(cardset: CardSet) -> CardSetResponse:
|
||||
response: CardSetResponse = CardSetResponse(
|
||||
id=cardset.id,
|
||||
created_date=cardset.created_date,
|
||||
last_modified_date=cardset.last_modified_date,
|
||||
version=cardset.version,
|
||||
name=str(cardset.name),
|
||||
parallel_set=bool(cardset.parallel_set),
|
||||
insert_set=bool(cardset.insert_set),
|
||||
vendor_id=str(cardset.vendor_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import FieldPosition
|
||||
|
||||
|
||||
class FieldPositionResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
short_name: str
|
||||
sport_id: str
|
||||
|
||||
|
||||
def to_response(fieldposition: FieldPosition) -> FieldPositionResponse:
|
||||
response: FieldPositionResponse = FieldPositionResponse(
|
||||
id=fieldposition.id,
|
||||
created_date=fieldposition.created_date,
|
||||
last_modified_date=fieldposition.last_modified_date,
|
||||
version=fieldposition.version,
|
||||
name=str(fieldposition.name),
|
||||
short_name=str(fieldposition.short_name),
|
||||
sport_id=str(fieldposition.sport_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Player
|
||||
|
||||
|
||||
class PlayerResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
first_name: str
|
||||
last_name: str
|
||||
|
||||
def to_response(player: Player) -> PlayerResponse:
|
||||
response: PlayerResponse = PlayerResponse(
|
||||
id=player.id,
|
||||
created_date=player.created_date,
|
||||
last_modified_date=player.last_modified_date,
|
||||
version=player.version,
|
||||
first_name=str(player.first_name),
|
||||
last_name=str(player.last_name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,36 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Rooster
|
||||
|
||||
|
||||
class RoosterResponse(BaseModel):
|
||||
"""
|
||||
Pydantic model for returning Rooster objects.
|
||||
"""
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
year: int
|
||||
team_id: str
|
||||
player_id: str
|
||||
position_id: str
|
||||
|
||||
|
||||
def to_response(rooster: Rooster) -> RoosterResponse:
|
||||
"""
|
||||
convert database object to response object (Pydantic).
|
||||
"""
|
||||
response: RoosterResponse = RoosterResponse(
|
||||
id=rooster.id,
|
||||
created_date=rooster.created_date,
|
||||
last_modified_date=rooster.last_modified_date,
|
||||
version=rooster.version,
|
||||
year=rooster.year,
|
||||
team_id=str(rooster.team_id),
|
||||
player_id=str(rooster.player_id),
|
||||
position_id=str(rooster.position_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Sport
|
||||
|
||||
|
||||
class SportResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
|
||||
|
||||
def to_response(sport: Sport) -> SportResponse:
|
||||
response: SportResponse = SportResponse(
|
||||
id=sport.id,
|
||||
created_date=sport.created_date,
|
||||
last_modified_date=sport.last_modified_date,
|
||||
version=sport.version,
|
||||
name=str(sport.name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Team
|
||||
|
||||
|
||||
class TeamResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
short_name: str
|
||||
sport_id: str
|
||||
|
||||
|
||||
def to_response(team: Team) -> TeamResponse:
|
||||
response: TeamResponse = TeamResponse(
|
||||
id=team.id,
|
||||
created_date=team.created_date,
|
||||
last_modified_date=team.last_modified_date,
|
||||
version=team.version,
|
||||
name=str(team.name),
|
||||
short_name=str(team.short_name),
|
||||
sport_id=str(team.sport_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
class and function for json response objects for Vendor.
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.tysc import Vendor
|
||||
|
||||
|
||||
class VendorResponse(BaseModel):
|
||||
"""
|
||||
Pydantic model for Vendor reponse object.
|
||||
"""
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
|
||||
def to_response(vendor: Vendor) -> VendorResponse:
|
||||
"""
|
||||
convert database object Vendor to response object VendorResponse.
|
||||
"""
|
||||
reponse: VendorResponse = VendorResponse(
|
||||
id=vendor.id,
|
||||
created_date=vendor.created_date,
|
||||
last_modified_date=vendor.last_modified_date,
|
||||
version=vendor.version,
|
||||
name=str(vendor.name)
|
||||
)
|
||||
return reponse
|
||||
@@ -0,0 +1,26 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.admin import Assignment
|
||||
|
||||
|
||||
class AssignmentResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
profile_id: str
|
||||
permission_id: str
|
||||
|
||||
|
||||
def to_response(assignment: Assignment) -> AssignmentResponse:
|
||||
response: AssignmentResponse = AssignmentResponse(
|
||||
id=assignment.id,
|
||||
created_date=assignment.created_date,
|
||||
last_modified_date=assignment.last_modified_date,
|
||||
version=assignment.version,
|
||||
profile_id=str(assignment.profile_id),
|
||||
permission_id=str(assignment.permission_id)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,24 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.admin import Permission
|
||||
|
||||
|
||||
class PermissionResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
name: str
|
||||
|
||||
|
||||
def to_response(permission: Permission) -> PermissionResponse:
|
||||
response: PermissionResponse = PermissionResponse(
|
||||
id=permission.id,
|
||||
created_date=permission.created_date,
|
||||
last_modified_date=permission.last_modified_date,
|
||||
version=permission.version,
|
||||
name=str(permission.name)
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,50 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.admin import Profile
|
||||
|
||||
|
||||
class ProfileResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
first_name: str
|
||||
last_name: str
|
||||
user_name: str
|
||||
email: str
|
||||
password: str
|
||||
enabled: bool
|
||||
|
||||
def to_response(profile: Profile) -> ProfileResponse:
|
||||
response: ProfileResponse = ProfileResponse(
|
||||
id=profile.id,
|
||||
created_date=profile.created_date,
|
||||
last_modified_date=profile.last_modified_date,
|
||||
version=profile.version,
|
||||
first_name=str(profile.first_name),
|
||||
last_name=str(profile.last_name),
|
||||
user_name=str(profile.user_name),
|
||||
email=str(profile.email),
|
||||
password=str(profile.password),
|
||||
enabled=bool(profile.enabled)
|
||||
)
|
||||
return response
|
||||
|
||||
class ProfileModel(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
active: bool
|
||||
|
||||
def to_model(profile: Profile) -> ProfileModel:
|
||||
model: ProfileModel = ProfileModel(
|
||||
username=profile.user_name,
|
||||
email=profile.email,
|
||||
first_name=profile.first_name,
|
||||
last_name=profile.last_name,
|
||||
active=profile.enabled,
|
||||
)
|
||||
return model
|
||||
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from kontor_model.db.models.admin import Token
|
||||
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
id: str
|
||||
created_date: datetime
|
||||
last_modified_date: datetime
|
||||
version: int
|
||||
token: str
|
||||
name: str
|
||||
last_used_date: datetime
|
||||
enabled: bool
|
||||
profile_id: str
|
||||
|
||||
|
||||
def to_response(token: Token) -> TokenResponse:
|
||||
response: TokenResponse = TokenResponse(
|
||||
id=token.id,
|
||||
created_date=token.created_date,
|
||||
last_modified_date=token.last_modified_date,
|
||||
version=token.version,
|
||||
token=str(token.token),
|
||||
name=str(token.name),
|
||||
last_used_date=token.last_used_date,
|
||||
enabled=bool(token.enabled),
|
||||
profile_id=str(token.profile_id)
|
||||
)
|
||||
return response
|
||||
Reference in New Issue
Block a user