kopia lustrzana https://github.com/bugout-dev/moonstream
Add leaderboard key value filter.
rodzic
3a0ccb889f
commit
62857b08d9
|
@ -1289,6 +1289,7 @@ def get_leaderboard_positions(
|
||||||
limit: int,
|
limit: int,
|
||||||
offset: int,
|
offset: int,
|
||||||
version_number: Optional[int] = None,
|
version_number: Optional[int] = None,
|
||||||
|
poitns_data: Optional[Dict[str, str]] = None,
|
||||||
) -> List[Row[Tuple[uuid.UUID, str, int, str, int]]]:
|
) -> List[Row[Tuple[uuid.UUID, str, int, str, int]]]:
|
||||||
"""
|
"""
|
||||||
Get the leaderboard positions
|
Get the leaderboard positions
|
||||||
|
@ -1324,6 +1325,18 @@ def get_leaderboard_positions(
|
||||||
.filter(LeaderboardVersion.version_number == latest_version)
|
.filter(LeaderboardVersion.version_number == latest_version)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if poitns_data:
|
||||||
|
|
||||||
|
query = query.filter(
|
||||||
|
or_(
|
||||||
|
*[
|
||||||
|
LeaderboardScores.points_data[point_key].astext == point_value
|
||||||
|
for point_key, point_value in poitns_data.items()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if limit:
|
if limit:
|
||||||
query = query.limit(limit)
|
query = query.limit(limit)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Leaderboard API.
|
Leaderboard API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List, Optional, Any, Union
|
from typing import Any, Dict, List, Optional, Any, Union
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
@ -88,6 +89,19 @@ app.add_middleware(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def points_data_dependency(request: Request):
|
||||||
|
# Extract all query parameters as a dictionary
|
||||||
|
query_params = dict(request.query_params)
|
||||||
|
# Filter parameters that start with 'points_data.'
|
||||||
|
points_data_params = {
|
||||||
|
key[len("points_data.") :]: value
|
||||||
|
for key, value in query_params.items()
|
||||||
|
if key.startswith("points_data.")
|
||||||
|
}
|
||||||
|
# Optionally, transform the keys or structure as needed
|
||||||
|
return points_data_params
|
||||||
|
|
||||||
|
|
||||||
@app.get(
|
@app.get(
|
||||||
"",
|
"",
|
||||||
response_model=List[data.LeaderboardPosition],
|
response_model=List[data.LeaderboardPosition],
|
||||||
|
@ -104,6 +118,7 @@ async def leaderboard(
|
||||||
offset: int = Query(0),
|
offset: int = Query(0),
|
||||||
db_session: Session = Depends(db.yield_db_session),
|
db_session: Session = Depends(db.yield_db_session),
|
||||||
version: Optional[str] = Query(None, description="Version of the leaderboard."),
|
version: Optional[str] = Query(None, description="Version of the leaderboard."),
|
||||||
|
points_data: Dict[str, str] = Depends(points_data_dependency),
|
||||||
) -> List[data.LeaderboardPosition]:
|
) -> List[data.LeaderboardPosition]:
|
||||||
"""
|
"""
|
||||||
Returns the leaderboard positions.
|
Returns the leaderboard positions.
|
||||||
|
@ -122,7 +137,7 @@ async def leaderboard(
|
||||||
raise EngineHTTPException(status_code=500, detail="Internal server error")
|
raise EngineHTTPException(status_code=500, detail="Internal server error")
|
||||||
|
|
||||||
leaderboard_positions = actions.get_leaderboard_positions(
|
leaderboard_positions = actions.get_leaderboard_positions(
|
||||||
db_session, leaderboard.id, limit, offset, version
|
db_session, leaderboard.id, limit, offset, version, points_data
|
||||||
)
|
)
|
||||||
|
|
||||||
result = [
|
result = [
|
||||||
|
|
Ładowanie…
Reference in New Issue