Add publications
This commit is contained in:
parent
be71dfc7ce
commit
583a5737a6
6 changed files with 199 additions and 2 deletions
5
src/services/publications/__init__.py
Normal file
5
src/services/publications/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from .data import Publication, PublicationProfile, Order, Sequence, Entry
|
||||
from .service import PublicationService
|
||||
from .repo import PublicationRepo
|
||||
|
||||
__all__ = ['Publication', 'PublicationProfile', 'Order', 'Sequence', 'Entry', 'PublicationService', 'PublicationRepo']
|
||||
43
src/services/publications/data.py
Normal file
43
src/services/publications/data.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from datetime import timedelta
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
@dataclass
|
||||
class Entry:
|
||||
id: int
|
||||
text: str
|
||||
html: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Sequence:
|
||||
position: int
|
||||
entry: Entry
|
||||
duration: timedelta | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Order:
|
||||
id: int
|
||||
title: str
|
||||
sequence_entries: list[Sequence]
|
||||
|
||||
|
||||
@dataclass
|
||||
class PublicationProfile:
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Publication:
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
by_line: str
|
||||
orders: list[Order] = field(default_factory=list)
|
||||
|
||||
# Rather than using a subclass I think this makes sense
|
||||
def to_profile(self) -> PublicationProfile:
|
||||
return PublicationProfile(id=self.id, title=self.title, description=self.description)
|
||||
17
src/services/publications/repo.py
Normal file
17
src/services/publications/repo.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import abc
|
||||
|
||||
from .data import Publication, PublicationProfile
|
||||
|
||||
|
||||
class PublicationRepo(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
def get_publication_by_id(self, pub_id: int) -> Publication | None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_publication_profile_by_id(self, pub_id: int) -> PublicationProfile | None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_all_publications(self) -> list[PublicationProfile]:
|
||||
pass
|
||||
18
src/services/publications/service.py
Normal file
18
src/services/publications/service.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from src.services.publications.data import Publication, PublicationProfile
|
||||
from src.services.publications.repo import PublicationRepo
|
||||
|
||||
|
||||
class PublicationService:
|
||||
"""This is a bit of a shell since there's no real behavior other than lookup at this point"""
|
||||
|
||||
def __init__(self, repo: PublicationRepo):
|
||||
self._repo = repo
|
||||
|
||||
def get_publication(self, publication_id: int) -> PublicationProfile | None:
|
||||
return self._repo.get_publication_profile_by_id(publication_id)
|
||||
|
||||
def get_full_publication(self, publication_id: int) -> Publication | None:
|
||||
return self._repo.get_publication_by_id(publication_id)
|
||||
|
||||
def get_all_publications(self) -> list[PublicationProfile]:
|
||||
return self._repo.get_all_publications()
|
||||
Loading…
Add table
Add a link
Reference in a new issue