-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this should also trigger the checking workflow
- Loading branch information
Showing
5 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod read; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use domain::models::Event; | ||
use shared::response_models::{Response, ResponseBody}; | ||
use infrastructure::establish_connection; | ||
use diesel::prelude::*; | ||
use rocket::response::status::NotFound; | ||
|
||
pub fn list_event(event_id: i32) -> Result<Event, NotFound<String>> { | ||
use domain::schema::events; | ||
|
||
match events::table.find(event_id).first::<Event>(&mut establish_connection()) { | ||
Ok(event) => Ok(event), | ||
Err(err) => match err { | ||
diesel::result::Error::NotFound => { | ||
let response = Response { body: ResponseBody::Message(format!("Error selecting event with id {} - {}", event_id, err))}; | ||
return Err(NotFound(serde_json::to_string(&response).unwrap())); | ||
}, | ||
_ => { | ||
panic!("Database error - {}", err); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn list_events() -> Vec<Event> { | ||
use domain::schema::events; | ||
|
||
match events::table.select(events::all_columns).load::<Event>(&mut establish_connection()) { | ||
Ok(mut events) => { | ||
events.sort(); | ||
events | ||
}, | ||
Err(err) => match err { | ||
_ => { | ||
panic!("Database error - {}", err); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
pub mod event; |