Can change default account
This commit is contained in:
parent
1977b5209c
commit
90bb4db806
@ -37,6 +37,13 @@ pub async fn update(account: AccountInPath, req: web::Json<UpdateAccountQuery>)
|
|||||||
Ok(HttpResponse::Accepted().finish())
|
Ok(HttpResponse::Accepted().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set an account as the default one
|
||||||
|
pub async fn set_default(account: AccountInPath) -> HttpResult {
|
||||||
|
accounts_service::set_default(account.as_ref().user_id(), account.as_ref().id()).await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Accepted().finish())
|
||||||
|
}
|
||||||
|
|
||||||
/// Delete an account
|
/// Delete an account
|
||||||
pub async fn delete(account: AccountInPath) -> HttpResult {
|
pub async fn delete(account: AccountInPath) -> HttpResult {
|
||||||
accounts_service::delete(account.as_ref().id()).await?;
|
accounts_service::delete(account.as_ref().id()).await?;
|
||||||
|
@ -111,11 +111,14 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/account/{account_id}",
|
"/api/account/{account_id}",
|
||||||
web::put().to(accounts_controller::update),
|
web::put().to(accounts_controller::update),
|
||||||
)
|
)
|
||||||
|
.route(
|
||||||
|
"/api/account/{account_id}/default",
|
||||||
|
web::put().to(accounts_controller::set_default),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/api/account/{account_id}",
|
"/api/account/{account_id}",
|
||||||
web::delete().to(accounts_controller::delete),
|
web::delete().to(accounts_controller::delete),
|
||||||
)
|
)
|
||||||
// TODO : set as default
|
|
||||||
// Static assets
|
// Static assets
|
||||||
.route("/", web::get().to(static_controller::root_index))
|
.route("/", web::get().to(static_controller::root_index))
|
||||||
.route(
|
.route(
|
||||||
|
@ -68,6 +68,25 @@ pub async fn get_list_user(id: UserID) -> anyhow::Result<Vec<Account>> {
|
|||||||
.get_results(&mut db()?)?)
|
.get_results(&mut db()?)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Change the default account of a user
|
||||||
|
pub async fn set_default(user_id: UserID, account_id: AccountID) -> anyhow::Result<()> {
|
||||||
|
diesel::update(accounts::dsl::accounts.filter(accounts::dsl::user_id.eq(user_id.0)))
|
||||||
|
.set((accounts::dsl::default_account.eq(false),))
|
||||||
|
.execute(&mut db()?)?;
|
||||||
|
|
||||||
|
diesel::update(
|
||||||
|
accounts::dsl::accounts.filter(
|
||||||
|
accounts::dsl::user_id
|
||||||
|
.eq(user_id.0)
|
||||||
|
.and(accounts::dsl::id.eq(account_id.0)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.set((accounts::dsl::default_account.eq(true),))
|
||||||
|
.execute(&mut db()?)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Delete an account
|
/// Delete an account
|
||||||
pub async fn delete(id: AccountID) -> anyhow::Result<()> {
|
pub async fn delete(id: AccountID) -> anyhow::Result<()> {
|
||||||
diesel::delete(accounts::dsl::accounts.filter(accounts::dsl::id.eq(id.0)))
|
diesel::delete(accounts::dsl::accounts.filter(accounts::dsl::id.eq(id.0)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user