|
|
|
@ -14,6 +14,16 @@ use axum::{Form, response::IntoResponse, routing::get, Router, body::Body, respo
|
|
|
|
|
use axum::extract::State;
|
|
|
|
|
use axum_csrf::{CsrfConfig, CsrfLayer, CsrfToken};
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, sqlx::Type, Deserialize, Debug, Clone, Copy)]
|
|
|
|
|
#[serde(rename_all = "lowercase")]
|
|
|
|
|
#[sqlx(type_name = "campus")]
|
|
|
|
|
enum Campus {
|
|
|
|
|
#[sqlx(rename = "c")]
|
|
|
|
|
Calgary,
|
|
|
|
|
#[sqlx(rename = "l")]
|
|
|
|
|
Lethbridge,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Template, Deserialize, Serialize)]
|
|
|
|
|
#[template(path = "course_interest.html")]
|
|
|
|
|
struct FormPage {
|
|
|
|
@ -29,6 +39,8 @@ struct DBFormResponse {
|
|
|
|
|
uleth_id: i32,
|
|
|
|
|
compiler_design: bool,
|
|
|
|
|
distributed_systems: bool,
|
|
|
|
|
calgary_cpsc_group: bool,
|
|
|
|
|
school_campus: Campus,
|
|
|
|
|
comments: String,
|
|
|
|
|
}
|
|
|
|
|
impl From<HTMLFormResponse> for DBFormResponse {
|
|
|
|
@ -39,6 +51,8 @@ impl From<HTMLFormResponse> for DBFormResponse {
|
|
|
|
|
uleth_id: html_form.uleth_id,
|
|
|
|
|
compiler_design: html_form.compiler_design,
|
|
|
|
|
distributed_systems: html_form.distributed_systems,
|
|
|
|
|
calgary_cpsc_group: html_form.calgary_cpsc_group,
|
|
|
|
|
school_campus: html_form.school_campus,
|
|
|
|
|
comments: html_form.comments,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -55,7 +69,11 @@ struct HTMLFormResponse {
|
|
|
|
|
#[serde(default = "bool::default")]
|
|
|
|
|
#[serde(deserialize_with = "checkbox::deserialize_checkbox")]
|
|
|
|
|
distributed_systems: bool,
|
|
|
|
|
#[serde(default = "bool::default")]
|
|
|
|
|
#[serde(deserialize_with = "checkbox::deserialize_checkbox")]
|
|
|
|
|
calgary_cpsc_group: bool,
|
|
|
|
|
comments: String,
|
|
|
|
|
school_campus: Campus,
|
|
|
|
|
authentication_key: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -69,23 +87,25 @@ impl DBFormResponse {
|
|
|
|
|
query!(
|
|
|
|
|
r#"
|
|
|
|
|
INSERT INTO responses
|
|
|
|
|
(name,email,uleth_id,compiler_design,distributed_systems,comments)
|
|
|
|
|
(name,email,uleth_id,compiler_design,distributed_systems,calgary_cpsc_group,comments,school_campus)
|
|
|
|
|
VALUES
|
|
|
|
|
($1, $2, $3, $4, $5, $6)
|
|
|
|
|
($1, $2, $3, $4, $5, $6, $7, $8)
|
|
|
|
|
"#,
|
|
|
|
|
to_add.name,
|
|
|
|
|
to_add.email,
|
|
|
|
|
to_add.uleth_id,
|
|
|
|
|
to_add.compiler_design,
|
|
|
|
|
to_add.distributed_systems,
|
|
|
|
|
to_add.comments)
|
|
|
|
|
to_add.calgary_cpsc_group,
|
|
|
|
|
to_add.comments,
|
|
|
|
|
to_add.school_campus as Campus)
|
|
|
|
|
.execute(&*pool)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
async fn all(pool: &PgPool) -> Result<Vec<DBFormResponse>, sqlx::Error> {
|
|
|
|
|
query_as!(DBFormResponse,
|
|
|
|
|
r#"
|
|
|
|
|
SELECT name,email,uleth_id,compiler_design,distributed_systems,comments
|
|
|
|
|
SELECT name,email,uleth_id,compiler_design,distributed_systems,calgary_cpsc_group,school_campus AS "school_campus: Campus",comments
|
|
|
|
|
FROM responses;
|
|
|
|
|
"#)
|
|
|
|
|
.fetch_all(&*pool)
|
|
|
|
|