Add maud for frontend and move api to sub module
This commit is contained in:
parent
9059894021
commit
1698ef9c60
25
Cargo.lock
generated
25
Cargo.lock
generated
@ -258,6 +258,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"dotenvy",
|
||||
"feed-rs",
|
||||
"maud",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_with",
|
||||
@ -950,6 +951,30 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
|
||||
|
||||
[[package]]
|
||||
name = "maud"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0bab19cef8a7fe1c18a43e881793bfc9d4ea984befec3ae5bd0415abf3ecf00"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"http",
|
||||
"itoa",
|
||||
"maud_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maud_macros"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0be95d66c3024ffce639216058e5bae17a83ecaf266ffc6e4d060ad447c9eed2"
|
||||
dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.5"
|
||||
|
@ -17,6 +17,7 @@ axum = "0.6"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
dotenvy = "0.15"
|
||||
feed-rs = "1.3"
|
||||
maud = { version = "0.25", features = ["axum"] }
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_with = "3"
|
||||
|
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()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user