diff --git a/sqlx-data.json b/sqlx-data.json index 2e1b6c5..14d3b89 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -32,24 +32,7 @@ }, "query": "\n select id, player_1, player_2\n from matches\n where id = $1\n " }, - "edda11e287e2d8e0cea5a97122f412fd22d8a468478bce1b229e3f418b0a31f1": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Uuid", - "Uuid", - "Text", - "Int2", - "Int2", - "Date" - ] - } - }, - "query": "\n INSERT INTO scores (match_id, game_id, winner, winner_score, loser_score, created_at, played_at)\n VALUES ($1, $2, $3, $4, $5, now(), $6)\n " - }, - "fa56576f5c3702155854b85a1abf7441e525c85bcc0f334f60ab1935ec3d2c7f": { + "b9912c14b491c1cfcb7c644339660fd48127d4df76360af1168055bae348506e": { "describe": { "columns": [ { @@ -93,10 +76,11 @@ ], "parameters": { "Left": [ - "Uuid" + "Uuid", + "Date" ] } }, - "query": "\n select match_id, game_id, winner, played_at, winner_score, loser_score\n from scores\n where match_id = $1\n order by played_at desc\n " + "query": "\n select match_id, game_id, winner, played_at, winner_score, loser_score\n from scores\n where match_id = $1\n and played_at > $2\n order by played_at desc\n " } } \ No newline at end of file diff --git a/src/routes/scores/get.rs b/src/routes/scores/get.rs index 6bdaa85..1804fdc 100644 --- a/src/routes/scores/get.rs +++ b/src/routes/scores/get.rs @@ -5,6 +5,7 @@ use crate::routes::{ use actix_web::{get, web, HttpResponse}; use actix_web_flash_messages::IncomingFlashMessages; use chrono::Days; +use chrono::{Duration, Utc}; use core::ops::Deref; use itertools::Itertools; use plotters::prelude::*; @@ -242,15 +243,19 @@ async fn get_match_scores( matchup_id: Uuid, pg_pool: &PgPool, ) -> Result, anyhow::Error> { + let now = Utc::now().date_naive(); + let cutoff_date = now - Duration::days(30 * 6); let scores = query_as!( MatchScore, r#" select match_id, game_id, winner, played_at, winner_score, loser_score from scores where match_id = $1 + and played_at > $2 order by played_at desc "#, - matchup_id + matchup_id, + cutoff_date ) .fetch_all(pg_pool) .await?;