Skip to content

Instantly share code, notes, and snippets.

@gidj
Last active December 9, 2019 23:37
Show Gist options
  • Save gidj/c96163931fc59ecaeaa206da4138c0bc to your computer and use it in GitHub Desktop.
Save gidj/c96163931fc59ecaeaa206da4138c0bc to your computer and use it in GitHub Desktop.
Service idea for CatalogAPI
from enum import Enum
from typing import Tuple
from pydantic import BaseModel
MAX_OBJECTS_PER_PAGE = 10
class Categories(Enum):
MUSIC = "2"
SPORTS = "3"
THEATER = "4"
class CatalogEvent(BaseModel):
# Put this in an app/services/models module
id = int
class Config:
# I think we should add this to all models that come from Catalog:
# https://pydantic-docs.helpmanual.io/usage/models/#faux-immutability
allow_mutation = False
class CatalogVenue(BaseModel):
id = int
class Config:
allow_mutation = False
class CatalogAPI(object):
async def get_events(
self,
page: int = 0,
limit: int = MAX_OBJECTS_PER_PAGE,
# We should try to expose all options to the api explictly
category_id: int = None,
venue_id: int = None,
) -> Tuple[CatalogEvent]:
# logic here for coverting the interface we expose for `get_events` to the api parameters that we need to send
# as query params to catalog-api on Vivid side; that way if they change the api, we don't have to change code
# all the way over in another module.
pass
async def get_event(self, event_id: int) -> CatalogEvent:
pass
async def get_venues(
self,
page: int = 0,
limit: int = MAX_OBJECTS_PER_PAGE,
category_id: int = None,
venue_id: int = None,
) -> Tuple[CatalogVenue]:
pass
async def get_venue(self, venue_id: int) -> CatalogVenue:
pass
# Etc
catalog = CatalogAPI()
catalog_events = catalog.get_events()
catalog_venue = catalog.get_venue(123)
# Then use these domain models in the app.api module to convert them to our "partnership" models.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment