Commit 9ba792fa authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Add database columns 'requires_login' and 'secret' to contest

parent 4e5c9c13
Pipeline #545 passed with stage
in 8 minutes and 38 seconds
ALTER TABLE contest ADD COLUMN requires_login BOOL;
ALTER TABLE contest ADD COLUMN secret TEXT;
ALTER TABLE contest ADD COLUMN requires_login INTEGER;
ALTER TABLE contest ADD COLUMN secret TEXT;
......@@ -12,6 +12,9 @@ struct ContestYaml {
duration_minutes: Option<i32>,
public_listing: Option<bool>,
requires_login: Option<bool>,
secret: Option<String>,
min_grade: Option<i32>,
max_grade: Option<i32>,
position: Option<i32>,
......@@ -42,7 +45,9 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
}),
config.min_grade,
config.max_grade,
config.position);
config.position,
config.requires_login,
config.secret);
// TODO: Timeparsing should fail more pleasantly (-> Panic, thus shows message)
for (positionalnumber, (name, info)) in config.tasks?.into_iter().enumerate() {
......
......@@ -111,11 +111,13 @@ impl MedalObject<Connection> for Contest {
let id = match self.get_id() {
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, positionalnumber = $10
WHERE id = $11";
SET location = $2,filename = $3, name = $4, duration = $5, public = $6, start_date = $7,
end_date = $8, min_grade = $9, max_grade = $10, positionalnumber = $11,
requires_login = $12, secret = $13
WHERE id = $1";
conn.execute(query,
&[&self.location,
&[&id,
&self.location,
&self.filename,
&self.name,
&self.duration,
......@@ -125,14 +127,15 @@ impl MedalObject<Connection> for Contest {
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
&self.requires_login,
&self.secret])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade, positionalnumber)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";
min_grade, max_grade, positionalnumber, requires_login, secret)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -143,7 +146,9 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber])
&self.positionalnumber,
&self.requires_login,
&self.secret])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -750,7 +755,7 @@ 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,
positionalnumber
positionalnumber, requires_login, secret
FROM contest
ORDER BY positionalnumber";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -764,12 +769,15 @@ impl MedalConnection for Connection {
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() })
.unwrap()
}
fn get_contest_by_id(&self, contest_id: i32) -> Contest {
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
requires_login, secret
FROM contest
WHERE id = $1";
self.query_map_one(query, &[&contest_id], |row| Contest { id: Some(contest_id),
......@@ -783,6 +791,8 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -790,8 +800,9 @@ impl MedalConnection for Connection {
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name, task.id, task.location, task.stars
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret, 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
......@@ -811,14 +822,16 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() },
Task { id: Some(row.get(11)), taskgroup: row.get(9), location: row.get(12), stars: row.get(13) })
Task { id: Some(row.get(13)), taskgroup: row.get(11), location: row.get(14), stars: row.get(15) })
})
.unwrap();
let mut taskgroupcontest_iter = taskgroupcontest.into_iter();
......@@ -839,8 +852,8 @@ impl MedalConnection for Connection {
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest_secret, taskgroup.id, taskgroup.name
FROM contest
JOIN taskgroup ON contest.id = taskgroup.contest
WHERE contest.id = $1
......@@ -857,10 +870,12 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() })
......@@ -923,7 +938,8 @@ impl MedalConnection for Connection {
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest) {
let query = "SELECT task.location, task.stars, taskgroup.id, taskgroup.name, taskgroup.active, contest.id,
contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret
FROM contest
JOIN taskgroup ON taskgroup.contest = contest.id
JOIN task ON task.taskgroup = taskgroup.id
......@@ -947,6 +963,8 @@ impl MedalConnection for Connection {
min_grade: row.get(13),
max_grade: row.get(14),
positionalnumber: None,
requires_login: row.get(15),
secret: row.get(16),
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -207,11 +207,13 @@ impl MedalObject<Connection> for Contest {
let id = match self.get_id() {
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, positionalnumber = $10
WHERE id = $11";
SET location = $2,filename = $3, name = $4, duration = $5, public = $6, start_date = $7,
end_date = $8, min_grade = $9, max_grade = $10, positionalnumber = $11,
requires_login = $12, secret = $13
WHERE id = $1";
conn.execute(query,
&[&self.location,
&[&id,
&self.location,
&self.filename,
&self.name,
&self.duration,
......@@ -221,14 +223,15 @@ impl MedalObject<Connection> for Contest {
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
&self.requires_login,
&self.secret])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade, positionalnumber)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";
min_grade, max_grade, positionalnumber, requires_login, secret)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -239,7 +242,9 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber])
&self.positionalnumber,
&self.requires_login,
&self.secret])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -846,7 +851,7 @@ 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,
positionalnumber
positionalnumber, requires_login, secret
FROM contest
ORDER BY positionalnumber";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -860,12 +865,15 @@ impl MedalConnection for Connection {
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() })
.unwrap()
}
fn get_contest_by_id(&self, contest_id: i32) -> Contest {
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
requires_login, secret
FROM contest
WHERE id = $1";
self.query_map_one(query, &[&contest_id], |row| Contest { id: Some(contest_id),
......@@ -879,6 +887,8 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -886,8 +896,9 @@ impl MedalConnection for Connection {
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name, task.id, task.location, task.stars
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret, 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
......@@ -907,14 +918,16 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() },
Task { id: Some(row.get(11)), taskgroup: row.get(9), location: row.get(12), stars: row.get(13) })
Task { id: Some(row.get(13)), taskgroup: row.get(11), location: row.get(14), stars: row.get(15) })
})
.unwrap();
let mut taskgroupcontest_iter = taskgroupcontest.into_iter();
......@@ -935,8 +948,8 @@ impl MedalConnection for Connection {
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest_secret, taskgroup.id, taskgroup.name
FROM contest
JOIN taskgroup ON contest.id = taskgroup.contest
WHERE contest.id = $1
......@@ -953,10 +966,12 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() })
......@@ -1019,7 +1034,8 @@ impl MedalConnection for Connection {
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest) {
let query = "SELECT task.location, task.stars, taskgroup.id, taskgroup.name, taskgroup.active, contest.id,
contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret
FROM contest
JOIN taskgroup ON taskgroup.contest = contest.id
JOIN task ON task.taskgroup = taskgroup.id
......@@ -1043,6 +1059,8 @@ impl MedalConnection for Connection {
min_grade: row.get(13),
max_grade: row.get(14),
positionalnumber: None,
requires_login: row.get(15),
secret: row.get(16),
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -207,11 +207,13 @@ impl MedalObject<Connection> for Contest {
let id = match self.get_id() {
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, positionalnumber = ?10
WHERE id = ?11";
SET location = ?2,filename = ?3, name = ?4, duration = ?5, public = ?6, start_date = ?7,
end_date = ?8, min_grade = ?9, max_grade = ?10, positionalnumber = ?11,
requires_login = ?12, secret = ?13
WHERE id = ?1";
conn.execute(query,
&[&self.location,
&[&id,
&self.location,
&self.filename,
&self.name,
&self.duration,
......@@ -221,14 +223,15 @@ impl MedalObject<Connection> for Contest {
&self.min_grade,
&self.max_grade,
&self.positionalnumber,
&id])
&self.requires_login,
&self.secret])
.unwrap();
id
}
None => {
let query = "INSERT INTO contest (location, filename, name, duration, public, start_date, end_date,
min_grade, max_grade, positionalnumber)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
min_grade, max_grade, positionalnumber, requires_login, secret)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)";
conn.execute(query,
&[&self.location,
&self.filename,
......@@ -239,7 +242,9 @@ impl MedalObject<Connection> for Contest {
&self.end,
&self.min_grade,
&self.max_grade,
&self.positionalnumber])
&self.positionalnumber,
&self.requires_login,
&self.secret])
.unwrap();
conn.get_last_id().unwrap()
}
......@@ -846,7 +851,7 @@ 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,
positionalnumber
positionalnumber, requires_login, secret
FROM contest
ORDER BY positionalnumber";
self.query_map_many(query, &[], |row| Contest { id: Some(row.get(0)),
......@@ -860,12 +865,15 @@ impl MedalConnection for Connection {
min_grade: row.get(8),
max_grade: row.get(9),
positionalnumber: row.get(10),
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() })
.unwrap()
}
fn get_contest_by_id(&self, contest_id: i32) -> Contest {
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade
let query = "SELECT location, filename, name, duration, public, start_date, end_date, min_grade, max_grade,
requires_login, secret
FROM contest
WHERE id = ?1";
self.query_map_one(query, &[&contest_id], |row| Contest { id: Some(contest_id),
......@@ -879,6 +887,8 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() })
.unwrap()
.unwrap() // TODO: Should return Option?
......@@ -886,8 +896,9 @@ impl MedalConnection for Connection {
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name, task.id, task.location, task.stars
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret, 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
......@@ -907,14 +918,16 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() },
Task { id: Some(row.get(11)), taskgroup: row.get(9), location: row.get(12), stars: row.get(13) })
Task { id: Some(row.get(13)), taskgroup: row.get(11), location: row.get(14), stars: row.get(15) })
})
.unwrap();
let mut taskgroupcontest_iter = taskgroupcontest.into_iter();
......@@ -935,8 +948,8 @@ impl MedalConnection for Connection {
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest {
let query = "SELECT contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade, taskgroup.id,
taskgroup.name
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest_secret, taskgroup.id, taskgroup.name
FROM contest
JOIN taskgroup ON contest.id = taskgroup.contest
WHERE contest.id = ?1
......@@ -953,10 +966,12 @@ impl MedalConnection for Connection {
min_grade: row.get(7),
max_grade: row.get(8),
positionalnumber: None,
requires_login: row.get(9),
secret: row.get(10),
taskgroups: Vec::new() },
Taskgroup { id: Some(row.get(9)),
Taskgroup { id: Some(row.get(11)),
contest: contest_id,
name: row.get(10),
name: row.get(12),
active: true,
positionalnumber: None,
tasks: Vec::new() })
......@@ -1019,7 +1034,8 @@ impl MedalConnection for Connection {
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest) {
let query = "SELECT task.location, task.stars, taskgroup.id, taskgroup.name, taskgroup.active, contest.id,
contest.location, contest.filename, contest.name, contest.duration, contest.public,
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade
contest.start_date, contest.end_date, contest.min_grade, contest.max_grade,
contest.requires_login, contest.secret
FROM contest
JOIN taskgroup ON taskgroup.contest = contest.id
JOIN task ON task.taskgroup = taskgroup.id
......@@ -1043,6 +1059,8 @@ impl MedalConnection for Connection {
min_grade: row.get(13),
max_grade: row.get(14),
positionalnumber: None,
requires_login: row.get(15),
secret: row.get(16),
taskgroups: Vec::new() })
})
.unwrap()
......
......@@ -73,6 +73,8 @@ pub struct Contest {
pub min_grade: Option<i32>,
pub max_grade: Option<i32>,
pub positionalnumber: Option<i32>,
pub requires_login: Option<bool>,
pub secret: Option<String>,
pub taskgroups: Vec<Taskgroup>,
}
......@@ -151,7 +153,7 @@ impl Contest {
#[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>,
positionalnumber: Option<i32>)
positionalnumber: Option<i32>, requires_login: Option<bool>, secret: Option<String>)
-> Self
{
Contest { id: None,
......@@ -165,6 +167,8 @@ impl Contest {
min_grade: min_grade,
max_grade: max_grade,
positionalnumber: positionalnumber,
requires_login: requires_login,
secret: secret,
taskgroups: Vec::new() }
}
}
......
......@@ -274,6 +274,8 @@ mod tests {
None,
None,
None,
None,
None,
None);
contest.save(&conn);
......@@ -287,6 +289,8 @@ mod tests {
None,
None,
None,
None,
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 1
......@@ -306,6 +310,8 @@ mod tests {
None,
None,
None,
None,
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 3
......@@ -325,6 +331,8 @@ mod tests {
None,
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