brewlog/src/application/routes/app/mod.rs

248 lines
7.5 KiB
Rust

mod add;
mod admin;
pub(super) mod auth;
mod bags;
mod brews;
mod cafes;
mod checkin;
mod cups;
mod data;
mod gear;
mod home;
mod roasters;
mod roasts;
mod stats;
mod timeline;
mod webauthn;
use axum::response::{IntoResponse, Redirect};
use axum::routing::{get, post};
use crate::application::state::AppState;
pub(super) fn router() -> axum::Router<AppState> {
axum::Router::new()
.route("/", get(home::home_page))
.route("/login", get(auth::login_page))
.route("/logout", post(auth::logout))
.route("/admin", get(admin::admin_page))
.route("/register/{token}", get(webauthn::register_page))
.route("/auth/cli-callback", get(webauthn::cli_callback_page))
.route("/data", get(data::data_page))
.route("/add", get(add::add_page))
.route("/scan", get(scan_redirect))
.route("/check-in", get(checkin::checkin_page))
.route("/timeline", get(timeline::timeline_page))
.route("/stats", get(stats::stats_page))
.route("/bags/{id}", get(bags::bag_detail_page))
.route("/bags/{id}/edit", get(bags::bag_edit_page))
.route("/brews/{id}", get(brews::brew_detail_page))
.route("/brews/{id}/edit", get(brews::brew_edit_page))
.route("/cafes/{slug}", get(cafes::cafe_detail_page))
.route("/cafes/{id}/edit", get(cafes::cafe_edit_page))
.route("/cups/{id}", get(cups::cup_detail_page))
.route("/cups/{id}/edit", get(cups::cup_edit_page))
.route("/gear/{id}", get(gear::gear_detail_page))
.route("/gear/{id}/edit", get(gear::gear_edit_page))
.route("/roasters/{slug}", get(roasters::roaster_detail_page))
.route("/roasters/{id}/edit", get(roasters::roaster_edit_page))
.route(
"/roasters/{roaster_slug}/roasts/{roast_slug}",
get(roasts::roast_detail_page),
)
.route("/roasts/{id}/edit", get(roasts::roast_edit_page))
.route("/static/css/styles.css", get(styles))
.route("/static/js/webauthn.js", get(webauthn_js))
.route(
"/static/js/components/photo-capture.js",
get(photo_capture_js),
)
.route(
"/static/js/components/searchable-select.js",
get(searchable_select_js),
)
.route("/static/js/components/chip-scroll.js", get(chip_scroll_js))
.route("/static/js/location.js", get(location_js))
.route("/static/js/image-utils.js", get(image_utils_js))
.route("/static/js/components/world-map.js", get(world_map_js))
.route("/static/js/components/donut-chart.js", get(donut_chart_js))
.route(
"/static/js/components/image-upload.js",
get(image_upload_js),
)
.route("/static/favicon-light.svg", get(favicon_light))
.route("/static/favicon-dark.svg", get(favicon_dark))
.route("/static/og-image.png", get(og_image))
.route("/static/app-icon-192.png", get(app_icon_192))
.route("/static/app-icon-512.png", get(app_icon_512))
.route("/static/site.webmanifest", get(site_webmanifest))
.route("/health", get(health))
}
async fn scan_redirect() -> Redirect {
Redirect::permanent("/")
}
async fn styles() -> impl IntoResponse {
(
[
("content-type", "text/css; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/css/styles.css"),
)
}
async fn webauthn_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/webauthn.js"),
)
}
async fn location_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/location.js"),
)
}
async fn image_utils_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/image-utils.js"),
)
}
async fn photo_capture_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/photo-capture.js"),
)
}
async fn searchable_select_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/searchable-select.js"),
)
}
async fn chip_scroll_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/chip-scroll.js"),
)
}
async fn world_map_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/world-map.js"),
)
}
async fn donut_chart_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/donut-chart.js"),
)
}
async fn image_upload_js() -> impl IntoResponse {
(
[
("content-type", "application/javascript; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/js/components/image-upload.js"),
)
}
async fn favicon_light() -> impl IntoResponse {
(
[
("content-type", "image/svg+xml"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/favicon-light.svg"),
)
}
async fn favicon_dark() -> impl IntoResponse {
(
[
("content-type", "image/svg+xml"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/favicon-dark.svg"),
)
}
async fn og_image() -> impl IntoResponse {
(
[
("content-type", "image/png"),
("cache-control", "public, max-age=604800"),
],
include_bytes!("../../../../static/og-image.png").as_slice(),
)
}
async fn app_icon_192() -> impl IntoResponse {
(
[
("content-type", "image/png"),
("cache-control", "public, max-age=604800"),
],
include_bytes!("../../../../static/app-icon-192.png").as_slice(),
)
}
async fn app_icon_512() -> impl IntoResponse {
(
[
("content-type", "image/png"),
("cache-control", "public, max-age=604800"),
],
include_bytes!("../../../../static/app-icon-512.png").as_slice(),
)
}
async fn site_webmanifest() -> impl IntoResponse {
(
[
("content-type", "application/manifest+json; charset=utf-8"),
("cache-control", "public, max-age=604800"),
],
include_str!("../../../../static/site.webmanifest"),
)
}
async fn health() -> impl IntoResponse {
([("content-type", "application/json")], r#"{"status":"ok"}"#)
}