Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Jef Roosens | 660712b280 | |
Jef Roosens | 167a1ff3ed | |
Jef Roosens | d9d4e66ee5 | |
Jef Roosens | 409ff8d812 | |
Jef Roosens | 0bbd2a0d77 |
|
@ -0,0 +1,5 @@
|
||||||
|
pipeline:
|
||||||
|
lint:
|
||||||
|
image: 'rustlang/rust:nightly'
|
||||||
|
commands:
|
||||||
|
- cargo fmt -- --check
|
|
@ -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
|
|
@ -40,11 +40,11 @@ pub struct PatchPost
|
||||||
/// by `super::MAX_POSTS`.
|
/// by `super::MAX_POSTS`.
|
||||||
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Post>>
|
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Post>>
|
||||||
{
|
{
|
||||||
Ok(posts
|
posts
|
||||||
.offset(offset_.into())
|
.offset(offset_.into())
|
||||||
.limit(std::cmp::min(limit_, super::MAX_POSTS).into())
|
.limit(std::cmp::min(limit_, super::MAX_POSTS).into())
|
||||||
.load(conn)
|
.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).
|
/// 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.
|
/// Create a new post & store it in the database.
|
||||||
pub fn create(conn: &PgConnection, new_post: &NewPost) -> RbResult<Post>
|
pub fn create(conn: &PgConnection, new_post: &NewPost) -> RbResult<Post>
|
||||||
{
|
{
|
||||||
Ok(insert_into(posts)
|
insert_into(posts)
|
||||||
.values(new_post)
|
.values(new_post)
|
||||||
.get_result(conn)
|
.get_result(conn)
|
||||||
.map_err(|_| RbError::DbError("Couldn't insert post."))?)
|
.map_err(|_| RbError::DbError("Couldn't insert post."))
|
||||||
|
|
||||||
// TODO check for conflict?
|
// 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.
|
/// 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>
|
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)
|
.set(patch_post)
|
||||||
.get_result(conn)
|
.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.
|
/// Delete a post with a given ID.
|
||||||
|
|
|
@ -54,11 +54,11 @@ pub struct PatchSection
|
||||||
/// `limit_` is determined by `super::MAX_SECTIONS`.
|
/// `limit_` is determined by `super::MAX_SECTIONS`.
|
||||||
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Section>>
|
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Section>>
|
||||||
{
|
{
|
||||||
Ok(sections
|
sections
|
||||||
.offset(offset_.into())
|
.offset(offset_.into())
|
||||||
.limit(std::cmp::min(limit_, super::MAX_SECTIONS).into())
|
.limit(std::cmp::min(limit_, super::MAX_SECTIONS).into())
|
||||||
.load(conn)
|
.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.
|
/// 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.
|
/// Create a new section.
|
||||||
pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<Section>
|
pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<Section>
|
||||||
{
|
{
|
||||||
Ok(insert_into(sections)
|
insert_into(sections)
|
||||||
.values(new_section)
|
.values(new_section)
|
||||||
.get_result(conn)
|
.get_result(conn)
|
||||||
.map_err(|_| RbError::DbError("Couldn't insert section."))?)
|
.map_err(|_| RbError::DbError("Couldn't insert section."))
|
||||||
|
|
||||||
// TODO check for conflict?
|
// TODO check for conflict?
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,10 @@ pub fn create(conn: &PgConnection, new_section: &NewSection) -> RbResult<Section
|
||||||
/// Update a section given its ID.
|
/// Update a section given its ID.
|
||||||
pub fn update(conn: &PgConnection, post_id: &Uuid, patch_post: &PatchSection) -> RbResult<Section>
|
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)
|
.set(patch_post)
|
||||||
.get_result(conn)
|
.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.
|
// Update a section given its shortname.
|
||||||
|
@ -98,10 +98,10 @@ pub fn update_with_shortname(
|
||||||
patch_section: &PatchSection,
|
patch_section: &PatchSection,
|
||||||
) -> RbResult<Section>
|
) -> RbResult<Section>
|
||||||
{
|
{
|
||||||
Ok(diesel::update(sections.filter(shortname.eq(shortname_)))
|
diesel::update(sections.filter(shortname.eq(shortname_)))
|
||||||
.set(patch_section)
|
.set(patch_section)
|
||||||
.get_result(conn)
|
.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.
|
/// Delete a section given its ID.
|
||||||
|
|
|
@ -44,11 +44,11 @@ pub struct PatchVersion
|
||||||
|
|
||||||
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Version>>
|
pub fn get(conn: &PgConnection, offset_: u32, limit_: u32) -> RbResult<Vec<Version>>
|
||||||
{
|
{
|
||||||
Ok(versions
|
versions
|
||||||
.offset(offset_.into())
|
.offset(offset_.into())
|
||||||
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
|
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
.map_err(|_| RbError::DbError("Couldn't query versions."))?)
|
.map_err(|_| RbError::DbError("Couldn't query versions."))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_for_post(
|
pub fn get_for_post(
|
||||||
|
@ -58,12 +58,12 @@ pub fn get_for_post(
|
||||||
limit_: u32,
|
limit_: u32,
|
||||||
) -> RbResult<Vec<Version>>
|
) -> RbResult<Vec<Version>>
|
||||||
{
|
{
|
||||||
Ok(versions
|
versions
|
||||||
.offset(offset_.into())
|
.offset(offset_.into())
|
||||||
.filter(post_id.eq(post_id_))
|
.filter(post_id.eq(post_id_))
|
||||||
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
|
.limit(std::cmp::min(limit_, super::MAX_VERSIONS).into())
|
||||||
.load(conn)
|
.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>
|
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>
|
pub fn create(conn: &PgConnection, new: &NewVersion) -> RbResult<Version>
|
||||||
{
|
{
|
||||||
Ok(insert_into(versions)
|
insert_into(versions)
|
||||||
.values(new)
|
.values(new)
|
||||||
.get_result(conn)
|
.get_result(conn)
|
||||||
.map_err(|_| RbError::DbError("Couldn't insert version."))?)
|
.map_err(|_| RbError::DbError("Couldn't insert version."))
|
||||||
|
|
||||||
// TODO check for conflict?
|
// TODO check for conflict?
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(conn: &PgConnection, id_: &Uuid, patch: &PatchVersion) -> RbResult<Version>
|
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)
|
.set(patch)
|
||||||
.get_result(conn)
|
.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<()>
|
pub fn delete(conn: &PgConnection, id_: &Uuid) -> RbResult<()>
|
||||||
|
|
|
@ -36,8 +36,7 @@ pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Post>>
|
||||||
{
|
{
|
||||||
Ok(conn
|
Ok(conn
|
||||||
.run(move |c| db::posts::find(c, &id))
|
.run(move |c| db::posts::find(c, &id))
|
||||||
.await?
|
.await?.map(|p| Json(p)))
|
||||||
.and_then(|p| Some(Json(p))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Patch a post given its ID.
|
/// Patch a post given its ID.
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub async fn find(conn: RbDbConn, shortname: String) -> RbOption<Json<db::Sectio
|
||||||
{
|
{
|
||||||
Ok(conn
|
Ok(conn
|
||||||
.run(move |c| db::sections::find_with_shortname(c, &shortname))
|
.run(move |c| db::sections::find_with_shortname(c, &shortname))
|
||||||
.await?
|
.await?.map(|p| Json(p)))
|
||||||
.and_then(|p| Some(Json(p))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Patch a section given its shortname.
|
/// Patch a section given its shortname.
|
||||||
|
|
|
@ -49,8 +49,7 @@ pub async fn find(conn: RbDbConn, id: uuid::Uuid) -> RbOption<Json<db::Version>>
|
||||||
{
|
{
|
||||||
Ok(conn
|
Ok(conn
|
||||||
.run(move |c| db::versions::find(c, &id))
|
.run(move |c| db::versions::find(c, &id))
|
||||||
.await?
|
.await?.map(|p| Json(p)))
|
||||||
.and_then(|p| Some(Json(p))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("/<id>", data = "<patch>")]
|
#[patch("/<id>", data = "<patch>")]
|
||||||
|
|
Reference in New Issue