brewlog/src/application/routes/app/cafes.rs
Jon Seager 94088f1f4b
feat: add edit button to all detail pages
Add edit_button and edit_delete_buttons macros to detail_cards.html.
All 7 entity detail pages now show an Edit button next to Delete when
authenticated. Each detail template struct receives a pre-computed
edit_url from the route handler.
2026-02-10 19:42:47 +00:00

43 lines
1.3 KiB
Rust

use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use tower_cookies::Cookies;
use crate::application::errors::map_app_error;
use crate::application::routes::api::images::resolve_image_url;
use crate::application::routes::render_html;
use crate::application::state::AppState;
use crate::presentation::web::templates::CafeDetailTemplate;
use crate::presentation::web::views::CafeDetailView;
#[tracing::instrument(skip(state, cookies))]
pub(crate) async fn cafe_detail_page(
State(state): State<AppState>,
cookies: Cookies,
Path(slug): Path<String>,
) -> Result<Response, StatusCode> {
let is_authenticated = crate::application::routes::is_authenticated(&state, &cookies).await;
let cafe = state
.cafe_repo
.get_by_slug(&slug)
.await
.map_err(|e| map_app_error(e.into()))?;
let image_url = resolve_image_url(&state, "cafe", i64::from(cafe.id)).await;
let edit_url = format!("/cafes/{}/edit", cafe.id);
let view = CafeDetailView::from_domain(cafe);
let template = CafeDetailTemplate {
nav_active: "",
is_authenticated,
version_info: &crate::VERSION_INFO,
base_url: crate::base_url(),
edit_url,
cafe: view,
image_url,
};
render_html(template).map(IntoResponse::into_response)
}