Fix campus type

main
Tait Hoyem 4 months ago
parent ba75b73ee3
commit 71b9d23517

@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS responses (
uleth_id INTEGER NOT NULL,
compiler_design BOOLEAN NOT NULL,
distributed_systems BOOLEAN NOT NULL,
calgary_cpsc_group BOOLEAN NOT NULL,
comments VARCHAR(1000) NOT NULL,
school_campus campus NOT NULL
);

@ -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)

@ -25,9 +25,9 @@ Likewise, <strong>both Calgary campus and Lethbridge campus students are encoura
<label for="id">ULeth ID#</label>
<input type="id" id="id" name="uleth_id"/>
<label for="camp">Campus</label>
<select id="camp" name="campus">
<option value="l" default>Lethbridge</option>
<option value="c">Calgary</option>
<select id="camp" name="school_campus">
<option value="lethbridge" default>Lethbridge</option>
<option value="calgary">Calgary</option>
</select>
</fieldset>
<fieldset>
@ -36,6 +36,8 @@ Likewise, <strong>both Calgary campus and Lethbridge campus students are encoura
<label for="ds">Distributed Systems</label>
<input type="checkbox" id="cd" name="compiler_design"/>
<label for="cd">Compiler Design</label>
<input type="checkbox" id="cccg" name="calgary_cpsc_group"/>
<label for="cccg">Compiler Design</label>
<label for="ac">Additional Comments</label>
<textarea id="ac" name="comments">
</textarea>

Loading…
Cancel
Save