Added filter on player count
This commit is contained in:
parent
a1df2b0ef6
commit
d755775f43
2 changed files with 10 additions and 0 deletions
|
|
@ -12,4 +12,10 @@ def filter_non_expansions_out(to_filter_boardgames: list[boardgame_classes.Board
|
|||
|
||||
filtered_boardgames = list(filter(lambda x: x.expansion_info != None, to_filter_boardgames))
|
||||
|
||||
return filtered_boardgames
|
||||
|
||||
|
||||
def filter_on_playercount(to_filter_boardgames: list[boardgame_classes.BoardGame], player_amount: int):
|
||||
filtered_boardgames = list(filter(lambda x: x.min_players <= player_amount and x.max_players >= player_amount,to_filter_boardgames))
|
||||
|
||||
return filtered_boardgames
|
||||
|
|
@ -64,6 +64,7 @@ app.add_middleware(
|
|||
class BoardgameFilterParams(BaseModel):
|
||||
filter_expansions_out: bool = False
|
||||
only_expansions: bool = False
|
||||
player_amount: int = -1
|
||||
|
||||
def do_filtering(self,boardgame_list) -> list[boardgame_classes.BoardGame]:
|
||||
if self.filter_expansions_out:
|
||||
|
|
@ -72,6 +73,9 @@ class BoardgameFilterParams(BaseModel):
|
|||
if self.only_expansions:
|
||||
boardgame_list = boardgame_filters.filter_non_expansions_out(boardgame_list)
|
||||
|
||||
if self.player_amount > -1:
|
||||
boardgame_list = boardgame_filters.filter_on_playercount(boardgame_list, self.player_amount)
|
||||
|
||||
return boardgame_list
|
||||
|
||||
class PlayFilterParams(BaseModel):
|
||||
|
|
|
|||
Loading…
Reference in a new issue