Commit df6c85a6 authored by Robert Czechowski's avatar Robert Czechowski

New database fields positionalnumber in contest: Add in object relation mapping

parent 9f72a703
......@@ -14,6 +14,7 @@ struct ContestYaml {
min_grade: Option<i32>,
max_grade: Option<i32>,
position: Option<i32>,
tasks: Option<serde_yaml::Mapping>,
}
......@@ -40,7 +41,8 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
strptime(&x, &"%FT%T%z").map(|t| t.to_timespec()).unwrap_or_else(|_| Timespec::new(0, 0))
}),
config.min_grade,
config.max_grade);
config.max_grade,
config.position);
// TODO: Timeparsing should fail more pleasantly (-> Panic, thus shows message)
for (positionalnumber, (name, info)) in config.tasks?.into_iter().enumerate() {
......
......@@ -112,8 +112,8 @@ impl MedalObject<Connection> for Contest {
Some(id) => {
let query = "UPDATE contest
SET location = $1,filename = $2, name = $3, duration = $4, public = $5, start_date = $6,
end_date = $7, min_grade = $8, max_grade = $9
WHERE id = $10";
end_date = $7, min_grade = $8, max_grade = $9, positionalnumber = $10
WHERE id = $11";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -124,14 +124,15 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)";
min_grade, max_grade, positionalnumber)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -141,7 +142,8 @@ impl MedalObject<Connection> for Contest {
&self.start,
&self.end,
&self.min_grade,
&self.max_grade])
&self.max_grade,
&self.positionalnumber])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -720,7 +722,8 @@ impl MedalConnection for Connection {
}
fn get_contest_list(&self) -> Vec<Contest> {
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
positionalnumber
FROM contest
ORDER BY id";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -733,6 +736,7 @@ impl MedalConnection for Connection {
end: row.get(7),
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
taskgroups: Vec::new() })
.unwrap()
}
......@@ -751,6 +755,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -777,6 +782,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -820,6 +826,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -907,6 +914,7 @@ impl MedalConnection for Connection {
end: row.get(11),
min_grade: row.get(12),
max_grade: row.get(13),
positionalnumber: None,
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -208,8 +208,8 @@ impl MedalObject<Connection> for Contest {
Some(id) => {
let query = "UPDATE contest
SET location = $1,filename = $2, name = $3, duration = $4, public = $5, start_date = $6,
end_date = $7, min_grade = $8, max_grade = $9
WHERE id = $10";
end_date = $7, min_grade = $8, max_grade = $9, positionalnumber = $10
WHERE id = $11";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -220,14 +220,15 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)";
min_grade, max_grade, positionalnumber)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -237,7 +238,8 @@ impl MedalObject<Connection> for Contest {
&self.start,
&self.end,
&self.min_grade,
&self.max_grade])
&self.max_grade,
&self.positionalnumber])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -816,7 +818,8 @@ impl MedalConnection for Connection {
}
fn get_contest_list(&self) -> Vec<Contest> {
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
positionalnumber
FROM contest
ORDER BY id";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -829,6 +832,7 @@ impl MedalConnection for Connection {
end: row.get(7),
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
taskgroups: Vec::new() })
.unwrap()
}
......@@ -847,6 +851,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -873,6 +878,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -916,6 +922,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -1003,6 +1010,7 @@ impl MedalConnection for Connection {
end: row.get(11),
min_grade: row.get(12),
max_grade: row.get(13),
positionalnumber: None,
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -195,8 +195,8 @@ impl MedalObject<Connection> for Contest {
Some(id) => {
let query = "UPDATE contest
SET location = ?1,filename = ?2, name = ?3, duration = ?4, public = ?5, start_date = ?6,
end_date = ?7, min_grade = ?8, max_grade = ?9
WHERE id = ?10";
end_date = ?7, min_grade = ?8, max_grade = ?9, positionalnumber = ?10,
WHERE id = ?11";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -207,14 +207,15 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)";
min_grade, max_grade, positionalnumber)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -224,7 +225,8 @@ impl MedalObject<Connection> for Contest {
&self.start,
&self.end,
&self.min_grade,
&self.max_grade])
&self.max_grade,
&self.positionalnumber])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -803,7 +805,8 @@ impl MedalConnection for Connection {
}
fn get_contest_list(&self) -> Vec<Contest> {
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
positionalnumber
FROM contest
ORDER BY id";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -816,6 +819,7 @@ impl MedalConnection for Connection {
end: row.get(7),
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
taskgroups: Vec::new() })
.unwrap()
}
......@@ -834,6 +838,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -860,6 +865,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -903,6 +909,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -990,6 +997,7 @@ impl MedalConnection for Connection {
end: row.get(11),
min_grade: row.get(12),
max_grade: row.get(13),
positionalnumber: None,
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -208,8 +208,8 @@ impl MedalObject<Connection> for Contest {
Some(id) => {
let query = "UPDATE contest
SET location = ?1,filename = ?2, name = ?3, duration = ?4, public = ?5, start_date = ?6,
end_date = ?7, min_grade = ?8, max_grade = ?9
WHERE id = ?10";
end_date = ?7, min_grade = ?8, max_grade = ?9, positionalnumber = ?10
WHERE id = ?11";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -220,14 +220,15 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)";
min_grade, max_grade, positionalnumber)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -237,7 +238,8 @@ impl MedalObject<Connection> for Contest {
&self.start,
&self.end,
&self.min_grade,
&self.max_grade])
&self.max_grade,
&self.positionalnumber])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -816,7 +818,8 @@ impl MedalConnection for Connection {
}
fn get_contest_list(&self) -> Vec<Contest> {
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT id, location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
positionalnumber
FROM contest
ORDER BY id";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -829,6 +832,7 @@ impl MedalConnection for Connection {
end: row.get(7),
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
taskgroups: Vec::new() })
.unwrap()
}
......@@ -847,6 +851,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -873,6 +878,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -916,6 +922,7 @@ impl MedalConnection for Connection {
end: row.get(6),
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
contest: contest_id,
......@@ -1003,6 +1010,7 @@ impl MedalConnection for Connection {
end: row.get(11),
min_grade: row.get(12),
max_grade: row.get(13),
positionalnumber: None,
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -70,6 +70,7 @@ pub struct Contest {
pub end: Option<Timespec>,
pub min_grade: Option<i32>,
pub max_grade: Option<i32>,
pub positionalnumber: Option<i32>,
pub taskgroups: Vec<Taskgroup>,
}
......@@ -146,7 +147,8 @@ impl Contest {
// TODO: Rewrite, so this attribute can be removed
#[allow(clippy::too_many_arguments)]
pub fn new(location: String, filename: String, name: String, duration: i32, public: bool,
start: Option<Timespec>, end: Option<Timespec>, min_grade: Option<i32>, max_grade: Option<i32>)
start: Option<Timespec>, end: Option<Timespec>, min_grade: Option<i32>, max_grade: Option<i32>,
positionalnumber: Option<i32>)
-> Self
{
Contest { id: None,
......@@ -159,6 +161,7 @@ impl Contest {
end: end,
min_grade: min_grade,
max_grade: max_grade,
positionalnumber: positionalnumber,
taskgroups: Vec::new() }
}
}
......
......@@ -273,6 +273,7 @@ mod tests {
None,
None,
None,
None,
None);
contest.save(&conn);
......@@ -285,6 +286,7 @@ mod tests {
None,
None,
None,
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 1
......@@ -303,6 +305,7 @@ mod tests {
None,
None,
None,
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 3
......@@ -321,6 +324,7 @@ mod tests {
None,
None,
None,
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupRenameName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 5
......
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