Add maud for frontend and move api to sub module
This commit is contained in:
4
src/handlers/api/mod.rs
Normal file
4
src/handlers/api/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod feed;
|
||||
pub mod feeds;
|
||||
pub mod entry;
|
||||
pub mod entries;
|
||||
19
src/handlers/home.rs
Normal file
19
src/handlers/home.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use axum::extract::State;
|
||||
use maud::{html, Markup};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::models::entry::get_entries;
|
||||
|
||||
pub async fn get(State(pool): State<PgPool>) -> Result<Markup> {
|
||||
let entries = get_entries(&pool).await?;
|
||||
Ok(html! {
|
||||
h1 { "crawlnicle" }
|
||||
ul {
|
||||
@for entry in entries {
|
||||
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
|
||||
li { (title) }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,2 @@
|
||||
pub mod feed;
|
||||
pub mod feeds;
|
||||
pub mod entry;
|
||||
pub mod entries;
|
||||
pub mod api;
|
||||
pub mod home;
|
||||
|
||||
13
src/main.rs
13
src/main.rs
@@ -25,12 +25,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
sqlx::migrate!().run(&pool).await?;
|
||||
|
||||
let app = Router::new()
|
||||
.route("/v1/feeds", get(handlers::feeds::get))
|
||||
.route("/v1/feed", post(handlers::feed::post))
|
||||
.route("/v1/feed/:id", get(handlers::feed::get))
|
||||
.route("/v1/entries", get(handlers::entries::get))
|
||||
.route("/v1/entry", post(handlers::entry::post))
|
||||
.route("/v1/entry/:id", get(handlers::entry::get))
|
||||
.route("/api/v1/feeds", get(handlers::api::feeds::get))
|
||||
.route("/api/v1/feed", post(handlers::api::feed::post))
|
||||
.route("/api/v1/feed/:id", get(handlers::api::feed::get))
|
||||
.route("/api/v1/entries", get(handlers::api::entries::get))
|
||||
.route("/api/v1/entry", post(handlers::api::entry::post))
|
||||
.route("/api/v1/entry/:id", get(handlers::api::entry::get))
|
||||
.route("/", get(handlers::home::get))
|
||||
.with_state(pool)
|
||||
.layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user