Commit e29e6c38 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Initial adapotion to postgres

parent 048e23f5
...@@ -35,3 +35,7 @@ bcrypt = "0.3" ...@@ -35,3 +35,7 @@ bcrypt = "0.3"
[dependencies.serde_json] [dependencies.serde_json]
version = "1.0.20" version = "1.0.20"
features = ["preserve_order"] features = ["preserve_order"]
[dependencies.postgres]
version = "0.15"
features = ["with-time"]
\ No newline at end of file
...@@ -56,7 +56,7 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont ...@@ -56,7 +56,7 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
if let Some(serde_yaml::Value::Number(cstars)) = if let Some(serde_yaml::Value::Number(cstars)) =
taskinfo.get(&serde_yaml::Value::String("stars".to_string())) taskinfo.get(&serde_yaml::Value::String("stars".to_string()))
{ {
stars = cstars.as_u64().unwrap() as u8; stars = cstars.as_u64().unwrap() as i8;
} }
let task = Task::new(taskdir, stars); let task = Task::new(taskdir, stars);
taskgroup.tasks.push(task); taskgroup.tasks.push(task);
......
This diff is collapsed.
...@@ -25,7 +25,7 @@ pub struct SessionUser { ...@@ -25,7 +25,7 @@ pub struct SessionUser {
pub zip: Option<String>, pub zip: Option<String>,
pub city: Option<String>, pub city: Option<String>,
pub nation: Option<String>, pub nation: Option<String>,
pub grade: u8, pub grade: i8,
pub is_teacher: bool, pub is_teacher: bool,
pub managed_by: Option<u32>, pub managed_by: Option<u32>,
...@@ -81,16 +81,16 @@ pub struct Task { ...@@ -81,16 +81,16 @@ pub struct Task {
pub id: Option<u32>, pub id: Option<u32>,
pub taskgroup: u32, pub taskgroup: u32,
pub location: String, pub location: String,
pub stars: u8, pub stars: i8,
} }
pub struct Submission { pub struct Submission {
pub id: Option<u32>, pub id: Option<u32>,
pub session_user: u32, pub session_user: u32,
pub task: u32, pub task: u32,
pub grade: u8, pub grade: i8,
pub validated: bool, pub validated: bool,
pub nonvalidated_grade: u8, pub nonvalidated_grade: i8,
pub needs_validation: bool, pub needs_validation: bool,
pub subtask_identifier: Option<String>, pub subtask_identifier: Option<String>,
pub value: String, pub value: String,
...@@ -101,7 +101,7 @@ pub struct Submission { ...@@ -101,7 +101,7 @@ pub struct Submission {
pub struct Grade { pub struct Grade {
pub taskgroup: u32, pub taskgroup: u32,
pub user: u32, pub user: u32,
pub grade: Option<u8>, pub grade: Option<i8>,
pub validated: bool, pub validated: bool,
} }
...@@ -227,7 +227,7 @@ impl Taskgroup { ...@@ -227,7 +227,7 @@ impl Taskgroup {
} }
impl Task { impl Task {
pub fn new(location: String, stars: u8) -> Self { pub fn new(location: String, stars: i8) -> Self {
Task { id: None, taskgroup: 0, location: location, stars: stars } Task { id: None, taskgroup: 0, location: location, stars: stars }
} }
} }
...@@ -368,7 +368,7 @@ pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token ...@@ -368,7 +368,7 @@ pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token
} }
pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str, csrf_token: &str, pub fn save_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str, csrf_token: &str,
data: String, grade: u8, subtask: Option<String>) data: String, grade: i8, subtask: Option<String>)
-> MedalResult<String> -> MedalResult<String>
{ {
let session = conn.get_session(&session_token) let session = conn.get_session(&session_token)
...@@ -499,7 +499,7 @@ pub struct MemberInfo { ...@@ -499,7 +499,7 @@ pub struct MemberInfo {
pub id: u32, pub id: u32,
pub firstname: String, pub firstname: String,
pub lastname: String, pub lastname: String,
pub grade: u8, pub grade: i8,
pub logincode: String, pub logincode: String,
} }
...@@ -674,7 +674,7 @@ impl std::convert::Into<String> for ProfileStatus { ...@@ -674,7 +674,7 @@ impl std::convert::Into<String> for ProfileStatus {
pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<u32>, csrf_token: &str, pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<u32>, csrf_token: &str,
firstname: String, lastname: String, street: Option<String>, firstname: String, lastname: String, street: Option<String>,
zip: Option<String>, city: Option<String>, password: Option<String>, zip: Option<String>, city: Option<String>, password: Option<String>,
password_repeat: Option<String>, grade: u8) password_repeat: Option<String>, grade: i8)
-> MedalResult<ProfileStatus> -> MedalResult<ProfileStatus>
{ {
let mut session = conn.get_session(&session_token) let mut session = conn.get_session(&session_token)
......
...@@ -27,6 +27,7 @@ use rusqlite::Connection; ...@@ -27,6 +27,7 @@ use rusqlite::Connection;
mod db_apply_migrations; mod db_apply_migrations;
mod db_conn; mod db_conn;
mod db_conn_sqlite; mod db_conn_sqlite;
mod db_conn_postgres;
mod db_objects; mod db_objects;
use db_conn::{MedalConnection, MedalObject}; use db_conn::{MedalConnection, MedalObject};
......
...@@ -460,7 +460,7 @@ fn submission_post(req: &mut Request) -> IronResult<Response> { ...@@ -460,7 +460,7 @@ fn submission_post(req: &mut Request) -> IronResult<Response> {
let formdata = iexpect!(req.get_ref::<UrlEncodedBody>().ok()); let formdata = iexpect!(req.get_ref::<UrlEncodedBody>().ok());
(iexpect!(formdata.get("csrf"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(), (iexpect!(formdata.get("csrf"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(),
iexpect!(formdata.get("data"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(), iexpect!(formdata.get("data"),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request")))[0].to_owned(),
iexpect!(formdata.get("grade").unwrap_or(&vec!["0".to_owned()])[0].parse::<u8>().ok(),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request"))), iexpect!(formdata.get("grade").unwrap_or(&vec!["0".to_owned()])[0].parse::<i8>().ok(),(status::BadRequest, mime!(Text/Html), format!("400 Bad Request"))),
formdata.get("subtask").map(|x| x[0].to_owned()), formdata.get("subtask").map(|x| x[0].to_owned()),
) )
}; };
...@@ -560,7 +560,7 @@ fn profile_post(req: &mut Request) -> IronResult<Response> { ...@@ -560,7 +560,7 @@ fn profile_post(req: &mut Request) -> IronResult<Response> {
formdata.get("city").map(|x| x[0].to_owned()), formdata.get("city").map(|x| x[0].to_owned()),
formdata.get("password").map(|x| x[0].to_owned()), formdata.get("password").map(|x| x[0].to_owned()),
formdata.get("password_repeat").map(|x| x[0].to_owned()), formdata.get("password_repeat").map(|x| x[0].to_owned()),
iexpect!(formdata.get("grade"))[0].parse::<u8>().unwrap_or(0)) iexpect!(formdata.get("grade"))[0].parse::<i8>().unwrap_or(0))
}; };
let profilechangeresult = with_conn![functions::edit_profile, let profilechangeresult = with_conn![functions::edit_profile,
...@@ -609,7 +609,7 @@ fn user_post(req: &mut Request) -> IronResult<Response> { ...@@ -609,7 +609,7 @@ fn user_post(req: &mut Request) -> IronResult<Response> {
formdata.get("city").map(|x| x[0].to_owned()), formdata.get("city").map(|x| x[0].to_owned()),
formdata.get("password").map(|x| x[0].to_owned()), formdata.get("password").map(|x| x[0].to_owned()),
formdata.get("password_repeat").map(|x| x[0].to_owned()), formdata.get("password_repeat").map(|x| x[0].to_owned()),
iexpect!(formdata.get("grade"))[0].parse::<u8>().unwrap_or(0)) iexpect!(formdata.get("grade"))[0].parse::<i8>().unwrap_or(0))
}; };
let profilechangeresult = with_conn![functions::edit_profile, let profilechangeresult = with_conn![functions::edit_profile,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment