diff --git a/Cargo.lock b/Cargo.lock index de8e823..03cff9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,6 +1062,7 @@ dependencies = [ "chrono", "pulldown-cmark", "reqwest", + "serde", "serde_json", ] diff --git a/Cargo.toml b/Cargo.toml index c70bb52..c4a91dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" actix-web = "3" actix-files = "0.4.0" askama = "0.9" +serde = "1.0.117" serde_json = "1.0" reqwest = { version = "0.10", features = ["blocking"] } pulldown-cmark = "0.8.0" diff --git a/src/popular.rs b/src/popular.rs index aba11f8..889d249 100644 --- a/src/popular.rs +++ b/src/popular.rs @@ -1,5 +1,6 @@ // CRATES -use actix_web::{get, HttpResponse, Result}; +use actix_web::{get, web, HttpResponse, Result}; +use serde::Deserialize; use askama::Template; #[path = "subreddit.rs"] mod subreddit; @@ -12,9 +13,17 @@ struct PopularTemplate { sort: String } +#[derive(Deserialize)] +pub struct Params { + sort: Option +} + #[get("/")] -pub async fn page() -> Result { - render("popular".to_string(), "hot".to_string()).await +pub async fn page(params: web::Query) -> Result { + match ¶ms.sort { + Some(sort) => render("popular".to_string(), sort.to_string()).await, + None => render("popular".to_string(), "hot".to_string()).await, + } } async fn render(sub_name: String, sort: String) -> Result {