Skip to main content

max / makenotwork

1.1 KB · 41 lines History Blame Raw
1 use axum::{extract::State, response::IntoResponse};
2 use tower_sessions::Session;
3
4 use crate::{
5 auth::AdminUser,
6 db,
7 error::Result,
8 helpers::get_csrf_token,
9 templates::AdminSignupsTemplate,
10 types::AdminSignupRow,
11 AppState,
12 };
13
14 /// Admin page listing email signups from the landing page.
15 #[tracing::instrument(skip_all, name = "admin::admin_signups")]
16 pub(super) async fn admin_signups(
17 State(state): State<AppState>,
18 session: Session,
19 AdminUser(admin): AdminUser,
20 ) -> Result<impl IntoResponse> {
21 let db_signups = db::email_signups::get_all_email_signups(&state.db).await?;
22 let total = db::email_signups::count_email_signups(&state.db).await?;
23
24 let signups: Vec<AdminSignupRow> = db_signups
25 .into_iter()
26 .map(|s| AdminSignupRow {
27 email: s.email,
28 source: s.source,
29 created_at: s.created_at.format("%b %d, %Y %H:%M").to_string(),
30 })
31 .collect();
32
33 Ok(AdminSignupsTemplate {
34 csrf_token: get_csrf_token(&session).await,
35 session_user: Some(admin),
36 signups,
37 total,
38 admin_active_page: "signups",
39 })
40 }
41