(
challenge_id: str,
response: Response,
participant=Cookie(default=None, alias=COOKIE_NAME),
)
| 335 | |
| 336 | @app.get("/api/challenges/{challenge_id}") |
| 337 | def get_challenge( |
| 338 | challenge_id: str, |
| 339 | response: Response, |
| 340 | participant=Cookie(default=None, alias=COOKIE_NAME), |
| 341 | ) -> dict: |
| 342 | current = get_or_create_participant(response, participant) |
| 343 | with connect() as conn: |
| 344 | row = conn.execute( |
| 345 | "SELECT * FROM challenges WHERE id = ?", (challenge_id,) |
| 346 | ).fetchone() |
| 347 | challenge = public_challenge(conn, row) |
| 348 | cells = [ |
| 349 | row_to_dict(cell) |
| 350 | for cell in conn.execute( |
| 351 | """ |
| 352 | SELECT cell_id, lat, lng |
| 353 | FROM challenge_cells |
| 354 | WHERE challenge_id = ? |
| 355 | ORDER BY cell_id |
| 356 | """, |
| 357 | (challenge_id,), |
| 358 | ).fetchall() |
| 359 | ] |
| 360 | unlocked = [ |
| 361 | row_to_dict(cell) |
| 362 | for cell in conn.execute( |
| 363 | """ |
| 364 | SELECT DISTINCT cell_id |
| 365 | FROM user_unlocked_cells |
| 366 | WHERE challenge_id = ? |
| 367 | """, |
| 368 | (challenge_id,), |
| 369 | ).fetchall() |
| 370 | ] |
| 371 | mine = [ |
| 372 | row_to_dict(cell) |
| 373 | for cell in conn.execute( |
| 374 | """ |
| 375 | SELECT cell_id |
| 376 | FROM user_unlocked_cells |
| 377 | WHERE challenge_id = ? AND participant_id = ? |
| 378 | """, |
| 379 | (challenge_id, current["id"]), |
| 380 | ).fetchall() |
| 381 | ] |
| 382 | return { |
| 383 | "challenge": challenge, |
| 384 | "cells": cells, |
| 385 | "unlocked": unlocked, |
| 386 | "mine": mine, |
| 387 | "participant": current, |
| 388 | } |
| 389 | |
| 390 | |
| 391 | @app.get("/api/challenges/{challenge_id}/leaderboard") |
nothing calls this directly
no test coverage detected