diff --git a/.sqlx/query-01bfc85cadf1d4f435adc819ea22843f10bcf2478f71d295d27c483ae5cbc92a.json b/.sqlx/query-01bfc85cadf1d4f435adc819ea22843f10bcf2478f71d295d27c483ae5cbc92a.json new file mode 100644 index 0000000..003abaa --- /dev/null +++ b/.sqlx/query-01bfc85cadf1d4f435adc819ea22843f10bcf2478f71d295d27c483ae5cbc92a.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE\n client_orders\n SET\n work_piece = $1,\n quantity = $2,\n due_date = $3,\n late_pen = $4,\n early_pen = $5\n WHERE\n client_name_id = $6 AND order_number = $7", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Int4", + "Int4", + "Money", + "Money", + "Text", + "Int8" + ] + }, + "nullable": [] + }, + "hash": "01bfc85cadf1d4f435adc819ea22843f10bcf2478f71d295d27c483ae5cbc92a" +} diff --git a/.sqlx/query-08f2e4f17a552ff708457691c7c323e2e5a345a5248ce1c8ee1031306f050023.json b/.sqlx/query-08f2e4f17a552ff708457691c7c323e2e5a345a5248ce1c8ee1031306f050023.json new file mode 100644 index 0000000..c09f1c4 --- /dev/null +++ b/.sqlx/query-08f2e4f17a552ff708457691c7c323e2e5a345a5248ce1c8ee1031306f050023.json @@ -0,0 +1,58 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM client_orders WHERE client_name_id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "client_name_id", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "order_number", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "work_piece", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "quantity", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "due_date", + "type_info": "Int4" + }, + { + "ordinal": 5, + "name": "late_pen", + "type_info": "Money" + }, + { + "ordinal": 6, + "name": "early_pen", + "type_info": "Money" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "08f2e4f17a552ff708457691c7c323e2e5a345a5248ce1c8ee1031306f050023" +} diff --git a/.sqlx/query-3c1276ce5af1d1557fd952e473343a8ea1d3e27a27a30ec759873e66e96ec128.json b/.sqlx/query-3c1276ce5af1d1557fd952e473343a8ea1d3e27a27a30ec759873e66e96ec128.json index 6b1cd56..6d75ea8 100644 --- a/.sqlx/query-3c1276ce5af1d1557fd952e473343a8ea1d3e27a27a30ec759873e66e96ec128.json +++ b/.sqlx/query-3c1276ce5af1d1557fd952e473343a8ea1d3e27a27a30ec759873e66e96ec128.json @@ -5,13 +5,13 @@ "columns": [ { "ordinal": 0, - "name": "order_number", - "type_info": "Int8" + "name": "client_name_id", + "type_info": "Varchar" }, { "ordinal": 1, - "name": "client_name_id", - "type_info": "Varchar" + "name": "order_number", + "type_info": "Int8" }, { "ordinal": 2, diff --git a/.sqlx/query-60e5f498ed312e9fb7f55e636f14e9f57d07fdda96855647dbf644f3f2f80ba2.json b/.sqlx/query-60e5f498ed312e9fb7f55e636f14e9f57d07fdda96855647dbf644f3f2f80ba2.json new file mode 100644 index 0000000..2eef7d8 --- /dev/null +++ b/.sqlx/query-60e5f498ed312e9fb7f55e636f14e9f57d07fdda96855647dbf644f3f2f80ba2.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO client_orders VALUES ($1, $2, $3, $4, $5, $6, $7)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Int8", + "Varchar", + "Int4", + "Int4", + "Money", + "Money" + ] + }, + "nullable": [] + }, + "hash": "60e5f498ed312e9fb7f55e636f14e9f57d07fdda96855647dbf644f3f2f80ba2" +} diff --git a/.sqlx/query-6358621f0acd1ff42b9d6c1342342801b1e3d6cdd52909752b98e447569d98fc.json b/.sqlx/query-6358621f0acd1ff42b9d6c1342342801b1e3d6cdd52909752b98e447569d98fc.json new file mode 100644 index 0000000..107f5ce --- /dev/null +++ b/.sqlx/query-6358621f0acd1ff42b9d6c1342342801b1e3d6cdd52909752b98e447569d98fc.json @@ -0,0 +1,56 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM client_orders", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "client_name_id", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "order_number", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "work_piece", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "quantity", + "type_info": "Int4" + }, + { + "ordinal": 4, + "name": "due_date", + "type_info": "Int4" + }, + { + "ordinal": 5, + "name": "late_pen", + "type_info": "Money" + }, + { + "ordinal": 6, + "name": "early_pen", + "type_info": "Money" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "6358621f0acd1ff42b9d6c1342342801b1e3d6cdd52909752b98e447569d98fc" +} diff --git a/.sqlx/query-a3edcc0b4d08810d9bbee3f13a2fa0b1ed7c1464634716fc902d3c25372d5bf3.json b/.sqlx/query-a3edcc0b4d08810d9bbee3f13a2fa0b1ed7c1464634716fc902d3c25372d5bf3.json index aefe6db..bbbcf4a 100644 --- a/.sqlx/query-a3edcc0b4d08810d9bbee3f13a2fa0b1ed7c1464634716fc902d3c25372d5bf3.json +++ b/.sqlx/query-a3edcc0b4d08810d9bbee3f13a2fa0b1ed7c1464634716fc902d3c25372d5bf3.json @@ -5,13 +5,13 @@ "columns": [ { "ordinal": 0, - "name": "order_number", - "type_info": "Int8" + "name": "client_name_id", + "type_info": "Varchar" }, { "ordinal": 1, - "name": "client_name_id", - "type_info": "Varchar" + "name": "order_number", + "type_info": "Int8" }, { "ordinal": 2, diff --git a/.sqlx/query-b8b9deea1f5d051398a9e38bbdb2c3209d7e9940710224661c48aa3358ac5ae6.json b/.sqlx/query-b8b9deea1f5d051398a9e38bbdb2c3209d7e9940710224661c48aa3358ac5ae6.json new file mode 100644 index 0000000..7d096f5 --- /dev/null +++ b/.sqlx/query-b8b9deea1f5d051398a9e38bbdb2c3209d7e9940710224661c48aa3358ac5ae6.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM client_orders WHERE client_name_id = $1 AND order_number = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Int8" + ] + }, + "nullable": [] + }, + "hash": "b8b9deea1f5d051398a9e38bbdb2c3209d7e9940710224661c48aa3358ac5ae6" +} diff --git a/Cargo.lock b/Cargo.lock index 808cf65..7053ffd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -439,6 +439,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dotenvy" version = "0.15.7" @@ -916,6 +922,7 @@ name = "infi-erp" version = "0.1.0" dependencies = [ "color-eyre", + "dotenv", "poem", "poem-openapi", "serde", diff --git a/Cargo.toml b/Cargo.toml index f303d6c..f8bdcd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ sqlx = { version = "0.7", features = [ "tls-rustls", "macros", ] } +dotenv = "0.15.0" diff --git a/migrations/001_t_client_orders.sql b/migrations/001_t_client_orders.sql index 3f205ad..79326b6 100644 --- a/migrations/001_t_client_orders.sql +++ b/migrations/001_t_client_orders.sql @@ -1,9 +1,11 @@ CREATE TABLE IF NOT EXISTS client_orders ( - order_number bigint NOT NULL primary key, - client_name_id varchar NOT NULL, - work_piece varchar NOT NULL, - quantity int NOT NULL, - due_date int NOT NULL, - late_pen money NOT NULL, - early_pen money NOT NULL + client_name_id varchar , + order_number bigint , + work_piece varchar NOT NULL, + quantity int NOT NULL, + due_date int NOT NULL, + late_pen money NOT NULL, + early_pen money NOT NULL, + + PRIMARY KEY (client_name_id, order_number) ); diff --git a/migrations/002_t_supplier_data.sql b/migrations/002_t_supplier_data.sql index cc65fcf..51b0b08 100644 --- a/migrations/002_t_supplier_data.sql +++ b/migrations/002_t_supplier_data.sql @@ -1,32 +1,33 @@ CREATE TABLE IF NOT EXISTS suppliers ( - supplier_id varchar NOT NULL primary key, - name varchar NOT NULL, - piece varchar NOT NULL, - min_order int NOT NULL, - price_per_piece money NOT NULL, - delivery_time interval NOT NULL + name varchar , + piece varchar , + min_order int NOT NULL, + price_per_piece money NOT NULL, + delivery_time interval NOT NULL, + + PRIMARY KEY (name, piece) ); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('A_P1', 'Supplier A', 'P1', 16, '$30', '4 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier A', 'P1', 16, '$30', '4 days'); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('A_P2', 'Supplier A', 'P2', 16, '$10', '4 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier A', 'P2', 16, '$10', '4 days'); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('B_P1', 'Supplier B', 'P1', 8, '$45', '2 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier B', 'P1', 8, '$45', '2 days'); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('B_P2', 'Supplier B', 'P2', 8, '$15', '2 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier B', 'P2', 8, '$15', '2 days'); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('C_P1', 'Supplier C', 'P1', 4, '$55', '1 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier C', 'P1', 4, '$55', '1 days'); INSERT INTO suppliers ( - supplier_id, name, piece, min_order, price_per_piece, delivery_time -) VALUES ('C_P2', 'Supplier C', 'P2', 4, '$18', '1 days'); + name, piece, min_order, price_per_piece, delivery_time +) VALUES ('Supplier C', 'P2', 4, '$18', '1 days'); diff --git a/migrations/004_t_pieces.sql b/migrations/004_t_pieces.sql index 32a7ba3..d000199 100644 --- a/migrations/004_t_pieces.sql +++ b/migrations/004_t_pieces.sql @@ -1,12 +1,18 @@ -- TODO: Rethink this table design afte more of the -- sistem funcionality comes online CREATE TABLE IF NOT EXISTS pieces ( - id bigserial NOT NULL primary key, - piece_type varchar NOT NULL , - -- Probably not necessary? - client_order int NOT NULL references client_orders(order_number), + piece_id int GENERATED ALWAYS AS IDENTITY, + piece_type varchar , + client_name varchar , + order_number bigint , raw_mat_cost money NOT NULL , -- raw material cost raw_mat_arr_date int NOT NULL , -- raw material arrival date dispatch_date int , -- Query to MES - total_prod_time int -- Query to MES (in seconds) + total_prod_time int , -- Query to MES (in seconds) + + PRIMARY KEY (piece_id), + + CONSTRAINT fk_client_order + FOREIGN KEY(client_name, order_number) REFERENCES client_orders(client_name_id, order_number) + ON DELETE SET NULL -- NOTE: may be able to be altered to ON DELETE CASCADE ); diff --git a/src/db.rs b/src/db.rs deleted file mode 100644 index d3dbdf5..0000000 --- a/src/db.rs +++ /dev/null @@ -1,135 +0,0 @@ -use core::fmt; - -use sqlx::{ - error::BoxDynError, postgres::types::PgMoney, prelude::FromRow, query_as, - PgPool, -}; - -#[derive(Debug, PartialEq, Eq, FromRow)] -pub struct ClientOrder { - pub order_number: i64, - pub client_name_id: String, - pub work_piece: String, //TODO: Change to enum if possible - pub quantity: i32, - pub due_date: i32, - pub late_pen: PgMoney, - pub early_pen: PgMoney, -} - -impl fmt::Display for ClientOrder { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "\ - \tOrder Number:\t{}\n\ - \tClient:\t\t{}\n\ - \tWork Piece:\t{}\n\ - \tQuantity:\t{}\n\ - \tDue Date:\t{}\n\ - \tLate Pen:\t{:?}\n\ - \tEarly Pen:\t{:?}\n\ - ", - self.order_number, - self.client_name_id, - self.work_piece, - self.quantity, - self.due_date, - self.late_pen, - self.early_pen, - ) - } -} - -pub async fn update_order( - new: ClientOrder, - old_number: i64, - pool: &PgPool, -) -> Result<(), BoxDynError> { - sqlx::query!( - " - UPDATE - client_orders - SET - client_name_id = $1, - work_piece = $2, - quantity = $3, - due_date = $4, - late_pen = $5, - early_pen = $6 - WHERE - order_number = $7 - ", - new.client_name_id, - new.work_piece, - new.quantity, - new.due_date, - new.late_pen, - new.early_pen, - old_number, - ) - .execute(pool) - .await?; - Ok(()) -} - -pub async fn place_order( - order: &ClientOrder, - pool: &PgPool, -) -> Result<(), BoxDynError> { - sqlx::query!( - " - INSERT INTO - client_orders - ( - order_number, - client_name_id, - work_piece, - Quantity, - due_date, - late_pen, - early_pen - ) - VALUES - ($1, $2, $3, $4, $5, $6, $7) - ", - order.order_number, - order.client_name_id, - order.work_piece, - order.quantity, - order.due_date, - order.late_pen, - order.early_pen - ) - .execute(pool) - .await?; - - Ok(()) -} - -//NOTE: return whether the order was placed or not -pub async fn place_unique_order( - order: &ClientOrder, - pool: &PgPool, -) -> Result<(), BoxDynError> { - let query = query_as!( - ClientOrder, - "SELECT * FROM client_orders WHERE order_number = $1", - order.order_number - ); - let orders = query.fetch_all(pool).await?; - if orders.is_empty() { - place_order(order, pool).await?; - } - Ok(()) -} - -pub async fn fetch_all_orders( - pool: &PgPool, -) -> Result, BoxDynError> { - let query = query_as!( - ClientOrder, - "SELECT * FROM client_orders ORDER BY order_number" - ); - let orders = query.fetch_all(pool).await?; - Ok(orders) -} diff --git a/src/main.rs b/src/main.rs index 99bb7f7..45c2734 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,15 @@ #![forbid(unsafe_code)] #![allow(dead_code, unused_variables)] -mod db; mod xml; use color_eyre::eyre::Result; use poem::{ - error::InternalServerError, listener::TcpListener, web::Data, EndpointExt, - Route, Server, + error::InternalServerError, + listener::TcpListener, + web::{Data, Path}, + EndpointExt, Route, Server, }; use poem_openapi::{ @@ -18,72 +19,201 @@ use poem_openapi::{ use sqlx::{ error::BoxDynError, - migrate, - postgres::{self, PgPool}, + postgres::{types::PgMoney, PgPool}, }; -use tracing::info; -use crate::xml::parse_xml; +#[derive(Object)] +struct Money { + cents: i64, +} + +impl From for Money { + fn from(value: PgMoney) -> Self { + Money { cents: value.0 } + } +} #[derive(Object)] -struct ClientOrder { - order_number: i64, +struct ClientOrderPayload { client_name_id: String, + order_number: i64, work_piece: String, quantity: i32, due_date: i32, - late_pen: i64, - early_pen: i64, + late_pen: Money, + early_pen: Money, +} + +#[derive(Object)] +struct DeleteOrderPayload { + client_name_id: String, + order_number: i64, } -type ClientOrderResponse = poem::Result>>; +type ClientOrderResponse = poem::Result>>; struct ClientOrderApi; #[OpenApi] impl ClientOrderApi { + #[oai(path = "/", method = "get")] + async fn index(&self) -> PlainText<&'static str> { + PlainText("Hello, world!") + } + + #[oai(path = "/orders/:name", method = "get")] + async fn get_from_client( + &self, + name: Path, + pool: Data<&PgPool>, + ) -> ClientOrderResponse { + tracing::info!("Fetching orders for: {}", name.0); + + let orders = sqlx::query_as!( + ClientOrderPayload, + "SELECT * FROM client_orders WHERE client_name_id = $1", + name.0 + ) + .fetch_all(pool.0) + .await + .map_err(InternalServerError)?; + + match orders.is_empty() { + true => Err(poem::error::NotFoundError.into()), + false => Ok(Json(orders)), + } + } + #[oai(path = "/orders", method = "get")] async fn get_all(&self, pool: Data<&PgPool>) -> ClientOrderResponse { - // TODO : get orders from db - - Ok(Json(vec![ClientOrder { - order_number: 1, - client_name_id: "client".to_string(), - work_piece: "work".to_string(), - quantity: 1, - due_date: 1, - late_pen: 1, - early_pen: 1, - }])) + let query = + sqlx::query_as!(ClientOrderPayload, "SELECT * FROM client_orders"); + + let orders = + query.fetch_all(pool.0).await.map_err(InternalServerError)?; + + if orders.is_empty() { + return Err(poem::error::NotFoundError.into()); + } + + Ok(Json(orders)) } #[oai(path = "/orders", method = "post")] async fn place_order( &self, pool: Data<&PgPool>, - order: Json, - ) -> poem::Result> { - // TODO : place order in db - Ok(Json(1)) + order: Json, + ) -> poem::Result<()> { + let order = order.0; + + sqlx::query!( + "INSERT INTO client_orders VALUES ($1, $2, $3, $4, $5, $6, $7)", + order.client_name_id, + order.order_number, + order.work_piece, + order.quantity, + order.due_date, + PgMoney(order.late_pen.cents), + PgMoney(order.early_pen.cents) + ) + .execute(pool.0) + .await + .map_err(InternalServerError)?; + + Ok(()) + } + + #[oai(path = "/orders", method = "put")] + async fn update_order( + &self, + pool: Data<&PgPool>, + order: Json, + ) -> poem::Result<()> { + let order = order.0; + + tracing::info!( + "Updating order: {} {}", + order.client_name_id, + order.order_number + ); + + sqlx::query!( + "UPDATE + client_orders + SET + work_piece = $1, + quantity = $2, + due_date = $3, + late_pen = $4, + early_pen = $5 + WHERE + client_name_id = $6 AND order_number = $7", + order.work_piece, + order.quantity, + order.due_date, + PgMoney(order.late_pen.cents), + PgMoney(order.early_pen.cents), + order.client_name_id, + order.order_number + ) + .execute(pool.0) + .await + .map_err(InternalServerError)?; + + Ok(()) + } + + #[oai(path = "/orders", method = "delete")] + async fn delete_order( + &self, + pool: Data<&PgPool>, + order: Json, + ) -> poem::Result<()> { + let order = order.0; + + tracing::info!( + "Deleting order: {} - {}", + order.client_name_id, + order.order_number + ); + + sqlx::query!( + "DELETE FROM client_orders \ + WHERE client_name_id = $1 AND order_number = $2", + order.client_name_id, + order.order_number + ) + .execute(pool.0) + .await + .map_err(InternalServerError)?; + + Ok(()) } } #[tokio::main] async fn main() -> Result<(), BoxDynError> { color_eyre::install()?; + dotenv::dotenv().ok(); tracing_subscriber::fmt::init(); let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL is not set"); let pool = PgPool::connect(db_url.as_str()).await?; + // NOTE: Run the migrations, only if necessary + sqlx::migrate!("./migrations").run(&pool).await?; + let api_service = OpenApiService::new(ClientOrderApi, "ClientOrders", "1.0.0") .server("http://localhost:3000"); - let ui = api_service.rapidoc(); //NOTE: #1 + + let ui = api_service.rapidoc(); //NOTE: Best looking out of the box + let route = Route::new() .nest("/", api_service) - .nest("/ui", ui) + .nest("/orders/ui", ui) .data(pool); Server::new(TcpListener::bind("0.0.0.0:3000")) @@ -92,36 +222,3 @@ async fn main() -> Result<(), BoxDynError> { Ok(()) } - -async fn temp_stuff() -> Result<(), BoxDynError> { - let db_url = "postgres://admin:admin@localhost:5432/infi-postgres"; - let pool = PgPool::connect(db_url).await?; - migrate!("./migrations").run(&pool).await?; // Runs only if needed - - let file = "mock_dataset.xml"; - let orders = parse_xml(file).await?; - info!("Parsed orders: {:?}", orders.len()); - - let mut handles = Vec::with_capacity(orders.len()); - for order in orders { - let pool = pool.clone(); - let handle = tokio::task::spawn(async move { - match db::place_unique_order(&order, &pool).await { - Ok(_) => {} - Err(err) => println!("Error: {:?}", err), - } - }); - handles.push(handle); - } - - info!("Orders to place: {:?}", handles.len()); - for handle in handles { - handle.await?; - } - info!("All orders placed"); - - let orders = db::fetch_all_orders(&pool).await?; - info!("Orders fetched: {:?}", orders.len()); - - Ok(()) -} diff --git a/src/xml.rs b/src/xml.rs index be61ce9..6cb9dfb 100644 --- a/src/xml.rs +++ b/src/xml.rs @@ -1,8 +1,4 @@ use serde::{Deserialize, Serialize}; -use serde_xml_rs::from_str; -use sqlx::{error::BoxDynError, postgres::types::PgMoney}; - -use crate::db::ClientOrder; #[derive(Debug, Deserialize)] struct Dataset { @@ -33,53 +29,57 @@ impl std::fmt::Display for WorkdPiece { pub struct RawClientOrder { pub ordernumber: i64, pub clientnameid: String, - pub workpiece: WorkdPiece, //TODO: Change to enum if possible + pub workpiece: WorkdPiece, pub quantity: i32, pub duedate: i32, pub latepen: String, pub earlypen: String, } - -impl TryInto for RawClientOrder { - type Error = BoxDynError; - fn try_into(self) -> Result { - let mut latepen = self.latepen.clone(); - let mut earlypen = self.earlypen.clone(); - - for c in ['$', '.'] { - if let Some(index) = latepen.find(c) { - latepen.remove(index); - } - if let Some(index) = earlypen.find(c) { - earlypen.remove(index); - } - } - - let latepen = PgMoney::from(latepen.parse::()?); - let earlypen = PgMoney::from(earlypen.parse::()?); - - Ok(ClientOrder { - order_number: self.ordernumber, - client_name_id: self.clientnameid, - work_piece: self.workpiece.to_string(), - quantity: self.quantity, - due_date: self.duedate, - late_pen: latepen, - early_pen: earlypen, - }) - } -} - -pub async fn parse_xml(data: &str) -> Result, BoxDynError> { - let file = std::fs::read_to_string(data)?; - let dataset: Dataset = from_str(file.as_str())?; - let orders = dataset - .orders - .into_iter() - .map(|o| o.try_into()) - .collect::>>(); - - orders - .into_iter() - .collect::, BoxDynError>>() -} +//NOTE: Commented until i re-implemnet the conversion +// +// use serde_xml_rs::from_str; +// use sqlx::{error::BoxDynError, postgres::types::PgMoney}; +// +// impl TryInto for RawClientOrder { +// type Error = BoxDynError; +// fn try_into(self) -> Result { +// let mut latepen = self.latepen.clone(); +// let mut earlypen = self.earlypen.clone(); +// +// for c in ['$', '.'] { +// if let Some(index) = latepen.find(c) { +// latepen.remove(index); +// } +// if let Some(index) = earlypen.find(c) { +// earlypen.remove(index); +// } +// } +// +// let latepen = PgMoney::from(latepen.parse::()?); +// let earlypen = PgMoney::from(earlypen.parse::()?); +// +// Ok(ClientOrder { +// order_number: self.ordernumber, +// client_name_id: self.clientnameid, +// work_piece: self.workpiece.to_string(), +// quantity: self.quantity, +// due_date: self.duedate, +// late_pen: latepen, +// early_pen: earlypen, +// }) +// } +// } +// +// pub async fn parse_xml(data: &str) -> Result, BoxDynError> { +// let file = std::fs::read_to_string(data)?; +// let dataset: Dataset = from_str(file.as_str())?; +// let orders = dataset +// .orders +// .into_iter() +// .map(|o| o.try_into()) +// .collect::>>(); +// +// orders +// .into_iter() +// .collect::, BoxDynError>>() +// }