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

Fix all types of objects stored in database to make Medal work with PostgreSQL databases

parent 401ed866
......@@ -10,7 +10,7 @@ use linked_hash_map::LinkedHashMap
#[derive(Serialize, Deserialize)]
struct TaskgroupJson {
location: String,
stars: Option<u8>,
stars: Option<i32>,
}
#[derive(Serialize, Deserialize)]
......@@ -27,7 +27,7 @@ struct ContestJson {
name: String,
participation_start: Option<DateTime<Utc>>,
participation_end: Option<DateTime<Utc>>,
duration_minutes: u32,
duration_minutes: i32,
public_listing: Option<bool>,
tasks: LinkedHashMap<String, serde_json::Value>,
}
......@@ -7,7 +7,7 @@ struct ContestYaml {
name: Option<String>,
participation_start: Option<String>,
participation_end: Option<String>,
duration_minutes: Option<u32>,
duration_minutes: Option<i32>,
public_listing: Option<bool>,
tasks: Option<serde_yaml::Mapping>,
......@@ -56,7 +56,7 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
if let Some(serde_yaml::Value::Number(cstars)) =
taskinfo.get(&serde_yaml::Value::String("stars".to_string()))
{
stars = cstars.as_u64().unwrap() as i8;
stars = cstars.as_u64().unwrap() as i32;
}
let task = Task::new(taskdir, stars);
taskgroup.tasks.push(task);
......
......@@ -14,43 +14,43 @@ pub trait MedalConnection {
fn save_session(&self, session: SessionUser);
fn get_session_or_new(&self, key: &str) -> SessionUser;
fn get_user_by_id(&self, user_id: u32) -> Option<SessionUser>;
fn get_user_and_group_by_id(&self, user_id: u32) -> Option<(SessionUser, Option<Group>)>;
fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser>;
fn get_user_and_group_by_id(&self, user_id: i32) -> Option<(SessionUser, Option<Group>)>;
//fn login(&self, session: &SessionUser, username: String, password: String) -> Result<String,()>;
fn login(&self, session: Option<&str>, username: &str, password: &str) -> Result<String, ()>;
fn login_with_code(&self, session: Option<&str>, logincode: &str) -> Result<String, ()>;
fn login_foreign(&self, session: Option<&str>, foreign_id: u32, foreign_type: functions::UserType,
fn login_foreign(&self, session: Option<&str>, foreign_id: &str, foreign_type: functions::UserType,
firstname: &str, lastname: &str)
-> Result<String, ()>;
fn create_user_with_groupcode(&self, session: Option<&str>, groupcode: &str) -> Result<String, ()>;
fn logout(&self, session: &str);
fn load_submission(&self, session: &SessionUser, task: u32, subtask: Option<&str>) -> Option<Submission>;
fn load_submission(&self, session: &SessionUser, task: i32, subtask: Option<&str>) -> Option<Submission>;
fn submit_submission(&self, submission: Submission);
fn get_grade_by_submission(&self, submission_id: u32) -> Grade;
fn get_contest_groups_grades(&self, session_id: u32, contest_id: u32)
fn get_grade_by_submission(&self, submission_id: i32) -> Grade;
fn get_contest_groups_grades(&self, session_id: i32, contest_id: i32)
-> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>);
fn get_taskgroup_user_grade(&self, session: &str, taskgroup_id: u32) -> Grade;
fn get_contest_user_grades(&self, session: &str, contest_id: u32) -> Vec<Grade>;
fn get_taskgroup_user_grade(&self, session: &str, taskgroup_id: i32) -> Grade;
fn get_contest_user_grades(&self, session: &str, contest_id: i32) -> Vec<Grade>;
fn get_contest_list(&self) -> Vec<Contest>;
fn get_contest_by_id(&self, contest_id: u32) -> Contest;
fn get_contest_by_id_partial(&self, contest_id: u32) -> Contest;
fn get_contest_by_id_complete(&self, contest_id: u32) -> Contest;
fn get_participation(&self, session: &str, contest_id: u32) -> Option<Participation>;
fn new_participation(&self, session: &str, contest_id: u32) -> Result<Participation, ()>;
fn get_task_by_id(&self, task_id: u32) -> Task;
fn get_task_by_id_complete(&self, task_id: u32) -> (Task, Taskgroup, Contest);
fn get_contest_by_id(&self, contest_id: i32) -> Contest;
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest;
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest;
fn get_participation(&self, session: &str, contest_id: i32) -> Option<Participation>;
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()>;
fn get_task_by_id(&self, task_id: i32) -> Task;
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest);
fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> u32;
fn find_next_submission_to_validate(&self, userid: u32, taskgroupid: u32);
fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> i32;
fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32);
fn add_group(&self, group: &mut Group);
fn get_groups(&self, session_id: u32) -> Vec<Group>;
fn get_groups_complete(&self, session_id: u32) -> Vec<Group>;
fn get_group_complete(&self, group_id: u32) -> Option<Group>;
fn get_groups(&self, session_id: i32) -> Vec<Group>;
fn get_groups_complete(&self, session_id: i32) -> Vec<Group>;
fn get_group_complete(&self, group_id: i32) -> Option<Group>;
}
pub trait MedalObject<T: MedalConnection> {
......
......@@ -149,7 +149,7 @@ impl MedalConnection for Connection {
self.get_session(&key).unwrap_or_else(|| self.new_session(&key))
}
fn get_user_by_id(&self, user_id: u32) -> Option<SessionUser> {
fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser> {
let res = self.query_row("SELECT session_token, csrf_token, last_login, last_activity, permanent_login, username, password, logincode, email, email_unconfirmed, email_confirmationcode, firstname, lastname, street, zip, city, nation, grade, is_teacher, managed_by, oauth_provider, oauth_foreign_id, salt FROM session_user WHERE id = ?1", &[&user_id], |row| {
SessionUser {
id: user_id,
......@@ -185,7 +185,7 @@ impl MedalConnection for Connection {
res.ok()
}
fn get_user_and_group_by_id(&self, user_id: u32) -> Option<(SessionUser, Option<Group>)> {
fn get_user_and_group_by_id(&self, user_id: i32) -> Option<(SessionUser, Option<Group>)> {
let session = self.get_user_by_id(user_id)?;
let group_id = match session.managed_by {
......@@ -211,7 +211,7 @@ impl MedalConnection for Connection {
fn login(&self, _session: Option<&str>, username: &str, password: &str) -> Result<String, ()> {
match self.query_row("SELECT id, password, salt FROM session_user WHERE username = ?1",
&[&username],
|row| -> (u32, Option<String>, Option<String>) { (row.get(0), row.get(1), row.get(2)) })
|row| -> (i32, Option<String>, Option<String>) { (row.get(0), row.get(1), row.get(2)) })
{
Ok((id, password_hash, salt)) => {
//password_hash ist das, was in der Datenbank steht
......@@ -239,7 +239,7 @@ impl MedalConnection for Connection {
//TODO: use session
fn login_with_code(&self, _session: Option<&str>, logincode: &str) -> Result<String, ()> {
match self.query_row("SELECT id FROM session_user WHERE logincode = ?1", &[&logincode], |row| -> u32 {
match self.query_row("SELECT id FROM session_user WHERE logincode = ?1", &[&logincode], |row| -> i32 {
row.get(0)
}) {
Ok(id) => {
......@@ -258,7 +258,7 @@ impl MedalConnection for Connection {
}
//TODO: use session
fn login_foreign(&self, _session: Option<&str>, foreign_id: u32, foreign_type: functions::UserType,
fn login_foreign(&self, _session: Option<&str>, foreign_id: &str, foreign_type: functions::UserType,
firstname: &str, lastname: &str)
-> Result<String, ()>
{
......@@ -266,7 +266,7 @@ impl MedalConnection for Connection {
let csrf_token: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
let now = time::get_time();
match self.query_row("SELECT id FROM session_user WHERE oauth_foreign_id = ?1", &[&foreign_id], |row| -> u32 {
match self.query_row("SELECT id FROM session_user WHERE oauth_foreign_id = ?1", &[&foreign_id], |row| -> i32 {
row.get(0)
}) {
Ok(id) => {
......@@ -285,7 +285,7 @@ impl MedalConnection for Connection {
//TODO: use session
fn create_user_with_groupcode(&self, _session: Option<&str>, groupcode: &str) -> Result<String, ()> {
match self.query_row("SELECT id FROM usergroup WHERE groupcode = ?1", &[&groupcode], |row| -> u32 {
match self.query_row("SELECT id FROM usergroup WHERE groupcode = ?1", &[&groupcode], |row| -> i32 {
row.get(0)
}) {
Ok(group_id) => {
......@@ -317,7 +317,7 @@ impl MedalConnection for Connection {
self.execute("UPDATE session_user SET session_token = NULL WHERE session_token = ?1", &[&session]).unwrap();
}
fn load_submission(&self, session: &SessionUser, task: u32, subtask: Option<&str>) -> Option<Submission> {
fn load_submission(&self, session: &SessionUser, task: i32, subtask: Option<&str>) -> Option<Submission> {
match subtask {
None => self.query_row("SELECT id, grade, validated, nonvalidated_grade, value, date, needs_validation FROM submission WHERE task = ?1 AND session_user = ?2 ORDER BY id DESC LIMIT 1", &[&task, &session.id], |row| {
Submission {
......@@ -359,7 +359,7 @@ impl MedalConnection for Connection {
grade.save(self);
}
}
fn get_grade_by_submission(&self, submission_id: u32) -> Grade {
fn get_grade_by_submission(&self, submission_id: i32) -> Grade {
self.query_row("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated FROM grade JOIN task ON grade.taskgroup = task.taskgroup JOIN submission ON task.id = submission.task AND grade.user = submission.session_user WHERE submission.id = ?1", &[&submission_id], |row| {
Grade {
taskgroup: row.get(0),
......@@ -379,17 +379,17 @@ impl MedalConnection for Connection {
})
}
fn get_contest_groups_grades(&self, session_id: u32, contest_id: u32)
fn get_contest_groups_grades(&self, session_id: i32, contest_id: i32)
-> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>) {
let mut stmt = self.prepare("SELECT id, name FROM taskgroup WHERE contest = ?1 ORDER BY id ASC").unwrap();
let tasknames_iter = stmt.query_map(&[&contest_id], |row| {
let x: (u32, String) = (row.get(0), row.get(1));
let x: (i32, String) = (row.get(0), row.get(1));
x
})
.unwrap();
let tasknames: Vec<(u32, String)> = tasknames_iter.map(|x| x.unwrap()).collect();
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let tasknames: Vec<(i32, String)> = tasknames_iter.map(|x| x.unwrap()).collect();
let mut taskindex: ::std::collections::BTreeMap<i32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len();
for (index, (i, _)) in tasknames.iter().enumerate() {
......@@ -458,16 +458,16 @@ impl MedalConnection for Connection {
(Vec::new(), Vec::new()) // should those be default filled?
}
}
fn get_contest_user_grades(&self, session_token: &str, contest_id: u32) -> Vec<Grade> {
fn get_contest_user_grades(&self, session_token: &str, contest_id: i32) -> Vec<Grade> {
let mut stmt = self.prepare("SELECT id, name FROM taskgroup WHERE contest = ?1 ORDER BY id ASC").unwrap();
let tasknames_iter = stmt.query_map(&[&contest_id], |row| {
let x: (u32, String) = (row.get(0), row.get(1));
let x: (i32, String) = (row.get(0), row.get(1));
x
})
.unwrap();
let tasknames: Vec<(u32, String)> = tasknames_iter.map(|x| x.unwrap()).collect();
let mut taskindex: ::std::collections::BTreeMap<u32, usize> = ::std::collections::BTreeMap::new();
let tasknames: Vec<(i32, String)> = tasknames_iter.map(|x| x.unwrap()).collect();
let mut taskindex: ::std::collections::BTreeMap<i32, usize> = ::std::collections::BTreeMap::new();
let n_tasks = tasknames.len();
for (index, (i, _)) in tasknames.iter().enumerate() {
......@@ -498,7 +498,7 @@ impl MedalConnection for Connection {
grades
}
fn get_taskgroup_user_grade(&self, session_token: &str, taskgroup_id: u32) -> Grade {
fn get_taskgroup_user_grade(&self, session_token: &str, taskgroup_id: i32) -> Grade {
let mut stmt = self.prepare("SELECT grade.taskgroup, grade.user, grade.grade, grade.validated
FROM grade
JOIN session_user ON session_user.id = grade.user
......@@ -533,7 +533,7 @@ impl MedalConnection for Connection {
res
}
fn get_contest_by_id(&self, contest_id: u32) -> Contest {
fn get_contest_by_id(&self, contest_id: i32) -> Contest {
self.query_row("SELECT location, filename, name, duration, public, start_date, end_date FROM contest WHERE id = ?1", &[&contest_id], |row| {
Contest {
id: Some(contest_id),
......@@ -549,7 +549,7 @@ impl MedalConnection for Connection {
}).unwrap()
}
fn get_contest_by_id_complete(&self, contest_id: u32) -> Contest {
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest {
let mut stmt = self.prepare("SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public, contest.start_date, contest.end_date, taskgroup.id, taskgroup.name, task.id, task.location, task.stars FROM contest JOIN taskgroup ON contest.id = taskgroup.contest JOIN task ON taskgroup.id = task.taskgroup WHERE contest.id = ?1").unwrap();
let mut taskgroupcontest_iter =
......@@ -583,7 +583,7 @@ impl MedalConnection for Connection {
contest
}
fn get_contest_by_id_partial(&self, contest_id: u32) -> Contest {
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest {
let mut stmt = self.prepare("SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public, contest.start_date, contest.end_date, taskgroup.id, taskgroup.name FROM contest JOIN taskgroup ON contest.id = taskgroup.contest WHERE contest.id = ?1").unwrap();
let mut taskgroupcontest_iter =
......@@ -611,7 +611,7 @@ impl MedalConnection for Connection {
contest
}
fn get_participation(&self, session: &str, contest_id: u32) -> Option<Participation> {
fn get_participation(&self, session: &str, contest_id: i32) -> Option<Participation> {
self.query_row("SELECT user, start_date FROM participation JOIN session_user ON session_user.id = user WHERE session_user.session_token = ?1 AND contest = ?2", &[&session, &contest_id], |row| {
Participation {
contest: contest_id,
......@@ -620,7 +620,7 @@ impl MedalConnection for Connection {
}
}).ok()
}
fn new_participation(&self, session: &str, contest_id: u32) -> Result<Participation, ()> {
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()> {
match self.query_row("SELECT user, start_date FROM participation JOIN session_user ON session_user.id = user WHERE session_user.session_token = ?1 AND contest = ?2", &[&session, &contest_id], |_| {}) {
Ok(()) => Err(()),
Err(_) => {
......@@ -634,13 +634,13 @@ impl MedalConnection for Connection {
}
}
}
fn get_task_by_id(&self, task_id: u32) -> Task {
fn get_task_by_id(&self, task_id: i32) -> Task {
self.query_row("SELECT location, stars, taskgroup FROM task WHERE id = ?1", &[&task_id], |row| {
Task { id: Some(task_id), taskgroup: row.get(2), location: row.get(0), stars: row.get(1) }
})
.unwrap()
}
fn get_task_by_id_complete(&self, task_id: u32) -> (Task, Taskgroup, Contest) {
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest) {
self.query_row(
"SELECT task.location, task.stars, taskgroup.id, taskgroup.name, contest.id, contest.location, contest.filename, contest.name, contest.duration, contest.public, contest.start_date, contest.end_date FROM contest JOIN taskgroup ON taskgroup.contest = contest.id JOIN task ON task.taskgroup = taskgroup.id WHERE task.id = ?1",
&[&task_id],
......@@ -669,15 +669,15 @@ impl MedalConnection for Connection {
}).unwrap()
}
fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> u32 {
fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> i32 {
match subtask {
Some(st) => self.query_row("SELECT id FROM submission JOIN task ON submission.task = task.id WHERE task.location = ?1 AND subtask_identifier = ?2 AND needs_validation = 1 LIMIT 1", &[&tasklocation, &st], |row| {row.get(0)}).unwrap(),
None => self.query_row("SELECT id FROM submission JOIN task ON submission.task = task.id WHERE task.location = ?1 AND needs_validation = 1 LIMIT 1", &[&tasklocation], |row| {row.get(0)}).unwrap(),
}
}
fn find_next_submission_to_validate(&self, userid: u32, taskgroupid: u32) {
let (id, validated) : (u32, bool) = self.query_row("SELECT id, validated FROM submission JOIN task ON submission.task = task.id WHERE task.taskgroup = ?1 AND submission.session_user = ?2 ORDER BY value DESC id DESC LIMIT 1", &[&taskgroupid, &userid], |row| {(row.get(0), row.get(1))}).unwrap();;
fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32) {
let (id, validated) : (i32, bool) = self.query_row("SELECT id, validated FROM submission JOIN task ON submission.task = task.id WHERE task.taskgroup = ?1 AND submission.session_user = ?2 ORDER BY value DESC id DESC LIMIT 1", &[&taskgroupid, &userid], |row| {(row.get(0), row.get(1))}).unwrap();;
if !validated {
self.execute("UPDATE submission SET needs_validation = 1 WHERE id = ?1", &[&id]).unwrap();
}
......@@ -685,7 +685,7 @@ impl MedalConnection for Connection {
fn add_group(&self, group: &mut Group) { group.save(self); }
fn get_groups(&self, session_id: u32) -> Vec<Group> {
fn get_groups(&self, session_id: i32) -> Vec<Group> {
let mut stmt = self.prepare("SELECT id, name, groupcode, tag FROM usergroup WHERE admin = ?1").unwrap();
let res = stmt.query_map(&[&session_id], |row| Group { id: Some(row.get(0)),
name: row.get(1),
......@@ -698,10 +698,10 @@ impl MedalConnection for Connection {
.collect();
res
}
fn get_groups_complete(&self, _session_id: u32) -> Vec<Group> {
fn get_groups_complete(&self, _session_id: i32) -> Vec<Group> {
unimplemented!();
}
fn get_group_complete(&self, group_id: u32) -> Option<Group> {
fn get_group_complete(&self, group_id: i32) -> Option<Group> {
let mut group = self.query_row("SELECT name, groupcode, tag, admin FROM usergroup WHERE id = ?1",
&[&group_id],
|row| Group { id: Some(group_id),
......@@ -883,7 +883,7 @@ impl MedalObject<Connection> for Grade {
impl MedalObject<Connection> for Participation {
fn save(&mut self, conn: &Connection) {
conn.execute("INSERT INTO0 participation (contest, user, start_date) VALUES (?1, ?2, ?3)",
conn.execute("INSERT INTO participation (contest, user, start_date) VALUES (?1, ?2, ?3)",
&[&self.contest, &self.user, &self.start])
.unwrap();
}
......
......@@ -4,7 +4,7 @@ use self::time::{Duration, Timespec};
#[derive(Clone)]
pub struct SessionUser {
pub id: u32,
pub id: i32,
pub session_token: Option<String>, // delete this to log out
pub csrf_token: String,
pub last_login: Option<Timespec>,
......@@ -25,23 +25,23 @@ pub struct SessionUser {
pub zip: Option<String>,
pub city: Option<String>,
pub nation: Option<String>,
pub grade: i8,
pub grade: i32,
pub is_teacher: bool,
pub managed_by: Option<u32>,
pub managed_by: Option<i32>,
pub oauth_foreign_id: Option<String>,
pub oauth_provider: Option<String>,
// pub oauth_extra_data: Option<String>,
// pub pms_id: Option<u32>,
// pub pms_school_id: Option<u32>,
// pub pms_id: Option<i32>,
// pub pms_school_id: Option<i32>,
}
// Short version for display
#[derive(Clone, Default)]
pub struct UserInfo {
pub id: u32,
pub id: i32,
pub username: Option<String>,
pub logincode: Option<String>,
pub firstname: Option<String>,
......@@ -50,20 +50,20 @@ pub struct UserInfo {
#[derive(Clone)]
pub struct Group {
pub id: Option<u32>,
pub id: Option<i32>,
pub name: String,
pub groupcode: String,
pub tag: String,
pub admin: u32,
pub admin: i32,
pub members: Vec<SessionUser>,
}
pub struct Contest {
pub id: Option<u32>,
pub id: Option<i32>,
pub location: String,
pub filename: String,
pub name: String,
pub duration: u32,
pub duration: i32,
pub public: bool,
pub start: Option<Timespec>,
pub end: Option<Timespec>,
......@@ -71,26 +71,26 @@ pub struct Contest {
}
pub struct Taskgroup {
pub id: Option<u32>,
pub contest: u32,
pub id: Option<i32>,
pub contest: i32,
pub name: String,
pub tasks: Vec<Task>,
}
pub struct Task {
pub id: Option<u32>,
pub taskgroup: u32,
pub id: Option<i32>,
pub taskgroup: i32,
pub location: String,
pub stars: i8,
pub stars: i32,
}
pub struct Submission {
pub id: Option<u32>,
pub session_user: u32,
pub task: u32,
pub grade: i8,
pub id: Option<i32>,
pub session_user: i32,
pub task: i32,
pub grade: i32,
pub validated: bool,
pub nonvalidated_grade: i8,
pub nonvalidated_grade: i32,
pub needs_validation: bool,
pub subtask_identifier: Option<String>,
pub value: String,
......@@ -99,45 +99,45 @@ pub struct Submission {
#[derive(Clone, Copy, Default)]
pub struct Grade {
pub taskgroup: u32,
pub user: u32,
pub grade: Option<i8>,
pub taskgroup: i32,
pub user: i32,
pub grade: Option<i32>,
pub validated: bool,
}
pub struct Participation {
pub contest: u32,
pub user: u32,
pub contest: i32,
pub user: i32,
pub start: Timespec,
}
pub trait HasId {
fn get_id(&self) -> Option<u32>;
fn set_id(&mut self, id: u32);
fn get_id(&self) -> Option<i32>;
fn set_id(&mut self, id: i32);
}
impl HasId for Submission {
fn get_id(&self) -> Option<u32> { self.id }
fn set_id(&mut self, id: u32) { self.id = Some(id); }
fn get_id(&self) -> Option<i32> { self.id }
fn set_id(&mut self, id: i32) { self.id = Some(id); }
}
impl HasId for Task {
fn get_id(&self) -> Option<u32> { self.id }
fn set_id(&mut self, id: u32) { self.id = Some(id); }
fn get_id(&self) -> Option<i32> { self.id }
fn set_id(&mut self, id: i32) { self.id = Some(id); }
}
impl HasId for Taskgroup {
fn get_id(&self) -> Option<u32> { self.id }
fn set_id(&mut self, id: u32) { self.id = Some(id); }
fn get_id(&self) -> Option<i32> { self.id }
fn set_id(&mut self, id: i32) { self.id = Some(id); }
}
impl HasId for Contest {
fn get_id(&self) -> Option<u32> { self.id }
fn set_id(&mut self, id: u32) { self.id = Some(id); }
fn get_id(&self) -> Option<i32> { self.id }
fn set_id(&mut self, id: i32) { self.id = Some(id); }
}
impl HasId for Group {
fn get_id(&self) -> Option<u32> { self.id }
fn set_id(&mut self, id: u32) { self.id = Some(id); }
fn get_id(&self) -> Option<i32> { self.id }
fn set_id(&mut self, id: i32) { self.id = Some(id); }
}
impl Contest {
pub fn new(location: String, filename: String, name: String, duration: u32, public: bool,
pub fn new(location: String, filename: String, name: String, duration: i32, public: bool,
start: Option<Timespec>, end: Option<Timespec>)
-> Self
{
......@@ -154,7 +154,7 @@ impl Contest {
}
impl SessionUser {
pub fn minimal(id: u32, session_token: String, csrf_token: String) -> Self {
pub fn minimal(id: i32, session_token: String, csrf_token: String) -> Self {
SessionUser { id: id,
session_token: Some(session_token),
csrf_token: csrf_token,
......@@ -227,7 +227,7 @@ impl Taskgroup {
}
impl Task {
pub fn new(location: String, stars: i8) -> Self {
pub fn new(location: String, stars: i32) -> Self {
Task { id: None, taskgroup: 0, location: location, stars: stars }
}
}
......@@ -14,7 +14,7 @@ use self::bcrypt::hash;
#[derive(Serialize, Deserialize)]
pub struct SubTaskInfo {
pub id: u32,
pub id: i32,
pub linktext: String,
pub active: bool,
pub greyout: bool,
......@@ -28,11 +28,11 @@ pub struct TaskInfo {
#[derive(Serialize, Deserialize)]
pub struct ContestInfo {
pub id: u32,
pub id: i32,
pub location: String,
pub filename: String,
pub name: String,
pub duration: u32,
pub duration: i32,
pub public: bool,
pub tasks: Vec<TaskInfo>,
}
......@@ -151,7 +151,7 @@ pub fn show_contests<T: MedalConnection>(conn: &T) -> MedalValue {
("contests".to_owned(), data)
}
fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<u32>) -> Vec<SubTaskInfo> {
fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<i32>) -> Vec<SubTaskInfo> {
let mut subtaskinfos = Vec::new();
let mut not_print_yet = true;
for st in &tg.tasks {
......@@ -173,7 +173,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<u32>) -> Vec
subtaskinfos
}
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str) -> MedalValueResult {
pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str) -> MedalValueResult {
let c = conn.get_contest_by_id_complete(contest_id);
let grades = conn.get_contest_user_grades(&session_token, contest_id);
......@@ -186,8 +186,8 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
let ti = TaskInfo { name: taskgroup.name, subtasks: subtaskstars };
tasks.push(ti);
totalgrade += i32::from(grade.grade.unwrap_or(0));
max_totalgrade += i32::from(taskgroup.tasks.iter().map(|x| x.stars).max().unwrap_or(0));
totalgrade += grade.grade.unwrap_or(0);
max_totalgrade += taskgroup.tasks.iter().map(|x| x.stars).max().unwrap_or(0);
}
let ci = ContestInfo { id: c.id.unwrap(),
......@@ -249,7 +249,7 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token
}
}
pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str) -> MedalValueResult {
pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str) -> MedalValueResult {
let session = conn.get_session(&session_token)
.ok_or(MedalError::AccessDenied)?
.ensure_alive()
......@@ -303,7 +303,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: u32, sessi
}
//TODO: use csrf_token
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: u32, session_token: &str, _csrf_token: &str)
pub fn start_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token: &str, _csrf_token: &str)
-> MedalResult<()> {
//TODO: use data or remove?
let _data = json_val::Map::new();
......@@ -351,7 +351,7 @@ pub fn logout<T: MedalConnection>(conn: &T, session_token: Option<String>) {
session_token.map(|token| conn.logout(&token));
}
pub fn load_submission<T: MedalConnection>(conn: &T, task_id: u32, session_token: &str, subtask: Option<String>)