Skip to main content

max / makenotwork

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