Add bots count limit

This commit is contained in:
2024-01-07 22:23:58 +01:00
parent ccb096f2e6
commit 92b828265b
3 changed files with 69 additions and 58 deletions

View File

@@ -20,7 +20,7 @@ use crate::{
pub type Database = Extension<Arc<PrismaClient>>;
//
const BOTS_COUNT_LIMIT: i64 = 3;
async fn get_services(db: Database) -> impl IntoResponse {
let services = db
@@ -84,6 +84,17 @@ async fn create_service(db: Database, Json(data): Json<CreateServiceData>) -> im
username,
} = data;
let exist_count = db
.service()
.count(vec![service::user::equals(user)])
.exec()
.await
.unwrap();
if exist_count >= BOTS_COUNT_LIMIT {
return StatusCode::PAYMENT_REQUIRED.into_response();
};
let service = db
.service()
.create(