Implement dupes flag in GET /cards

This commit is contained in:
Cal Corum 2023-05-03 13:29:03 -05:00
parent 5f150ebe5a
commit a7bfcaaff1

13
main.py
View File

@ -2221,6 +2221,19 @@ async def v1_cards_get(
all_cards = all_cards.order_by(-Card.id)
if limit is not None:
all_cards = all_cards.limit(limit)
if dupes:
if team_id is None:
raise HTTPException(status_code=400, detail='Dupe checking must include a team_id')
logging.info(f'dupe check')
p_query = Card.select(Card.player).where(Card.team_id == team_id)
seen = set()
dupes = []
for x in p_query:
if x.player.player_id in seen:
dupes.append(x.player_id)
else:
seen.add(x.player_id)
all_cards = all_cards.where(Card.player_id << dupes)
# if all_cards.count() == 0:
# db.close()