mirror of
https://github.com/flibusta-apps/services_manager_server.git
synced 2025-12-06 12:35:39 +01:00
Add bots count limit
This commit is contained in:
13
src/views.rs
13
src/views.rs
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user