Skip to main content

max / makenotwork

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