-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from LRZ-BADW/user-budget-sync
User Budget Sync
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
.sqlx/query-46e3c0b0e81ae0a98157ced83a6565d7ccf616a0a2b0d445f1be759779ff2fad.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::authorization::require_admin_user; | ||
use crate::database::budgeting::user_budget::sync_user_budgets_in_db; | ||
use crate::error::NormalApiError; | ||
use actix_web::web::{Data, ReqData}; | ||
use actix_web::HttpResponse; | ||
use anyhow::Context; | ||
use lrzcc_wire::budgeting::UserBudgetSync; | ||
use lrzcc_wire::user::{Project, User}; | ||
use sqlx::MySqlPool; | ||
|
||
// TODO: write tests for this endpoint | ||
#[tracing::instrument(name = "user_budget_sync")] | ||
pub async fn user_budget_sync( | ||
user: ReqData<User>, | ||
project: ReqData<Project>, | ||
db_pool: Data<MySqlPool>, | ||
// TODO: this can only be an authorization or unexpected error, we need a type for that | ||
) -> Result<HttpResponse, NormalApiError> { | ||
require_admin_user(&user)?; | ||
let mut transaction = db_pool | ||
.begin() | ||
.await | ||
.context("Failed to begin transaction")?; | ||
let count = sync_user_budgets_in_db(&mut transaction).await?; | ||
transaction | ||
.commit() | ||
.await | ||
.context("Failed to commit transaction")?; | ||
Ok(HttpResponse::Ok().content_type("application/json").json( | ||
UserBudgetSync { | ||
updated_budget_count: count as u32, | ||
}, | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters