feat: error when starting BAL if user already has an ongoing one
All checks were successful
/ test (push) Successful in 15m24s
All checks were successful
/ test (push) Successful in 15m24s
This commit is contained in:
parent
c667608fbb
commit
ffa19712bd
2 changed files with 9 additions and 0 deletions
|
|
@ -25,6 +25,11 @@ pub enum BalState {
|
||||||
Ended
|
Ended
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_ongoing_bal<C>(db_conn: &C, user_id: u32) -> Option<Model>
|
||||||
|
where C: ConnectionTrait {
|
||||||
|
Entity::find().filter(Column::UserId.eq(user_id)).filter(Column::State.eq(BalState::Ongoing)).one(db_conn).await.unwrap_or(None)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
#[sea_orm(has_many = "super::book_instance::Entity")]
|
#[sea_orm(has_many = "super::book_instance::Entity")]
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ pub async fn update_bal(
|
||||||
responses(
|
responses(
|
||||||
(status = OK, body = bal::Model, description = "Successfully started bal"),
|
(status = OK, body = bal::Model, description = "Successfully started bal"),
|
||||||
(status = CONFLICT, description = "The specified BAL was not in a Pending state, cannot start it"),
|
(status = CONFLICT, description = "The specified BAL was not in a Pending state, cannot start it"),
|
||||||
|
(status = CONFLICT, description = "Cannot have multiple ongoing BALs at the same time !"),
|
||||||
(status = NOT_FOUND, description = "No bal with specified id was found"),
|
(status = NOT_FOUND, description = "No bal with specified id was found"),
|
||||||
(status = FORBIDDEN, description = "You don't own the specified bal"),
|
(status = FORBIDDEN, description = "You don't own the specified bal"),
|
||||||
),
|
),
|
||||||
|
|
@ -179,6 +180,9 @@ pub async fn start_bal(
|
||||||
if bal.state != BalState::Pending {
|
if bal.state != BalState::Pending {
|
||||||
return (StatusCode::CONFLICT, Json(None));
|
return (StatusCode::CONFLICT, Json(None));
|
||||||
}
|
}
|
||||||
|
if bal::get_user_ongoing_bal(state.db_conn.as_ref(), claims.user_id).await.is_some() {
|
||||||
|
return (StatusCode::CONFLICT, Json(None));
|
||||||
|
}
|
||||||
let mut bal: bal::ActiveModel = bal.into();
|
let mut bal: bal::ActiveModel = bal.into();
|
||||||
bal.state = Set(BalState::Ongoing);
|
bal.state = Set(BalState::Ongoing);
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue