Compare commits

...
This repository has been archived on 2023-07-04. You can view files and clone it, but cannot push or open issues/pull-requests.

5 Commits
main ... dev

Author SHA1 Message Date
Jef Roosens 660712b280
Gosh darn indents
ci/woodpecker/push/rustfmt Pipeline failed Details
ci/woodpecker/push/test Pipeline was successful Details
2022-01-02 20:43:34 +01:00
Jef Roosens 167a1ff3ed
Added per-step when clause 2022-01-02 20:42:34 +01:00
Jef Roosens d9d4e66ee5
Adding testing CI step
ci/woodpecker/push/rustfmt Pipeline failed Details
ci/woodpecker/push/test Pipeline failed Details
2022-01-02 20:38:44 +01:00
Jef Roosens 409ff8d812
Ran clippy fix
ci/woodpecker/push/lint Pipeline failed Details
2021-12-30 14:23:06 +01:00
Jef Roosens 0bbd2a0d77
Added linting pipeline
ci/woodpecker/push/lint Pipeline failed Details
2021-12-30 13:00:44 +01:00
8 changed files with 45 additions and 28 deletions

View File

@ -0,0 +1,5 @@
pipeline:
lint:
image: 'rustlang/rust:nightly'
commands:
- cargo fmt -- --check

View File

@ -0,0 +1,15 @@
# When block for each step is temporary until top-level when is properly implemented
pipeline:
clippy:
image: 'rust:1.57'
commands:
- cargo clippy -- -D clippy::all --no-deps
when:
event: pull_request
tests:
image: 'rust:1.57'
commands:
- cargo test
when:
event: pull_request

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>")]