Skip to content

Commit

Permalink
Revert "Update API endpoints for EU parliament polls"
Browse files Browse the repository at this point in the history
This reverts commit 8eab244.
  • Loading branch information
RichardKruemmel authored Jun 8, 2024
1 parent 8f3a553 commit d75697d
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions src/api/versions/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
from src.db.connection import Session
from src.api.utils.error import check_entity_not_found
from src.api.utils.party_sort import party_sort
from src.api.utils.polls import (
get_politcian_ids_by_bundestag_polldata_and_follow_ids,
get_politcian_ids_by_euparl_polldata_and_follow_ids,
)
from src.api.utils.polls import get_politcian_ids_by_bundestag_polldata_and_follow_ids
from src.redis_cache.cache import ONE_DAY_IN_SECONDS, ONE_WEEK_IN_SECONDS, custom_cache

router = APIRouter(
Expand Down Expand Up @@ -269,7 +266,7 @@ def read_politician_sidejobs(db: Session = Depends(get_db)):
def read_latest_polls(
follow_ids: List[int] = Query(None), db: Session = Depends(get_db)
):
polls = crud.get_polls_total(db, parliament=schemas.Parliament.BUNDESTAG)
polls = crud.get_polls_total(db)
latest_polls = get_politcian_ids_by_bundestag_polldata_and_follow_ids(
polls, db, follow_ids
)
Expand All @@ -284,9 +281,7 @@ def read_latest_polls(
page: int = Query(1),
):
size = page * 10
filtered_polls = crud.get_all_polls_total(
db, schemas.Parliament.BUNDESTAG, size, filters
)
filtered_polls = crud.get_all_polls_total(db, size, filters)
polls = {}
polls["data"] = get_politcian_ids_by_bundestag_polldata_and_follow_ids(
filtered_polls, db
Expand All @@ -299,41 +294,6 @@ def read_latest_polls(
return polls


@router.get("/eu/polls", response_model=List[schemas.BundestagPollDataWithPoliticians])
def read_latest_polls(
follow_ids: List[int] = Query(None), db: Session = Depends(get_db)
):
polls = crud.get_polls_total(db, parliament=schemas.Parliament.EUPARL)
print(polls)
latest_polls = get_politcian_ids_by_euparl_polldata_and_follow_ids(
polls, db, follow_ids
)
check_entity_not_found(latest_polls, "Polls")
return latest_polls


@router.get("/eu/allpolls", response_model=schemas.BundestagPoll)
def read_latest_polls(
filters: List[int] = Query(None),
db: Session = Depends(get_db),
page: int = Query(1),
):
size = page * 10
filtered_polls = crud.get_all_polls_total(
db, schemas.Parliament.EUPARL, size, filters
)
polls = {}
polls["data"] = get_politcian_ids_by_euparl_polldata_and_follow_ids(
filtered_polls, db
)
if len(polls["data"]) < 10:
polls["last_page"] = True
else:
polls["last_page"] = False
check_entity_not_found(polls, "Polls")
return polls


@router.get("/politician/{id}/news", response_model=Page[schemas.PolitrackNewsArticle])
@custom_cache(expire=ONE_WEEK_IN_SECONDS)
async def read_politician_news(id: int):
Expand Down

0 comments on commit d75697d

Please sign in to comment.