db_conn.rs 2.24 KB
Newer Older
1
use db_objects::*;
2
use ::functions;
3
use std::path::{Path};
4
5

pub trait MedalConnection {
6
    fn create(file: &Path) -> Self;
7
8
    fn dbtype(&self) -> &'static str;

Robert Czechowski's avatar
Robert Czechowski committed
9
    fn migration_already_applied(&self, name: &str) -> bool;   
10
11
    fn apply_migration(&mut self, name: &str, contents: String);

Robert Czechowski's avatar
Robert Czechowski committed
12
13
    fn get_session(&self, key: String) -> Option<SessionUser>;
    fn new_session(&self) -> SessionUser;
Robert Czechowski's avatar
Robert Czechowski committed
14
    fn save_session(&self, session: SessionUser);
Robert Czechowski's avatar
Robert Czechowski committed
15
    fn get_session_or_new(&self, key: String) -> SessionUser;
16

Robert Czechowski's avatar
Robert Czechowski committed
17
    //fn login(&self, session: &SessionUser, username: String, password: String) -> Result<String,()>;
18

Robert Czechowski's avatar
Robert Czechowski committed
19
    fn login(&self, session: Option<String>, username: String, password: String) -> Result<String,()>;
Robert Czechowski's avatar
Robert Czechowski committed
20
    fn login_with_code(&self, session: Option<String>, logincode: String) -> Result<String,()>;
21
    fn login_foreign(&self, session: Option<String>, foreign_id: u32, foreign_type: functions::UserType, firstname: String, lastname:String) -> Result<String,()>;
Robert Czechowski's avatar
Robert Czechowski committed
22
    fn create_user_with_groupcode(&self, session: Option<String>, groupcode: String) -> Result<String,()>;
Robert Czechowski's avatar
Robert Czechowski committed
23
    fn logout(&self, session: String);
24

Robert Czechowski's avatar
Robert Czechowski committed
25
26
    fn load_submission(&self, session: &SessionUser, task: u32, subtask: Option<String>) -> Option<Submission>;
    fn submit_submission(&self, submission: Submission);
27

Robert Czechowski's avatar
Robert Czechowski committed
28
    fn get_contest_list(&self) -> Vec<Contest>;
Robert Czechowski's avatar
Robert Czechowski committed
29
30
31
32
33
34
    fn get_contest_by_id(&self, contest_id: u32) -> Contest;
    fn get_contest_by_id_complete(&self, contest_id :u32) -> Contest;
    fn get_participation(&self, session: String, contest_id: u32) -> Option<Participation>;
    fn new_participation(&self, session: String, 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);
Robert Czechowski's avatar
Robert Czechowski committed
35
36
37

    fn get_submission_to_validate(&self, tasklocation: String, subtask: Option<String>) -> u32;
    fn find_next_submission_to_validate(&self, userid: u32, taskgroupid: u32);
Robert Czechowski's avatar
Robert Czechowski committed
38
39
40
41
42

    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>;    
43
44
45
46
}


pub trait MedalObject<T: MedalConnection> {
Robert Czechowski's avatar
Robert Czechowski committed
47
    fn save(&mut self, conn: &T);
48
}