-
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.
again thanks to Brook Jeynes for the tutorial
- Loading branch information
Showing
5 changed files
with
34 additions
and
10 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
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,24 @@ | ||
use domain::models::{Event, NewEvent}; | ||
use shared::response_models::{Response, ResponseBody}; | ||
use infrastructure::establish_connection; | ||
use diesel::prelude::*; | ||
use rocket::response::status::Created; | ||
use rocket::serde::json::Json; | ||
|
||
pub fn create_event(event: Json<NewEvent>) -> Created<String> { | ||
use domain::schema::events; | ||
|
||
let event = event.into_inner(); | ||
|
||
match diesel::insert_into(events::table).values(&event).get_result::<Event>(&mut establish_connection()) { | ||
Ok(event) => { | ||
let response = Response { body: ResponseBody::Event(event) }; | ||
Created::new("").tagged_body(serde_json::to_string(&response).unwrap()) | ||
}, | ||
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 +1,2 @@ | ||
pub mod read; | ||
pub mod read; | ||
pub mod create; |