Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
26effac5
Commit
26effac5
authored
Apr 09, 2019
by
Robert Czechowski
Browse files
Rustfmt ALL the code!
parent
598119ab
Pipeline
#70
failed with stage
in 1 minute and 29 seconds
Changes
8
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
src/configreader_yaml.rs
View file @
26effac5
use
db_objects
::{
Contest
,
Task
group
,
Task
};
use
db_objects
::{
Contest
,
Task
,
Task
group
};
use
serde_yaml
;
use
serde_yaml
;
...
@@ -9,19 +9,22 @@ struct ContestYaml {
...
@@ -9,19 +9,22 @@ struct ContestYaml {
participation_end
:
Option
<
String
>
,
participation_end
:
Option
<
String
>
,
duration_minutes
:
Option
<
u32
>
,
duration_minutes
:
Option
<
u32
>
,
public_listing
:
Option
<
bool
>
,
public_listing
:
Option
<
bool
>
,
tasks
:
Option
<
serde_yaml
::
Mapping
>
,
tasks
:
Option
<
serde_yaml
::
Mapping
>
,
}
}
// The task path is stored relatively to the contest.yaml for easier identificationy
// The task path is stored relatively to the contest.yaml for easier identificationy
// Concatenation happens in functions::show_task
// Concatenation happens in functions::show_task
pub
fn
parse_yaml
(
content
:
&
str
,
filename
:
&
str
,
directory
:
&
str
)
->
Option
<
Contest
>
{
pub
fn
parse_yaml
(
content
:
&
str
,
filename
:
&
str
,
directory
:
&
str
)
->
Option
<
Contest
>
{
let
config
:
ContestYaml
=
serde_yaml
::
from_str
(
&
content
)
.unwrap
();
let
config
:
ContestYaml
=
serde_yaml
::
from_str
(
&
content
)
.unwrap
();
let
mut
contest
=
Contest
::
new
(
directory
.to_string
(),
filename
.to_string
(),
config
.name
?
,
config
.duration_minutes
?
,
config
.public_listing
.unwrap_or
(
false
),
None
,
None
);
let
mut
contest
=
Contest
::
new
(
directory
.to_string
(),
filename
.to_string
(),
config
.name
?
,
config
.duration_minutes
?
,
config
.public_listing
.unwrap_or
(
false
),
None
,
None
);
for
(
name
,
info
)
in
config
.tasks
?
{
for
(
name
,
info
)
in
config
.tasks
?
{
if
let
serde_yaml
::
Value
::
String
(
name
)
=
name
{
if
let
serde_yaml
::
Value
::
String
(
name
)
=
name
{
...
@@ -30,46 +33,46 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
...
@@ -30,46 +33,46 @@ pub fn parse_yaml(content: &str, filename: &str, directory: &str) -> Option<Cont
serde_yaml
::
Value
::
String
(
taskdir
)
=>
{
serde_yaml
::
Value
::
String
(
taskdir
)
=>
{
let
mut
task
=
Task
::
new
(
taskdir
,
3
);
let
mut
task
=
Task
::
new
(
taskdir
,
3
);
taskgroup
.tasks
.push
(
task
);
taskgroup
.tasks
.push
(
task
);
}
,
}
serde_yaml
::
Value
::
Sequence
(
taskdirs
)
=>
{
serde_yaml
::
Value
::
Sequence
(
taskdirs
)
=>
{
let
mut
stars
=
2
;
let
mut
stars
=
2
;
for
taskdir
in
taskdirs
{
for
taskdir
in
taskdirs
{
if
let
serde_yaml
::
Value
::
String
(
taskdir
)
=
taskdir
{
if
let
serde_yaml
::
Value
::
String
(
taskdir
)
=
taskdir
{
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
taskgroup
.tasks
.push
(
task
);
taskgroup
.tasks
.push
(
task
);
}
}
else
{
else
{
panic!
(
"Invalid contest YAML: {}{} (a)"
,
directory
,
filename
)
panic!
(
"Invalid contest YAML: {}{} (a)"
,
directory
,
filename
)
}
}
stars
+=
1
;
stars
+=
1
;
}
}
}
}
serde_yaml
::
Value
::
Mapping
(
taskdirs
)
=>
{
serde_yaml
::
Value
::
Mapping
(
taskdirs
)
=>
{
let
mut
stars
=
2
;
let
mut
stars
=
2
;
for
(
taskdir
,
taskinfo
)
in
taskdirs
{
for
(
taskdir
,
taskinfo
)
in
taskdirs
{
if
let
(
serde_yaml
::
Value
::
String
(
taskdir
),
serde_yaml
::
Value
::
Mapping
(
taskinfo
))
=
(
taskdir
,
taskinfo
)
{
if
let
(
serde_yaml
::
Value
::
String
(
taskdir
),
serde_yaml
::
Value
::
Mapping
(
taskinfo
))
=
if
let
Some
(
serde_yaml
::
Value
::
Number
(
cstars
))
=
taskinfo
.get
(
&
serde_yaml
::
Value
::
String
(
"stars"
.to_string
()))
{
(
taskdir
,
taskinfo
)
{
if
let
Some
(
serde_yaml
::
Value
::
Number
(
cstars
))
=
taskinfo
.get
(
&
serde_yaml
::
Value
::
String
(
"stars"
.to_string
()))
{
stars
=
cstars
.as_u64
()
.unwrap
()
as
u8
;
stars
=
cstars
.as_u64
()
.unwrap
()
as
u8
;
}
}
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
let
mut
task
=
Task
::
new
(
taskdir
,
stars
);
taskgroup
.tasks
.push
(
task
);
taskgroup
.tasks
.push
(
task
);
stars
+=
1
;
stars
+=
1
;
}
}
else
{
else
{
panic!
(
"Invalid contest YAML: {}{} (b)"
,
directory
,
filename
)
panic!
(
"Invalid contest YAML: {}{} (b)"
,
directory
,
filename
)
}
}
}
}
}
}
_
=>
panic!
(
"Invalid contest YAML: {}{} (c)"
,
directory
,
filename
)
_
=>
panic!
(
"Invalid contest YAML: {}{} (c)"
,
directory
,
filename
)
,
}
}
contest
.taskgroups
.push
(
taskgroup
);
contest
.taskgroups
.push
(
taskgroup
);
}
}
else
{
else
{
panic!
(
"Invalid contest YAML: {}{} (d)"
,
directory
,
filename
)
panic!
(
"Invalid contest YAML: {}{} (d)"
,
directory
,
filename
)
}
}
}
}
Some
(
contest
)
Some
(
contest
)
}
}
src/db_apply_migrations.rs
View file @
26effac5
...
@@ -3,22 +3,19 @@ use std::io::Read;
...
@@ -3,22 +3,19 @@ use std::io::Read;
use
db_conn
::
MedalConnection
;
use
db_conn
::
MedalConnection
;
pub
fn
test
<
C
:
MedalConnection
>
(
conn
:
&
mut
C
)
{
pub
fn
test
<
C
:
MedalConnection
>
(
conn
:
&
mut
C
)
{
let
mut
paths
:
Vec
<
_
>
=
let
mut
paths
:
Vec
<
_
>
=
fs
::
read_dir
(
format!
(
"migrations/{}"
,
conn
.dbtype
()))
fs
::
read_dir
(
format!
(
"migrations/{}"
,
conn
.dbtype
()))
.unwrap
()
.unwrap
()
.map
(|
r
|
r
.unwrap
())
.map
(|
r
|
r
.unwrap
())
.filter
(|
r
|
{
.filter
(|
r
|
r
.path
()
r
.path
()
.display
()
.to_string
()
.ends_with
(
".sql"
)
.display
()
})
.to_string
()
.collect
();
.ends_with
(
".sql"
))
.collect
();
paths
.sort_by_key
(|
dir
|
dir
.path
());
paths
.sort_by_key
(|
dir
|
dir
.path
());
for
path
in
paths
{
for
path
in
paths
{
let
filename
=
path
.file_name
()
.into_string
()
.unwrap
();
let
filename
=
path
.file_name
()
.into_string
()
.unwrap
();
if
!
conn
.migration_already_applied
(
&
filename
)
{
if
!
conn
.migration_already_applied
(
&
filename
)
{
let
mut
file
=
fs
::
File
::
open
(
path
.path
())
.unwrap
();
let
mut
file
=
fs
::
File
::
open
(
path
.path
())
.unwrap
();
let
mut
contents
=
String
::
new
();
let
mut
contents
=
String
::
new
();
file
.read_to_string
(
&
mut
contents
)
.unwrap
();
file
.read_to_string
(
&
mut
contents
)
.unwrap
();
...
@@ -28,8 +25,5 @@ pub fn test<C: MedalConnection>(conn: &mut C) {
...
@@ -28,8 +25,5 @@ pub fn test<C: MedalConnection>(conn: &mut C) {
/*else { // TODO: Show in high debug level only
/*else { // TODO: Show in high debug level only
println!("Found: {}. Already applied", path.path().display());
println!("Found: {}. Already applied", path.path().display());
}*/
}*/
}
}
}
}
src/db_conn.rs
View file @
26effac5
use
db_objects
::
*
;
use
db_objects
::
*
;
use
::
functions
;
use
functions
;
use
std
::
path
::
{
Path
}
;
use
std
::
path
::
Path
;
pub
trait
MedalConnection
{
pub
trait
MedalConnection
{
fn
create
(
file
:
&
Path
)
->
Self
;
fn
create
(
file
:
&
Path
)
->
Self
;
...
@@ -19,21 +19,24 @@ pub trait MedalConnection {
...
@@ -19,21 +19,24 @@ pub trait MedalConnection {
//fn login(&self, session: &SessionUser, username: String, password: String) -> Result<String,()>;
//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
(
&
self
,
session
:
Option
<&
str
>
,
username
:
&
str
,
password
:
&
str
)
->
Result
<
String
,
()
>
;
fn
login_with_code
(
&
self
,
session
:
Option
<&
str
>
,
logincode
:
&
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
,
firstname
:
&
str
,
lastname
:
&
str
)
->
Result
<
String
,()
>
;
fn
login_foreign
(
&
self
,
session
:
Option
<&
str
>
,
foreign_id
:
u32
,
foreign_type
:
functions
::
UserType
,
fn
create_user_with_groupcode
(
&
self
,
session
:
Option
<&
str
>
,
groupcode
:
&
str
)
->
Result
<
String
,()
>
;
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
logout
(
&
self
,
session
:
&
str
);
fn
load_submission
(
&
self
,
session
:
&
SessionUser
,
task
:
u32
,
subtask
:
Option
<&
str
>
)
->
Option
<
Submission
>
;
fn
load_submission
(
&
self
,
session
:
&
SessionUser
,
task
:
u32
,
subtask
:
Option
<&
str
>
)
->
Option
<
Submission
>
;
fn
submit_submission
(
&
self
,
submission
:
Submission
);
fn
submit_submission
(
&
self
,
submission
:
Submission
);
fn
get_grade_by_submission
(
&
self
,
submission_id
:
u32
)
->
Grade
;
fn
get_grade_by_submission
(
&
self
,
submission_id
:
u32
)
->
Grade
;
fn
get_contest_groups_grades
(
&
self
,
session_id
:
u32
,
contest_id
:
u32
)
->
(
Vec
<
String
>
,
Vec
<
(
Group
,
Vec
<
(
UserInfo
,
Vec
<
Grade
>
)
>
)
>
);
fn
get_contest_groups_grades
(
&
self
,
session_id
:
u32
,
contest_id
:
u32
)
->
(
Vec
<
String
>
,
Vec
<
(
Group
,
Vec
<
(
UserInfo
,
Vec
<
Grade
>
)
>
)
>
);
fn
get_contest_user_grades
(
&
self
,
session
:
String
,
contest_id
:
u32
)
->
Vec
<
Grade
>
;
fn
get_contest_user_grades
(
&
self
,
session
:
String
,
contest_id
:
u32
)
->
Vec
<
Grade
>
;
fn
get_contest_list
(
&
self
)
->
Vec
<
Contest
>
;
fn
get_contest_list
(
&
self
)
->
Vec
<
Contest
>
;
fn
get_contest_by_id
(
&
self
,
contest_id
:
u32
)
->
Contest
;
fn
get_contest_by_id
(
&
self
,
contest_id
:
u32
)
->
Contest
;
fn
get_contest_by_id_complete
(
&
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
get_participation
(
&
self
,
session
:
&
str
,
contest_id
:
u32
)
->
Option
<
Participation
>
;
fn
new_participation
(
&
self
,
session
:
&
str
,
contest_id
:
u32
)
->
Result
<
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
(
&
self
,
task_id
:
u32
)
->
Task
;
...
@@ -48,7 +51,6 @@ pub trait MedalConnection {
...
@@ -48,7 +51,6 @@ pub trait MedalConnection {
fn
get_group_complete
(
&
self
,
group_id
:
u32
)
->
Option
<
Group
>
;
fn
get_group_complete
(
&
self
,
group_id
:
u32
)
->
Option
<
Group
>
;
}
}
pub
trait
MedalObject
<
T
:
MedalConnection
>
{
pub
trait
MedalObject
<
T
:
MedalConnection
>
{
fn
save
(
&
mut
self
,
conn
:
&
T
);
fn
save
(
&
mut
self
,
conn
:
&
T
);
}
}
src/db_conn_sqlite.rs
View file @
26effac5
This diff is collapsed.
Click to expand it.
src/db_objects.rs
View file @
26effac5
extern
crate
time
;
extern
crate
time
;
use
self
::
time
::{
Timespec
,
Duration
};
use
self
::
time
::{
Duration
,
Timespec
};
#[derive(Clone)]
#[derive(Clone)]
pub
struct
SessionUser
{
pub
struct
SessionUser
{
...
@@ -11,7 +10,7 @@ pub struct SessionUser {
...
@@ -11,7 +10,7 @@ pub struct SessionUser {
pub
last_login
:
Option
<
Timespec
>
,
pub
last_login
:
Option
<
Timespec
>
,
pub
last_activity
:
Option
<
Timespec
>
,
pub
last_activity
:
Option
<
Timespec
>
,
pub
permanent_login
:
bool
,
pub
permanent_login
:
bool
,
pub
username
:
Option
<
String
>
,
pub
username
:
Option
<
String
>
,
pub
password
:
Option
<
String
>
,
pub
password
:
Option
<
String
>
,
pub
salt
:
Option
<
String
>
,
pub
salt
:
Option
<
String
>
,
...
@@ -51,7 +50,7 @@ pub struct Group {
...
@@ -51,7 +50,7 @@ pub struct Group {
pub
groupcode
:
String
,
pub
groupcode
:
String
,
pub
tag
:
String
,
pub
tag
:
String
,
pub
admin
:
u32
,
pub
admin
:
u32
,
pub
members
:
Vec
<
SessionUser
>
pub
members
:
Vec
<
SessionUser
>
,
}
}
pub
struct
Contest
{
pub
struct
Contest
{
...
@@ -66,7 +65,6 @@ pub struct Contest {
...
@@ -66,7 +65,6 @@ pub struct Contest {
pub
taskgroups
:
Vec
<
Taskgroup
>
,
pub
taskgroups
:
Vec
<
Taskgroup
>
,
}
}
pub
struct
Taskgroup
{
pub
struct
Taskgroup
{
pub
id
:
Option
<
u32
>
,
pub
id
:
Option
<
u32
>
,
pub
contest
:
u32
,
pub
contest
:
u32
,
...
@@ -81,7 +79,6 @@ pub struct Task {
...
@@ -81,7 +79,6 @@ pub struct Task {
pub
stars
:
u8
,
pub
stars
:
u8
,
}
}
pub
struct
Submission
{
pub
struct
Submission
{
pub
id
:
Option
<
u32
>
,
pub
id
:
Option
<
u32
>
,
pub
session_user
:
u32
,
pub
session_user
:
u32
,
...
@@ -109,63 +106,78 @@ pub struct Participation {
...
@@ -109,63 +106,78 @@ pub struct Participation {
pub
start
:
Timespec
,
pub
start
:
Timespec
,
}
}
pub
trait
HasId
{
fn
get_id
(
&
self
)
->
Option
<
u32
>
;
fn
set_id
(
&
mut
self
,
id
:
u32
);
}
pub
trait
HasId
{
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
<
u32
>
;
impl
HasId
for
Task
{
fn
get_id
(
&
self
)
->
Option
<
u32
>
{
self
.id
}
fn
set_id
(
&
mut
self
,
id
:
u32
)
{
self
.id
=
Some
(
id
);}
}
fn
set_id
(
&
mut
self
,
id
:
u32
);
impl
HasId
for
Taskgroup
{
fn
get_id
(
&
self
)
->
Option
<
u32
>
{
self
.id
}
fn
set_id
(
&
mut
self
,
id
:
u32
)
{
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
);}
}
impl
HasId
for
Submission
{
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
<
u32
>
{
self
.id
}
fn
set_id
(
&
mut
self
,
id
:
u32
)
{
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
);
}
}
impl
HasId
for
Taskgroup
{
fn
get_id
(
&
self
)
->
Option
<
u32
>
{
self
.id
}
fn
set_id
(
&
mut
self
,
id
:
u32
)
{
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
);
}
}
impl
HasId
for
Group
{
fn
get_id
(
&
self
)
->
Option
<
u32
>
{
self
.id
}
fn
set_id
(
&
mut
self
,
id
:
u32
)
{
self
.id
=
Some
(
id
);
}
}
impl
Contest
{
impl
Contest
{
pub
fn
new
(
location
:
String
,
filename
:
String
,
name
:
String
,
duration
:
u32
,
public
:
bool
,
start
:
Option
<
Timespec
>
,
end
:
Option
<
Timespec
>
)
->
Self
{
pub
fn
new
(
location
:
String
,
filename
:
String
,
name
:
String
,
duration
:
u32
,
public
:
bool
,
Contest
{
start
:
Option
<
Timespec
>
,
end
:
Option
<
Timespec
>
)
id
:
None
,
->
Self
location
:
location
,
{
filename
:
filenam
e
,
Contest
{
id
:
Non
e
,
name
:
name
,
location
:
location
,
duration
:
duration
,
filename
:
filename
,
public
:
public
,
name
:
name
,
start
:
start
,
duration
:
duration
,
end
:
end
,
public
:
public
,
taskgroups
:
Vec
::
new
()
,
start
:
start
,
end
:
end
,
}
taskgroups
:
Vec
::
new
()
}
}
}
}
}
impl
SessionUser
{
impl
SessionUser
{
pub
fn
minimal
(
id
:
u32
,
session_token
:
String
,
csrf_token
:
String
)
->
Self
{
pub
fn
minimal
(
id
:
u32
,
session_token
:
String
,
csrf_token
:
String
)
->
Self
{
SessionUser
{
SessionUser
{
id
:
id
,
id
:
id
,
session_token
:
Some
(
session_token
),
session_token
:
Some
(
session_token
),
csrf_token
:
csrf_token
,
csrf_token
:
csrf_token
,
last_login
:
None
,
last_login
:
None
,
last_activity
:
None
,
// now?
last_activity
:
None
,
// now?
// müssen die überhaupt außerhalb der datenbankabstraktion sichtbar sein?
// müssen die überhaupt außerhalb der datenbankabstraktion sichtbar sein?
permanent_login
:
false
,
permanent_login
:
false
,
username
:
None
,
username
:
None
,
password
:
None
,
password
:
None
,
salt
:
None
,
salt
:
None
,
logincode
:
None
,
logincode
:
None
,
email
:
None
,
email
:
None
,
email_unconfirmed
:
None
,
email_unconfirmed
:
None
,
email_confirmationcode
:
None
,
email_confirmationcode
:
None
,
firstname
:
None
,
firstname
:
None
,
lastname
:
None
,
lastname
:
None
,
street
:
None
,
street
:
None
,
zip
:
None
,
zip
:
None
,
city
:
None
,
city
:
None
,
nation
:
None
,
nation
:
None
,
grade
:
0
,
grade
:
0
,
is_teacher
:
false
,
is_teacher
:
false
,
managed_by
:
None
,
managed_by
:
None
,
pms_id
:
None
,
pms_id
:
None
,
pms_school_id
:
None
}
pms_school_id
:
None
,
}
}
}
pub
fn
ensure_alive
(
self
)
->
Option
<
Self
>
{
pub
fn
ensure_alive
(
self
)
->
Option
<
Self
>
{
...
@@ -173,41 +185,26 @@ impl SessionUser {
...
@@ -173,41 +185,26 @@ impl SessionUser {
let
now
=
time
::
get_time
();
let
now
=
time
::
get_time
();
if
now
-
self
.last_activity
?
<
duration
{
if
now
-
self
.last_activity
?
<
duration
{
Some
(
self
)
Some
(
self
)
}
}
else
{
else
{
None
None
}
}
}
}
pub
fn
ensure_logged_in
(
self
)
->
Option
<
Self
>
{
pub
fn
ensure_logged_in
(
self
)
->
Option
<
Self
>
{
if
self
.password
.is_some
()
||
self
.logincode
.is_some
()
||
self
.pms_id
.is_some
()
{
if
self
.password
.is_some
()
||
self
.logincode
.is_some
()
||
self
.pms_id
.is_some
()
{
self
.ensure_alive
()
self
.ensure_alive
()
}
}
else
{
else
{
None
None
}
}
}
}
}
}
impl
Taskgroup
{
impl
Taskgroup
{
pub
fn
new
(
name
:
String
)
->
Self
{
pub
fn
new
(
name
:
String
)
->
Self
{
Taskgroup
{
id
:
None
,
contest
:
0
,
name
:
name
,
tasks
:
Vec
::
new
()
}
}
Taskgroup
{
id
:
None
,
contest
:
0
,
name
:
name
,
tasks
:
Vec
::
new
(),
}
}
}
}
impl
Task
{
impl
Task
{
pub
fn
new
(
location
:
String
,
stars
:
u8
)
->
Self
{
pub
fn
new
(
location
:
String
,
stars
:
u8
)
->
Self
{
Task
{
Task
{
id
:
None
,
taskgroup
:
0
,
location
:
location
,
stars
:
stars
}
id
:
None
,
}
taskgroup
:
0
,
location
:
location
,
stars
:
stars
,
}
}
}
}
src/functions.rs
View file @
26effac5
This diff is collapsed.
Click to expand it.
src/main.rs
View file @
26effac5
...
@@ -7,44 +7,44 @@ extern crate router;
...
@@ -7,44 +7,44 @@ extern crate router;
#[macro_use]
#[macro_use]
extern
crate
serde_derive
;
extern
crate
serde_derive
;
extern
crate
structopt
;
extern
crate
handlebars_iron
;
extern
crate
rusqlite
;
extern
crate
iron_sessionstorage
;
extern
crate
iron_sessionstorage
;
extern
crate
urlencoded
;
extern
crate
time
;
extern
crate
persistent
;
extern
crate
rand
;
extern
crate
mount
;
extern
crate
mount
;
extern
crate
staticfile
;
extern
crate
handlebars_iron
;
extern
crate
serde_json
;
extern
crate
params
;
extern
crate
params
;
extern
crate
persistent
;
extern
crate
rand
;
extern
crate
reqwest
;
extern
crate
reqwest
;
extern
crate
rusqlite
;
extern
crate
serde_json
;
extern
crate
serde_yaml
;
extern
crate
serde_yaml
;
extern
crate
staticfile
;
extern
crate
structopt
;
extern
crate
time
;
extern
crate
urlencoded
;
use
rusqlite
::
Connection
;
use
rusqlite
::
Connection
;
mod
db_apply_migrations
;
mod
db_apply_migrations
;
mod
db_conn_sqlite
;
mod
db_conn
;
mod
db_conn
;
mod
db_conn_sqlite
;
mod
db_objects
;
mod
db_objects
;
use
functions
::
SetPassword
;
// TODO: Refactor, so we don't need to take this from there!
use
db_conn
::{
MedalConnection
,
MedalObject
};
use
db_conn
::{
MedalConnection
,
MedalObject
};
use
functions
::
SetPassword
;
// TODO: Refactor, so we don't need to take this from there!
use
db_objects
::
*
;
use
db_objects
::
*
;
mod
webfw_iron
;
mod
configreader_yaml
;
mod
configreader_yaml
;
mod
webfw_iron
;
use
webfw_iron
::
start_server
;
use
webfw_iron
::
start_server
;
mod
functions
;
mod
functions
;
use
std
::
path
;
use
std
::
fs
;
use
std
::
fs
;
use
std
::
path
;
use
std
::
path
::{
Path
,
PathBuf
};
use
std
::
path
::{
Path
,
PathBuf
};
use
structopt
::
StructOpt
;
use
structopt
::
StructOpt
;
#[derive(Serialize,
Deserialize,
Clone,
Default)]
#[derive(Serialize,
Deserialize,
Clone,
Default)]
...
@@ -65,7 +65,7 @@ fn read_config_from_file(file: &Path) -> Config {
...
@@ -65,7 +65,7 @@ fn read_config_from_file(file: &Path) -> Config {
println!
(
"Reading configuration file '{}'"
,
file
.to_str
()
.unwrap_or
(
"<Encoding error>"
));
println!
(
"Reading configuration file '{}'"
,
file
.to_str
()
.unwrap_or
(
"<Encoding error>"
));
let
mut
config
:
Config
=
if
let
Ok
(
mut
file
)
=
fs
::
File
::
open
(
file
)
{
let
mut
config
:
Config
=
if
let
Ok
(
mut
file
)
=
fs
::
File
::
open
(
file
)
{
let
mut
contents
=
String
::
new
();
let
mut
contents
=
String
::
new
();
file
.read_to_string
(
&
mut
contents
)
.unwrap
();
file
.read_to_string
(
&
mut
contents
)
.unwrap
();