Skip to main content

nfl_data/web/
mod.rs

1mod assets;
2mod error;
3mod nflverse;
4mod slates;
5mod view;
6
7use std::sync::Arc;
8
9use axum::Router;
10use time::OffsetDateTime;
11
12use crate::{NflData, Season};
13
14/// Admin router config: season and optional test clock override.
15#[derive(Debug, Clone)]
16pub struct AdminConfig {
17    pub season: Season,
18    pub now_override: Option<OffsetDateTime>,
19}
20
21/// Private state shared by the admin handlers.
22#[derive(Clone)]
23pub(crate) struct AdminState {
24    nfl: Arc<NflData>,
25    config: AdminConfig,
26}
27
28impl axum::extract::FromRef<AdminState> for Arc<NflData> {
29    fn from_ref(state: &AdminState) -> Self {
30        Arc::clone(&state.nfl)
31    }
32}
33
34/// Build the admin router. Not authenticated: the host must mount it behind
35/// its own admin gate.
36pub fn router<S>(nfl: Arc<NflData>, config: AdminConfig) -> Router<S>
37where
38    S: Clone + Send + Sync + 'static,
39{
40    Router::new()
41        .nest("/salary-imports", salary_imports::router())
42        .route("/", axum::routing::get(view::index))
43        .route("/slates", axum::routing::get(slates::index))
44        .route("/slates/{id}", axum::routing::get(slates::show))
45        .route(
46            "/nflverse",
47            axum::routing::get(nflverse::show).post(nflverse::start),
48        )
49        .route(
50            "/nflverse/fill-missing-espn-ids",
51            axum::routing::post(nflverse::fill_missing_espn_ids),
52        )
53        .route(
54            "/static/{*path}",
55            axum::routing::get(assets::serve).head(assets::serve),
56        )
57        .with_state(AdminState { nfl, config })
58}
59
60mod salary_imports;
61
62#[cfg(test)]
63pub(crate) mod tests {
64    // Shared fixture; the standalone [[test]] binaries compile separately.
65    pub(crate) mod salary_fixture;
66    pub(crate) mod salary_imports;
67}