Add PATCH /family/{id} route
This commit is contained in:
@ -49,6 +49,15 @@ pub async fn add_member(
|
||||
})
|
||||
}
|
||||
|
||||
/// Find a family by id
|
||||
pub async fn get_by_id(id: FamilyID) -> anyhow::Result<Family> {
|
||||
db_connection::execute(|conn| {
|
||||
families::table
|
||||
.filter(families::dsl::id.eq(id.0))
|
||||
.first(conn)
|
||||
})
|
||||
}
|
||||
|
||||
/// Find a family by invitation code
|
||||
pub async fn get_by_invitation_code(code: &str) -> anyhow::Result<Family> {
|
||||
db_connection::execute(|conn| {
|
||||
@ -141,6 +150,20 @@ pub async fn get_family_membership(
|
||||
})
|
||||
}
|
||||
|
||||
/// Update a family
|
||||
pub async fn update_family(family: &Family) -> anyhow::Result<()> {
|
||||
db_connection::execute(|conn| {
|
||||
diesel::update(families::dsl::families.filter(families::dsl::id.eq(family.id().0)))
|
||||
.set((
|
||||
families::dsl::name.eq(family.name.clone()),
|
||||
families::dsl::invitation_code.eq(family.invitation_code.clone()),
|
||||
))
|
||||
.execute(conn)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Delete a family
|
||||
pub async fn delete_family(family_id: FamilyID) -> anyhow::Result<()> {
|
||||
// TODO : delete members and couples
|
||||
|
Reference in New Issue
Block a user