Ran clippy fix
ci/woodpecker/push/lint Pipeline failed Details

dev
Jef Roosens 2021-12-30 14:23:06 +01:00
parent 0bbd2a0d77
commit 409ff8d812
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
6 changed files with 25 additions and 28 deletions

View File

@ -40,11 +40,11 @@ pub struct PatchPost
/// by `super::MAX_POSTS`.
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Post>>
{
Ok(posts
posts
.offset(offset_.into())
.limit(std::cmp::min(limit_, super::MAX_POSTS).into())
.load(conn)
.map_err(|_| RbError::DbError("Couldn't query posts."))?)
.map_err(|_| RbError::DbError("Couldn't query posts."))
}
/// Try to find a post given its id (primary key).
@ -60,10 +60,10 @@ pub fn find(conn: &PgConnection, id_: &Uuid) -> RbOption<Post>
/// Create a new post & store it in the database.
pub fn create(conn: &PgConnection, new_post: &NewPost) -> RbResult<Post>
{
Ok(insert_into(posts)
insert_into(posts)
.values(new_post)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't insert post."))?)
.map_err(|_| RbError::DbError("Couldn't insert post."))
// TODO check for conflict?
}
@ -71,10 +71,10 @@ pub fn create(conn: &PgConnection, new_post: &NewPost) -> RbResult<Post>
/// Update a post in the database with a given ID, returning the updated row.
pub fn update(conn: &PgConnection, post_id: &Uuid, patch_post: &PatchPost) -> RbResult<Post>
{
Ok(diesel::update(posts.filter(id.eq(post_id)))
diesel::update(posts.filter(id.eq(post_id)))
.set(patch_post)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't update post."))?)
.map_err(|_| RbError::DbError("Couldn't update post."))
}
/// Delete a post with a given ID.

View File

@ -54,11 +54,11 @@ pub struct PatchSection
/// `limit_` is determined by `super::MAX_SECTIONS`.
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Section>>
{
Ok(sections
sections
.offset(offset_.into())
.limit(std::cmp::min(limit_, super::MAX_SECTIONS).into())
.load(conn)
.map_err(|_| RbError::DbError("Couldn't query sections."))?)
.map_err(|_| RbError::DbError("Couldn't query sections."))
}
/// Try to find a section given its shortname.
@ -74,10 +74,10 @@ pub fn find_with_shortname(conn: &PgConnection, shortname_: &str) -> RbOption<Se
/// Create a new section.
pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<Section>
{
Ok(insert_into(sections)
insert_into(sections)
.values(new_section)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't insert section."))?)
.map_err(|_| RbError::DbError("Couldn't insert section."))
// TODO check for conflict?
}
@ -85,10 +85,10 @@ pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<Section
/// Update a section given its ID.
pub fn update(conn: &PgConnection, post_id: &Uuid, patch_post: &PatchSection) -> RbResult<Section>
{
Ok(diesel::update(sections.filter(id.eq(post_id)))
diesel::update(sections.filter(id.eq(post_id)))
.set(patch_post)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't update section."))?)
.map_err(|_| RbError::DbError("Couldn't update section."))
}
// Update a section given its shortname.
@ -98,10 +98,10 @@ pub fn update_with_shortname(
patch_section: &PatchSection,
) -> RbResult<Section>
{
Ok(diesel::update(sections.filter(shortname.eq(shortname_)))
diesel::update(sections.filter(shortname.eq(shortname_)))
.set(patch_section)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't update section with shortname."))?)
.map_err(|_| RbError::DbError("Couldn't update section with shortname."))
}
/// Delete a section given its ID.

View File

@ -44,11 +44,11 @@ pub struct PatchVersion
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Version>>
{
Ok(versions
versions
.offset(offset_.into())
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
.load(conn)
.map_err(|_| RbError::DbError("Couldn't query versions."))?)
.map_err(|_| RbError::DbError("Couldn't query versions."))
}
pub fn get_for_post(
@ -58,12 +58,12 @@ pub fn get_for_post(
limit_: u32,
) -> RbResult<Vec<Version>>
{
Ok(versions
versions
.offset(offset_.into())
.filter(post_id.eq(post_id_))
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
.load(conn)
.map_err(|_| RbError::DbError("Couldn't query versions."))?)
.map_err(|_| RbError::DbError("Couldn't query versions."))
}
pub fn find(conn: &PgConnection, id_: &Uuid) -> RbOption<Version>
@ -77,20 +77,20 @@ pub fn find(conn: &PgConnection, id_: &Uuid) -> RbOption<Version>
pub fn create(conn: &PgConnection, new: &NewVersion) -> RbResult<Version>
{
Ok(insert_into(versions)
insert_into(versions)
.values(new)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't insert version."))?)
.map_err(|_| RbError::DbError("Couldn't insert version."))
// TODO check for conflict?
}
pub fn update(conn: &PgConnection, id_: &Uuid, patch: &PatchVersion) -> RbResult<Version>
{
Ok(diesel::update(versions.filter(id.eq(id_)))
diesel::update(versions.filter(id.eq(id_)))
.set(patch)
.get_result(conn)
.map_err(|_| RbError::DbError("Couldn't update version."))?)
.map_err(|_| RbError::DbError("Couldn't update version."))
}
pub fn delete(conn: &PgConnection, id_: &Uuid) -> RbResult<()>

View File

@ -36,8 +36,7 @@ pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Post>>
{
Ok(conn
.run(move |c| db::posts::find(c, &id))
.await?
.and_then(|p| Some(Json(p))))
.await?.map(|p| Json(p)))
}
/// Patch a post given its ID.

View File

@ -40,8 +40,7 @@ pub async fn find(conn: RbDbConn, shortname: String) -> RbOption<Json<db::Sectio
{
Ok(conn
.run(move |c| db::sections::find_with_shortname(c, &shortname))
.await?
.and_then(|p| Some(Json(p))))
.await?.map(|p| Json(p)))
}
/// Patch a section given its shortname.

View File

@ -49,8 +49,7 @@ pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Version>>
{
Ok(conn
.run(move |c| db::versions::find(c, &id))
.await?
.and_then(|p| Some(Json(p))))
.await?.map(|p| Json(p)))
}
#[patch("/<id>", data = "<patch>")]