db_conn.rs 2.86 KB
Newer Older
1
2
3
4
5
use db_objects::*;

pub trait MedalConnection {
    fn dbtype(&self) -> &'static str;

6
7
    fn migration_already_applied(&self, name: &str) -> bool;
    fn apply_migration(&mut self, name: &str, contents: &str);
8

9
    fn get_session(&self, key: &str) -> Option<SessionUser>;
10
    fn new_session(&self, key: &str) -> SessionUser;
Robert Czechowski's avatar
Robert Czechowski committed
11
    fn save_session(&self, session: SessionUser);
12
    fn get_session_or_new(&self, key: &str) -> SessionUser;
13

14
15
    fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser>;
    fn get_user_and_group_by_id(&self, user_id: i32) -> Option<(SessionUser, Option<Group>)>;
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
20
    fn login(&self, session: Option<&str>, username: &str, password: &str) -> Result<String, ()>;
    fn login_with_code(&self, session: Option<&str>, logincode: &str) -> Result<String, ()>;
Robert Czechowski's avatar
rustfmt    
Robert Czechowski committed
21
    fn login_foreign(&self, session: Option<&str>, foreign_id: &str, is_teacher: bool, firstname: &str, lastname: &str)
Robert Czechowski's avatar
Robert Czechowski committed
22
23
                     -> Result<String, ()>;
    fn create_user_with_groupcode(&self, session: Option<&str>, groupcode: &str) -> Result<String, ()>;
24
    fn create_group_with_users(&self, group: Group);
25
    fn logout(&self, session: &str);
26

27
    fn load_submission(&self, session: &SessionUser, task: i32, subtask: Option<&str>) -> Option<Submission>;
Robert Czechowski's avatar
Robert Czechowski committed
28
    fn submit_submission(&self, submission: Submission);
29
30
    fn get_grade_by_submission(&self, submission_id: i32) -> Grade;
    fn get_contest_groups_grades(&self, session_id: i32, contest_id: i32)
Robert Czechowski's avatar
Robert Czechowski committed
31
                                 -> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>);
32
33
    fn get_taskgroup_user_grade(&self, session: &str, taskgroup_id: i32) -> Grade;
    fn get_contest_user_grades(&self, session: &str, contest_id: i32) -> Vec<Grade>;
34

Robert Czechowski's avatar
Robert Czechowski committed
35
    fn get_contest_list(&self) -> Vec<Contest>;
36
37
38
39
40
41
42
    fn get_contest_by_id(&self, contest_id: i32) -> Contest;
    fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest;
    fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest;
    fn get_participation(&self, session: &str, contest_id: i32) -> Option<Participation>;
    fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()>;
    fn get_task_by_id(&self, task_id: i32) -> Task;
    fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest);
Robert Czechowski's avatar
Robert Czechowski committed
43

44
45
    fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> i32;
    fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32);
Robert Czechowski's avatar
Robert Czechowski committed
46
47

    fn add_group(&self, group: &mut Group);
48
49
50
    fn get_groups(&self, session_id: i32) -> Vec<Group>;
    fn get_groups_complete(&self, session_id: i32) -> Vec<Group>;
    fn get_group_complete(&self, group_id: i32) -> Option<Group>;
51
52

    fn reset_all_contest_visibilities(&self);
53
54
55
}

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