Can create a movement

This commit is contained in:
2025-04-15 22:39:42 +02:00
parent 5a51dee8b0
commit b4cf6624f7
9 changed files with 160 additions and 0 deletions

View File

@ -5,6 +5,7 @@ use std::error::Error;
pub mod accounts_controller;
pub mod auth_controller;
pub mod files_controller;
pub mod movement_controller;
pub mod server_controller;
pub mod static_controller;
pub mod tokens_controller;

View File

@ -0,0 +1,16 @@
use crate::controllers::HttpResult;
use crate::extractors::auth_extractor::AuthExtractor;
use crate::services::movements_service;
use crate::services::movements_service::UpdateMovementQuery;
use actix_web::{HttpResponse, web};
/// Create a new movement
pub async fn create(auth: AuthExtractor, req: web::Json<UpdateMovementQuery>) -> HttpResult {
if let Some(err) = req.check_error(auth.user_id()).await? {
return Ok(HttpResponse::BadRequest().json(err));
}
movements_service::create(&req).await?;
Ok(HttpResponse::Created().finish())
}

View File

@ -41,6 +41,7 @@ pub struct ServerConstraints {
pub token_ip_net: LenConstraints,
pub token_max_inactivity: LenConstraints,
pub account_name: LenConstraints,
pub movement_label: LenConstraints,
}
impl Default for ServerConstraints {
@ -50,6 +51,7 @@ impl Default for ServerConstraints {
token_ip_net: LenConstraints::max_only(44),
token_max_inactivity: LenConstraints::new(3600, 3600 * 24 * 365),
account_name: LenConstraints::not_empty(50),
movement_label: LenConstraints::not_empty(200),
}
}
}