Database connection and user registration

This commit is contained in:
Alphonse Paix
2025-08-21 15:38:12 +02:00
parent 1fd1c4eef4
commit 709bd28a8c
14 changed files with 3023 additions and 18 deletions

View File

@@ -0,0 +1,5 @@
use axum::{http::StatusCode, response::IntoResponse};
pub async fn health_check() -> impl IntoResponse {
StatusCode::OK
}

View File

@@ -0,0 +1,37 @@
use axum::{Form, extract::State, http::StatusCode, response::IntoResponse};
use chrono::Utc;
use serde::Deserialize;
use sqlx::PgPool;
use uuid::Uuid;
pub async fn subscribe(
State(connection): State<PgPool>,
form: Form<FormData>,
) -> impl IntoResponse {
match sqlx::query!(
r#"
insert into subscriptions (id, email, name, subscribed_at)
values ($1, $2, $3, $4);
"#,
Uuid::new_v4(),
form.email,
form.name,
Utc::now()
)
.execute(&connection)
.await
{
Ok(_) => StatusCode::OK,
Err(e) => {
eprintln!("Failed to execute query: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
}
}
}
#[derive(Deserialize)]
#[allow(dead_code)]
pub struct FormData {
name: String,
email: String,
}