Added create section endpoint
This commit is contained in:
parent
8534090f0f
commit
3e7612a9a8
11 changed files with 75 additions and 30 deletions
|
|
@ -1,8 +1,8 @@
|
|||
pub mod posts;
|
||||
pub mod sections;
|
||||
pub mod tokens;
|
||||
pub mod users;
|
||||
pub mod sections;
|
||||
pub mod posts;
|
||||
|
||||
pub use sections::{NewSection, Section};
|
||||
pub use tokens::{NewRefreshToken, RefreshToken};
|
||||
pub use users::{NewUser, User};
|
||||
pub use sections::{Section, NewSection};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use chrono::NaiveDate;
|
||||
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
|
||||
use uuid::Uuid;
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crate::{
|
||||
errors::{RbError, RbResult},
|
||||
|
|
@ -28,7 +28,9 @@ pub struct NewPost
|
|||
|
||||
pub fn all(conn: &PgConnection) -> RbResult<Vec<Post>>
|
||||
{
|
||||
posts.load::<Post>(conn).map_err(|_| RbError::DbError("Couldn't get all posts."))
|
||||
posts
|
||||
.load::<Post>(conn)
|
||||
.map_err(|_| RbError::DbError("Couldn't get all posts."))
|
||||
}
|
||||
|
||||
pub fn create(conn: &PgConnection, new_post: &NewPost) -> RbResult<()>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use diesel::{insert_into, prelude::*, Insertable, PgConnection, Queryable};
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -16,19 +17,22 @@ pub struct Section
|
|||
pub has_titles: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[derive(Deserialize, Insertable)]
|
||||
#[table_name = "sections"]
|
||||
// #[serde(rename_all = "camelCase")]
|
||||
pub struct NewSection
|
||||
{
|
||||
title: String,
|
||||
description: Option<String>,
|
||||
is_default: bool,
|
||||
has_titles: bool,
|
||||
is_default: Option<bool>,
|
||||
has_titles: Option<bool>,
|
||||
}
|
||||
|
||||
pub fn all(conn: &PgConnection) -> RbResult<Vec<Section>>
|
||||
{
|
||||
sections.load::<Section>(conn).map_err(|_| RbError::DbError("Couldn't get all sections"))
|
||||
sections
|
||||
.load::<Section>(conn)
|
||||
.map_err(|_| RbError::DbError("Couldn't get all sections"))
|
||||
}
|
||||
|
||||
pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<()>
|
||||
|
|
|
|||
Reference in a new issue