validation backend
This commit is contained in:
@@ -16,12 +16,14 @@ use crate::server::services::{
|
|||||||
use common::proto::komp_ac::{
|
use common::proto::komp_ac::{
|
||||||
table_structure::table_structure_service_server::TableStructureServiceServer,
|
table_structure::table_structure_service_server::TableStructureServiceServer,
|
||||||
table_definition::table_definition_server::TableDefinitionServer,
|
table_definition::table_definition_server::TableDefinitionServer,
|
||||||
|
table_validation::table_validation_service_server::TableValidationServiceServer,
|
||||||
tables_data::tables_data_server::TablesDataServer,
|
tables_data::tables_data_server::TablesDataServer,
|
||||||
table_script::table_script_server::TableScriptServer,
|
table_script::table_script_server::TableScriptServer,
|
||||||
auth::auth_service_server::AuthServiceServer,
|
auth::auth_service_server::AuthServiceServer,
|
||||||
search2::search2_server::Search2Server,
|
search2::search2_server::Search2Server,
|
||||||
};
|
};
|
||||||
use search::{SearcherService, SearcherServer};
|
use search::{SearcherService, SearcherServer};
|
||||||
|
use crate::table_validation::post::service::TableValidationSvc;
|
||||||
|
|
||||||
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Initialize JWT for authentication
|
// Initialize JWT for authentication
|
||||||
@@ -43,6 +45,7 @@ pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error:
|
|||||||
|
|
||||||
// Initialize services, passing the indexer sender to the relevant ones
|
// Initialize services, passing the indexer sender to the relevant ones
|
||||||
let table_definition_service = TableDefinitionService { db_pool: db_pool.clone() };
|
let table_definition_service = TableDefinitionService { db_pool: db_pool.clone() };
|
||||||
|
let table_validation_service = TableValidationSvc { db: db_pool.clone() };
|
||||||
let tables_data_service = TablesDataService {
|
let tables_data_service = TablesDataService {
|
||||||
db_pool: db_pool.clone(),
|
db_pool: db_pool.clone(),
|
||||||
indexer_tx: indexer_tx.clone(),
|
indexer_tx: indexer_tx.clone(),
|
||||||
@@ -55,6 +58,7 @@ pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error:
|
|||||||
Server::builder()
|
Server::builder()
|
||||||
.add_service(TableStructureServiceServer::new(TableStructureHandler { db_pool: db_pool.clone() }))
|
.add_service(TableStructureServiceServer::new(TableStructureHandler { db_pool: db_pool.clone() }))
|
||||||
.add_service(TableDefinitionServer::new(table_definition_service))
|
.add_service(TableDefinitionServer::new(table_definition_service))
|
||||||
|
.add_service(TableValidationServiceServer::new(table_validation_service))
|
||||||
.add_service(TablesDataServer::new(tables_data_service))
|
.add_service(TablesDataServer::new(tables_data_service))
|
||||||
.add_service(TableScriptServer::new(table_script_service))
|
.add_service(TableScriptServer::new(table_script_service))
|
||||||
.add_service(AuthServiceServer::new(auth_service))
|
.add_service(AuthServiceServer::new(auth_service))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub mod table_structure_service;
|
pub mod table_structure_service;
|
||||||
pub mod table_definition_service;
|
pub mod table_definition_service;
|
||||||
|
pub mod table_validation_service;
|
||||||
pub mod tables_data_service;
|
pub mod tables_data_service;
|
||||||
pub mod table_script_service;
|
pub mod table_script_service;
|
||||||
pub mod auth_service;
|
pub mod auth_service;
|
||||||
@@ -9,6 +10,7 @@ pub mod search2_service;
|
|||||||
|
|
||||||
pub use table_structure_service::TableStructureHandler;
|
pub use table_structure_service::TableStructureHandler;
|
||||||
pub use table_definition_service::TableDefinitionService;
|
pub use table_definition_service::TableDefinitionService;
|
||||||
|
pub use table_validation_service::*;
|
||||||
pub use tables_data_service::TablesDataService;
|
pub use tables_data_service::TablesDataService;
|
||||||
pub use table_script_service::TableScriptService;
|
pub use table_script_service::TableScriptService;
|
||||||
pub use auth_service::AuthServiceImpl;
|
pub use auth_service::AuthServiceImpl;
|
||||||
|
|||||||
11
server/src/server/services/table_validation_service.rs
Normal file
11
server/src/server/services/table_validation_service.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// src/server/services/table_validation_service.rs
|
||||||
|
|
||||||
|
use tonic::transport::Server;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use common::proto::komp_ac::table_validation::table_validation_service_server::TableValidationServiceServer;
|
||||||
|
use crate::table_validation::get::service::TableValidationSvc;
|
||||||
|
|
||||||
|
pub fn svc(db: PgPool) -> TableValidationServiceServer<TableValidationSvc> {
|
||||||
|
TableValidationServiceServer::new(TableValidationSvc { db })
|
||||||
|
}
|
||||||
2
server/src/table_validation/get/mod.rs
Normal file
2
server/src/table_validation/get/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// src/table_validation/get/mod.rs
|
||||||
|
pub mod service;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/table_validation/service.rs
|
// src/table_validation/get/service.rs
|
||||||
|
|
||||||
use tonic::{Request, Response, Status};
|
use tonic::{Request, Response, Status};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
@@ -8,7 +8,7 @@ use common::proto::komp_ac::table_validation::{
|
|||||||
GetTableValidationRequest, TableValidationResponse,
|
GetTableValidationRequest, TableValidationResponse,
|
||||||
FieldValidation, CharacterLimits, CountMode as PbCountMode,
|
FieldValidation, CharacterLimits, CountMode as PbCountMode,
|
||||||
};
|
};
|
||||||
use crate::table_validation::repo;
|
use crate::table_validation::post::repo; // repo still lives in post
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct FieldConfig {
|
struct FieldConfig {
|
||||||
@@ -58,6 +58,14 @@ impl TableValidationService for TableValidationSvc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(cl) = cfg.character_limits {
|
if let Some(cl) = cfg.character_limits {
|
||||||
|
let min = cl.min.unwrap_or(0);
|
||||||
|
let max = cl.max.unwrap_or(0);
|
||||||
|
|
||||||
|
// Skip "empty" validations (min=0,max=0,warn_at=None)
|
||||||
|
if min == 0 && max == 0 && cl.warn_at.is_none() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let pb_mode = match cl.count_mode.as_deref() {
|
let pb_mode = match cl.count_mode.as_deref() {
|
||||||
Some("BYTES") => PbCountMode::Bytes as i32,
|
Some("BYTES") => PbCountMode::Bytes as i32,
|
||||||
Some("DISPLAY_WIDTH") => PbCountMode::DisplayWidth as i32,
|
Some("DISPLAY_WIDTH") => PbCountMode::DisplayWidth as i32,
|
||||||
@@ -65,8 +73,8 @@ impl TableValidationService for TableValidationSvc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let limits = CharacterLimits {
|
let limits = CharacterLimits {
|
||||||
min: cl.min.unwrap_or(0),
|
min,
|
||||||
max: cl.max.unwrap_or(0),
|
max,
|
||||||
warn_at: cl.warn_at,
|
warn_at: cl.warn_at,
|
||||||
count_mode: pb_mode,
|
count_mode: pb_mode,
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/table_validation/mod.rs
|
// src/table_validation/mod.rs
|
||||||
|
|
||||||
pub mod repo;
|
pub mod post;
|
||||||
pub mod service;
|
pub mod get;
|
||||||
|
|||||||
3
server/src/table_validation/post/mod.rs
Normal file
3
server/src/table_validation/post/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// src/table_validation/post/mod.rs
|
||||||
|
|
||||||
|
pub mod repo;
|
||||||
Reference in New Issue
Block a user