"""
byceps.services.site.service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from typing import List, Optional

from ...typing import PartyID

from .models.site import Site as DbSite
from .transfer.models import Site, SiteID


def find_site(site_id: SiteID) -> Optional[Site]:
    """Return the site with that id, or `None` if not found."""
    site = DbSite.query.get(site_id)

    if site is None:
        return None

    return _db_entity_to_site(site)


def get_sites_for_party(party_id: PartyID) -> List[Site]:
    """Return the sites for that party."""
    sites = DbSite.query \
        .filter_by(party_id=party_id) \
        .all()

    return [_db_entity_to_site(site) for site in sites]


def _db_entity_to_site(site: DbSite) -> Site:
    return Site(
        site.id,
        site.party_id,
        site.title,
    )

@@ -188,16 +188,43 @@
 tional%0A%0A
+from ...database import db%0A
 from ...
@@ -330,16 +330,262 @@
 iteID%0A%0A%0A
+def create_site(site_id: SiteID, party_id: PartyID, title: str) -%3E Site:%0A    %22%22%22Create a site for that party.%22%22%22%0A    site = DbSite(site_id, party_id, title)%0A%0A    db.session.add(site)%0A    db.session.commit()%0A%0A    return _db_entity_to_site(site)%0A%0A%0A
 def find

Add service function to create a site