trying to make the post request into the scripts

This commit is contained in:
filipriec
2025-03-08 11:51:26 +01:00
parent 53ab9ad7d7
commit 8ad2179d86
7 changed files with 342 additions and 15 deletions

View File

@@ -8,13 +8,15 @@ use crate::server::services::{
UctovnictvoService,
TableStructureHandler,
TableDefinitionService,
TablesDataService, // Add this
TablesDataService,
TableScriptService,
};
use common::proto::multieko2::adresar::adresar_server::AdresarServer;
use common::proto::multieko2::uctovnictvo::uctovnictvo_server::UctovnictvoServer;
use common::proto::multieko2::table_structure::table_structure_service_server::TableStructureServiceServer;
use common::proto::multieko2::table_definition::table_definition_server::TableDefinitionServer;
use common::proto::multieko2::tables_data::tables_data_server::TablesDataServer; // Add this
use common::proto::multieko2::tables_data::tables_data_server::TablesDataServer;
use common::proto::multieko2::table_script::table_script_server::TableScriptServer;
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse()?;
@@ -26,13 +28,15 @@ pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error:
// Initialize services
let table_definition_service = TableDefinitionService { db_pool: db_pool.clone() };
let tables_data_service = TablesDataService { db_pool: db_pool.clone() }; // Add this
let table_script_service = TableScriptService { db_pool: db_pool.clone() };
Server::builder()
.add_service(AdresarServer::new(AdresarService { db_pool: db_pool.clone() }))
.add_service(UctovnictvoServer::new(UctovnictvoService { db_pool: db_pool.clone() }))
.add_service(TableStructureServiceServer::new(TableStructureHandler { db_pool: db_pool.clone() }))
.add_service(TableDefinitionServer::new(table_definition_service))
.add_service(TablesDataServer::new(tables_data_service)) // Add this
.add_service(TablesDataServer::new(tables_data_service))
.add_service(TableScriptServer::new(table_script_service))
.add_service(reflection_service)
.serve(addr)
.await?;

View File

@@ -5,9 +5,11 @@ pub mod table_structure_service;
pub mod uctovnictvo_service;
pub mod table_definition_service;
pub mod tables_data_service;
pub mod table_script_service;
pub use adresar_service::AdresarService;
pub use table_structure_service::TableStructureHandler;
pub use uctovnictvo_service::UctovnictvoService;
pub use table_definition_service::TableDefinitionService;
pub use tables_data_service::TablesDataService;
pub use table_script_service::TableScriptService;

View File

@@ -0,0 +1,25 @@
// src/server/services/table_script_service.rs
use tonic::{Request, Response, Status};
use common::proto::multieko2::table_script::{
table_script_server::TableScript,
PostTableScriptRequest, TableScriptResponse
};
use crate::table_script::handlers::post_table_script;
use sqlx::PgPool;
#[derive(Debug)]
pub struct TableScriptService {
pub db_pool: PgPool,
}
#[tonic::async_trait]
impl TableScript for TableScriptService {
async fn post_table_script(
&self,
request: Request<PostTableScriptRequest>,
) -> Result<Response<TableScriptResponse>, Status> {
let request = request.into_inner();
let response = post_table_script(&self.db_pool, request).await?;
Ok(Response::new(response))
}
}

View File

@@ -1,12 +1,10 @@
// src/steel/validation/script.rs
use steel_core::steel_vm::engine::Engine;
use std::fmt;
#[derive(Debug)]
pub enum ScriptValidationError {
EmptyScript,
InvalidSyntax(String),
MissingTransformFunction,
}
impl fmt::Display for ScriptValidationError {
@@ -14,7 +12,6 @@ impl fmt::Display for ScriptValidationError {
match self {
Self::EmptyScript => write!(f, "Script cannot be empty"),
Self::InvalidSyntax(msg) => write!(f, "Syntax error: {}", msg),
Self::MissingTransformFunction => write!(f, "Script must define a 'transform' function"),
}
}
}
@@ -24,14 +21,7 @@ pub fn validate_script(script: &str) -> Result<(), ScriptValidationError> {
if script.trim().is_empty() {
return Err(ScriptValidationError::EmptyScript);
}
// Create a new Steel engine
let mut engine = Engine::new();
// Check for the presence of a 'transform' function
if engine.extract_value("transform").is_err() {
return Err(ScriptValidationError::MissingTransformFunction);
}
// If we get here, the script passed basic validation
Ok(())
}