Commit 8fb09f4f authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Add contest lists of contests with login required (challenges)

parent 9ba792fa
Pipeline #546 passed with stage
in 7 minutes and 40 seconds
...@@ -28,6 +28,7 @@ pub struct ContestInfo { ...@@ -28,6 +28,7 @@ pub struct ContestInfo {
pub name: String, pub name: String,
pub duration: i32, pub duration: i32,
pub public: bool, pub public: bool,
pub login_required: bool,
} }
#[derive(Clone)] #[derive(Clone)]
...@@ -151,6 +152,7 @@ pub enum ContestVisibility { ...@@ -151,6 +152,7 @@ pub enum ContestVisibility {
All, All,
Open, Open,
Current, Current,
LoginRequired,
} }
pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str, pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
...@@ -182,16 +184,19 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str, ...@@ -182,16 +184,19 @@ pub fn show_contests<T: MedalConnection>(conn: &T, session_token: &str,
let v: Vec<ContestInfo> = let v: Vec<ContestInfo> =
conn.get_contest_list() conn.get_contest_list()
.iter() .iter()
.map(|c| ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public }) .map(|c| ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public, login_required: c.requires_login.unwrap_or(false) })
.filter(|ci| ci.public) .filter(|ci| ci.public)
.filter(|ci| ci.duration == 0 || visibility != ContestVisibility::Open) .filter(|ci| ci.duration == 0 || visibility != ContestVisibility::Open)
.filter(|ci| ci.duration != 0 || visibility != ContestVisibility::Current) .filter(|ci| ci.duration != 0 || visibility != ContestVisibility::Current)
.filter(|ci| ci.login_required || visibility != ContestVisibility::LoginRequired)
.filter(|ci| !ci.login_required || visibility == ContestVisibility::LoginRequired)
.collect(); .collect();
data.insert("contest".to_string(), to_json(&v)); data.insert("contest".to_string(), to_json(&v));
data.insert("contestlist_header".to_string(), data.insert("contestlist_header".to_string(),
to_json(&match visibility { to_json(&match visibility {
ContestVisibility::Open => "Trainingsaufgaben", ContestVisibility::Open => "Trainingsaufgaben",
ContestVisibility::Current => "Aktuelle Wettbewerbe", ContestVisibility::Current => "Aktuelle Wettbewerbe",
ContestVisibility::LoginRequired => "Herausforderungen",
ContestVisibility::All => "Alle Wettbewerbe", ContestVisibility::All => "Alle Wettbewerbe",
})); }));
...@@ -274,7 +279,8 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token ...@@ -274,7 +279,8 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
let ci = ContestInfo { id: contest.id.unwrap(), let ci = ContestInfo { id: contest.id.unwrap(),
name: contest.name.clone(), name: contest.name.clone(),
duration: contest.duration, duration: contest.duration,
public: contest.public }; public: contest.public,
login_required: contest.requires_login.unwrap_or(false)};
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
data.insert("contest".to_string(), to_json(&ci)); data.insert("contest".to_string(), to_json(&ci));
...@@ -413,7 +419,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi ...@@ -413,7 +419,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
data.insert("result".to_string(), to_json(&results)); data.insert("result".to_string(), to_json(&results));
let c = conn.get_contest_by_id(contest_id); let c = conn.get_contest_by_id(contest_id);
let ci = ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public }; let ci = ContestInfo { id: c.id.unwrap(), name: c.name.clone(), duration: c.duration, public: c.public, login_required: c.requires_login.unwrap_or(false)};
data.insert("contest".to_string(), to_json(&ci)); data.insert("contest".to_string(), to_json(&ci));
data.insert("contestname".to_string(), to_json(&c.name)); data.insert("contestname".to_string(), to_json(&c.name));
......
...@@ -378,6 +378,8 @@ fn contests<C>(req: &mut Request) -> IronResult<Response> ...@@ -378,6 +378,8 @@ fn contests<C>(req: &mut Request) -> IronResult<Response>
core::ContestVisibility::Open core::ContestVisibility::Open
} else if query_string.contains("current") { } else if query_string.contains("current") {
core::ContestVisibility::Current core::ContestVisibility::Current
} else if query_string.contains("challenge") {
core::ContestVisibility::LoginRequired
} else { } else {
core::ContestVisibility::All core::ContestVisibility::All
}; };
......
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