Create utils.rs for Utilities

This commit is contained in:
spikecodes 2020-11-17 11:37:40 -08:00
parent 4350d5b7b3
commit 2c06ae1d8f
8 changed files with 90 additions and 101 deletions

View file

@ -5,12 +5,13 @@ use serde::Deserialize;
#[path = "subreddit.rs"]
mod subreddit;
use subreddit::{posts, Post};
// STRUCTS
#[derive(Template)]
#[template(path = "popular.html", escape = "none")]
struct PopularTemplate {
posts: Vec<subreddit::Post>,
posts: Vec<Post>,
sort: String,
}
@ -21,7 +22,7 @@ pub struct Params {
// RENDER
async fn render(sub_name: String, sort: String) -> Result<HttpResponse> {
let posts: Vec<subreddit::Post> = subreddit::posts(sub_name, &sort).await;
let posts: Vec<Post> = posts(sub_name, &sort).await;
let s = PopularTemplate { posts: posts, sort: sort }.render().unwrap();
Ok(HttpResponse::Ok().content_type("text/html").body(s))