Templates refactoring
This commit is contained in:
@@ -1,41 +1,18 @@
|
||||
use crate::{routes::AppError, startup::AppState};
|
||||
use crate::{
|
||||
domain::PostEntry,
|
||||
routes::AppError,
|
||||
startup::AppState,
|
||||
templates::{PostTemplate, PostsTemplate},
|
||||
};
|
||||
use anyhow::Context;
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
struct PostEntry {
|
||||
post_id: Uuid,
|
||||
author: Option<String>,
|
||||
title: String,
|
||||
content: String,
|
||||
published_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl PostEntry {
|
||||
#[allow(dead_code)]
|
||||
fn formatted_date(&self) -> String {
|
||||
self.published_at.format("%B %d, %Y").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "../templates/posts.html")]
|
||||
struct PostsTemplate {
|
||||
posts: Vec<PostEntry>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "../templates/post.html")]
|
||||
struct PostTemplate {
|
||||
post: PostEntry,
|
||||
}
|
||||
|
||||
pub async fn list_posts(
|
||||
State(AppState {
|
||||
connection_pool, ..
|
||||
|
||||
Reference in New Issue
Block a user