Skip to content

Commit

Permalink
presentations backend
Browse files Browse the repository at this point in the history
  • Loading branch information
subhojit777 committed May 23, 2019
1 parent 9bd39de commit 18b5602
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions migrations/2019-05-23-032722_create_presentations/down.sql
@@ -0,0 +1 @@
DROP TABLE presentations
5 changes: 5 additions & 0 deletions migrations/2019-05-23-032722_create_presentations/up.sql
@@ -0,0 +1,5 @@
CREATE TABLE presentations (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
created TIMESTAMP NOT NULL
)
24 changes: 24 additions & 0 deletions src/models.rs
Expand Up @@ -74,3 +74,27 @@ impl GHAccessTokenBody {
/// This defines an actor for retrieving answer from database by id.
#[derive(Queryable, Deserialize)]
pub struct GetAnswerById(pub i32);

/// Presentation model.
#[derive(Queryable, Serialize, Deserialize)]
pub struct Presentation {
id: i32,
title: String,
created: NaiveDateTime,
}

/// Creates a new presentation.
#[derive(Insertable, Debug)]
#[table_name = "presentations"]
pub struct NewPresentation {
title: String,
created: NaiveDateTime,
}

/// The structure of the body of JSON request for creating a new presentation.
///
/// This is used for making the API request, and `NewPresentation` is used by the application for
/// creating the presentation in database.
pub struct PresentationInput {
title: String,
}
14 changes: 13 additions & 1 deletion src/schema.rs
Expand Up @@ -8,6 +8,14 @@ table! {
}
}

table! {
presentations (id) {
id -> Integer,
title -> Varchar,
created -> Timestamp,
}
}

table! {
questions (id) {
id -> Integer,
Expand All @@ -16,4 +24,8 @@ table! {
}
}

allow_tables_to_appear_in_same_query!(answers, questions,);
allow_tables_to_appear_in_same_query!(
answers,
presentations,
questions,
);

0 comments on commit 18b5602

Please sign in to comment.