Skip to content

Commit

Permalink
Add entity handlers and repositories for topics, committees, and polls
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardKruemmel authored and takahiromitsui committed Apr 17, 2024
1 parent 137343f commit efe96c2
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/service_layer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# local
from src.domain import events, commands
from src.api import repository
from src.entrypoints import redis_eventpublisher
from src.logging_config import configure_logging
from src.service_layer import utils

Expand Down Expand Up @@ -41,6 +40,26 @@ def fetch_missing_entity(command: commands.FetchMissingEntity) -> List[Any]:
"parliament-periods", repo
).fetch_missing_entities()
return missing_parliament_period_data
if command.entity == "topic":
repo = repository.SqlAlchemyFactory(command.session).create_topic_repository()
missing_topic_data = utils.FetchMissingEntity(
"topics", repo
).fetch_missing_entities()
return missing_topic_data
if command.entity == "committee":
repo = repository.SqlAlchemyFactory(
command.session
).create_committee_repository()
missing_committee_data = utils.FetchMissingEntity(
"committees", repo
).fetch_missing_entities()
return missing_committee_data
if command.entity == "poll":
repo = repository.SqlAlchemyFactory(command.session).create_poll_repository()
missing_poll_data = utils.FetchMissingEntity(
"polls", repo
).fetch_missing_entities()
return missing_poll_data
return []


Expand All @@ -57,6 +76,16 @@ def prepare_update_data(command: commands.PrepareUpdateData):
if command.entity == "parliament-period":
parliament_periods = utils.prepare_parliament_period_data(command.data)
return {"entities": ["parliament_period"], "data": [parliament_periods]}
if command.entity == "topic":
topics = utils.prepare_topic_data(command.data)
return {"entities": ["topic"], "data": [topics]}
if command.entity == "committee":
committees = utils.prepare_committee_data(command.data)
committee_has_topics = utils.prepare_committee_has_topic_data(command.data)
return {"entities": ["committee"], "data": [committees, committee_has_topics]}
if command.entity == "poll":
polls = utils.prepare_poll_data(command.data)
return {"entities": ["poll"], "data": [polls]}


# Step 3
Expand All @@ -75,6 +104,19 @@ def update_table(command: commands.UpdateTable):
if command.entities == ["parliament_period"]:
parliament_period_repo = factory.create_parliament_period_repository()
parliament_period_repo.add_or_update_list(command.data[0])
if command.entities == ["topic"]:
topic_repo = factory.create_topic_repository()
topic_repo.add_or_update_list(command.data[0])
if command.entities == ["committee"]:
committee_repo = factory.create_committee_repository()
committee_repo.add_or_update_list(command.data[0])
committee_has_topic_repo = factory.create_committee_has_topic_repository()
committee_has_topic_repo.add_or_update_list(command.data[1])
if command.entities == ["poll"]:
poll_repo = factory.create_poll_repository()
poll_repo.add_or_update_list(command.data[0])
# add poll has topic
# add poll has field_link


def publish_missing_entity_fetched_event(
Expand Down

0 comments on commit efe96c2

Please sign in to comment.