diff --git a/.sqlx/query-1c8be5c0021c10a1377ac2a03d9b3f8b7e3994e0d4edf0e36275619d11a233f3.json b/.sqlx/query-053634754e0b3678d61c7dd5f89a894bc5619fa2f94cdbcc6dfd59bcc3aa123f.json similarity index 88% rename from .sqlx/query-1c8be5c0021c10a1377ac2a03d9b3f8b7e3994e0d4edf0e36275619d11a233f3.json rename to .sqlx/query-053634754e0b3678d61c7dd5f89a894bc5619fa2f94cdbcc6dfd59bcc3aa123f.json index 562b326..c5b009a 100644 --- a/.sqlx/query-1c8be5c0021c10a1377ac2a03d9b3f8b7e3994e0d4edf0e36275619d11a233f3.json +++ b/.sqlx/query-053634754e0b3678d61c7dd5f89a894bc5619fa2f94cdbcc6dfd59bcc3aa123f.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ? AND deleted IS NULL", + "query": "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ? AND CAST(strftime('%m', date_time) AS INTEGER) <= ?", "describe": { "columns": [ { @@ -50,7 +50,7 @@ } ], "parameters": { - "Right": 2 + "Right": 3 }, "nullable": [ false, @@ -64,5 +64,5 @@ false ] }, - "hash": "1c8be5c0021c10a1377ac2a03d9b3f8b7e3994e0d4edf0e36275619d11a233f3" + "hash": "053634754e0b3678d61c7dd5f89a894bc5619fa2f94cdbcc6dfd59bcc3aa123f" } diff --git a/.sqlx/query-77e028e8c559bdb0a725d6af0b75fc7048bb63735b359dc1365abbba68774a93.json b/.sqlx/query-77e028e8c559bdb0a725d6af0b75fc7048bb63735b359dc1365abbba68774a93.json deleted file mode 100644 index feba609..0000000 --- a/.sqlx/query-77e028e8c559bdb0a725d6af0b75fc7048bb63735b359dc1365abbba68774a93.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "db_name": "SQLite", - "query": "UPDATE extra_hours SET deleted = ?, update_version = ?, update_process = ? WHERE id = ?", - "describe": { - "columns": [], - "parameters": { - "Right": 4 - }, - "nullable": [] - }, - "hash": "77e028e8c559bdb0a725d6af0b75fc7048bb63735b359dc1365abbba68774a93" -} diff --git a/.sqlx/query-a90b5c6c759c7d5dc7beb05c8e90963c7eec7158004bc002b5fd81cffd0e17e2.json b/.sqlx/query-a90b5c6c759c7d5dc7beb05c8e90963c7eec7158004bc002b5fd81cffd0e17e2.json deleted file mode 100644 index b26757e..0000000 --- a/.sqlx/query-a90b5c6c759c7d5dc7beb05c8e90963c7eec7158004bc002b5fd81cffd0e17e2.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE id = ? AND deleted IS NULL", - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Blob" - }, - { - "name": "sales_person_id", - "ordinal": 1, - "type_info": "Blob" - }, - { - "name": "amount", - "ordinal": 2, - "type_info": "Float" - }, - { - "name": "category", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "description", - "ordinal": 4, - "type_info": "Text" - }, - { - "name": "date_time", - "ordinal": 5, - "type_info": "Text" - }, - { - "name": "created", - "ordinal": 6, - "type_info": "Text" - }, - { - "name": "deleted", - "ordinal": 7, - "type_info": "Text" - }, - { - "name": "update_version", - "ordinal": 8, - "type_info": "Blob" - } - ], - "parameters": { - "Right": 1 - }, - "nullable": [ - false, - false, - false, - false, - true, - false, - false, - true, - false - ] - }, - "hash": "a90b5c6c759c7d5dc7beb05c8e90963c7eec7158004bc002b5fd81cffd0e17e2" -} diff --git a/Cargo.lock b/Cargo.lock index 58748e4..b051355 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,7 @@ checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "app" -version = "0.1.5" +version = "0.1.1-dev" dependencies = [ "dao", "dao_impl", diff --git a/app/Cargo.toml b/app/Cargo.toml index 23076cf..a1283d5 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.1.5" +version = "0.1.1-dev" edition = "2021" resolver = "2" diff --git a/dao/src/extra_hours.rs b/dao/src/extra_hours.rs index 3989318..38a262f 100644 --- a/dao/src/extra_hours.rs +++ b/dao/src/extra_hours.rs @@ -28,11 +28,11 @@ pub struct ExtraHoursEntity { #[automock] #[async_trait] pub trait ExtraHoursDao { - async fn find_by_id(&self, id: Uuid) -> Result, crate::DaoError>; async fn find_by_sales_person_id_and_year( &self, sales_person_id: Uuid, year: u32, + until_week: u8, ) -> Result, crate::DaoError>; async fn create(&self, entity: &ExtraHoursEntity, process: &str) -> Result<(), crate::DaoError>; diff --git a/dao_impl/src/extra_hours.rs b/dao_impl/src/extra_hours.rs index 11f0404..6fe22e9 100644 --- a/dao_impl/src/extra_hours.rs +++ b/dao_impl/src/extra_hours.rs @@ -69,31 +69,19 @@ impl ExtraHoursDaoImpl { #[async_trait] impl ExtraHoursDao for ExtraHoursDaoImpl { - async fn find_by_id(&self, id: Uuid) -> Result, crate::DaoError> { - let id_vec = id.as_bytes().to_vec(); - Ok(query_as!( - ExtraHoursDb, - "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE id = ? AND deleted IS NULL", - id_vec, - ).fetch_optional(self.pool.as_ref()) - .await - .map_db_error()? - .as_ref() - .map(ExtraHoursEntity::try_from) - .transpose()?) - } - async fn find_by_sales_person_id_and_year( &self, sales_person_id: Uuid, year: u32, + until_week: u8, ) -> Result, crate::DaoError> { let id_vec = sales_person_id.as_bytes().to_vec(); Ok(query_as!( ExtraHoursDb, - "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ? AND deleted IS NULL", + "SELECT id, sales_person_id, amount, category, description, date_time, created, deleted, update_version FROM extra_hours WHERE sales_person_id = ? AND CAST(strftime('%Y', date_time) AS INTEGER) = ? AND CAST(strftime('%m', date_time) AS INTEGER) <= ?", id_vec, year, + until_week, ).fetch_all(self.pool.as_ref()) .await .map_db_error()? @@ -142,26 +130,10 @@ impl ExtraHoursDao for ExtraHoursDaoImpl { } async fn update( &self, - entity: &ExtraHoursEntity, - process: &str, + _entity: &ExtraHoursEntity, + _process: &str, ) -> Result<(), crate::DaoError> { - let id_vec = entity.id.as_bytes().to_vec(); - let version_vec = entity.version.as_bytes().to_vec(); - let delete = entity - .deleted - .map(|date_time| date_time.format(&Iso8601::DATE_TIME)) - .transpose()?; - query!( - "UPDATE extra_hours SET deleted = ?, update_version = ?, update_process = ? WHERE id = ?", - delete, - version_vec, - process, - id_vec, - ) - .execute(self.pool.as_ref()) - .await - .map_db_error()?; - Ok(()) + unimplemented!() } async fn delete(&self, _id: Uuid, _process: &str) -> Result<(), crate::DaoError> { unimplemented!() diff --git a/rest/src/extra_hours.rs b/rest/src/extra_hours.rs index d104c74..82d06cb 100644 --- a/rest/src/extra_hours.rs +++ b/rest/src/extra_hours.rs @@ -1,63 +1,14 @@ -use std::rc::Rc; - use axum::{ - body::Body, - extract::{Path, Query, State}, - response::Response, - routing::{delete, get, post}, - Extension, Json, Router, + body::Body, extract::State, response::Response, routing::post, Extension, Json, Router, }; use rest_types::ExtraHoursTO; -use serde::Deserialize; use service::extra_hours::ExtraHoursService; -use uuid::Uuid; use crate::{error_handler, Context, RestStateDef}; pub fn generate_route() -> Router { - Router::new() - .route("/", post(create_extra_hours::)) - .route("/:id", delete(delete_extra_hours::)) - .route( - "/by-sales-person/:id", - get(get_extra_hours_for_sales_person::), - ) -} - -#[derive(Clone, Debug, Deserialize)] -pub struct ExtraHoursForSalesPersonAttributes { - year: u32, - until_week: u8, -} - -pub async fn get_extra_hours_for_sales_person( - rest_state: State, - Extension(context): Extension, - query: Query, - Path(sales_person_id): Path, -) -> Response { - error_handler( - (async { - let extra_hours: Rc<[ExtraHoursTO]> = rest_state - .extra_hours_service() - .find_by_sales_person_id_and_year( - sales_person_id, - query.year, - query.until_week, - context.into(), - ) - .await? - .iter() - .map(ExtraHoursTO::from) - .collect(); - Ok(Response::builder() - .status(201) - .body(Body::new(serde_json::to_string(&extra_hours).unwrap())) - .unwrap()) - }) - .await, - ) + Router::new().route("/", post(create_extra_hours::)) } pub async fn create_extra_hours( @@ -74,27 +25,10 @@ pub async fn create_extra_hours( .await?, ); Ok(Response::builder() - .status(201) + .status(200) .body(Body::new(serde_json::to_string(&extra_hours).unwrap())) .unwrap()) }) .await, ) } - -pub async fn delete_extra_hours( - rest_state: State, - Extension(context): Extension, - Path(extra_hours_id): Path, -) -> Response { - error_handler( - (async { - rest_state - .extra_hours_service() - .delete(extra_hours_id, context.into()) - .await?; - Ok(Response::builder().status(204).body(Body::empty()).unwrap()) - }) - .await, - ) -} diff --git a/service/src/extra_hours.rs b/service/src/extra_hours.rs index a419703..9ab6484 100644 --- a/service/src/extra_hours.rs +++ b/service/src/extra_hours.rs @@ -107,5 +107,5 @@ pub trait ExtraHoursService { &self, id: Uuid, context: Authentication, - ) -> Result<(), ServiceError>; + ) -> Result; } diff --git a/service_impl/src/extra_hours.rs b/service_impl/src/extra_hours.rs index 1ab8b0d..562dab6 100644 --- a/service_impl/src/extra_hours.rs +++ b/service_impl/src/extra_hours.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use dao::extra_hours; use service::{ extra_hours::ExtraHours, - permission::{Authentication, HR_PRIVILEGE, SALES_PRIVILEGE}, + permission::{Authentication, HR_PRIVILEGE}, ServiceError, }; use tokio::join; @@ -78,29 +78,12 @@ impl< async fn find_by_sales_person_id_and_year( &self, - sales_person_id: Uuid, - year: u32, - until_week: u8, - context: Authentication, + _sales_person_id: Uuid, + _year: u32, + _until_week: u8, + _context: Authentication, ) -> Result, ServiceError> { - let (hr_permission, sales_person_permission) = join!( - self.permission_service - .check_permission(HR_PRIVILEGE, context.clone()), - self.sales_person_service - .verify_user_is_sales_person(sales_person_id, context), - ); - hr_permission.or(sales_person_permission)?; - - let extra_hours_entities = self - .extra_hours_dao - .find_by_sales_person_id_and_year(sales_person_id, year) - .await?; - let extra_hours = extra_hours_entities - .iter() - .filter(|extra_hours| extra_hours.date_time.iso_week() <= until_week) - .map(ExtraHours::from) - .collect::>(); - Ok(extra_hours.into()) + unimplemented!() } async fn create( @@ -144,40 +127,11 @@ impl< ) -> Result { unimplemented!() } - async fn delete( &self, - extra_hours_id: Uuid, - context: Authentication, - ) -> Result<(), ServiceError> { - let (hr_permission, sales_person_permission) = join!( - self.permission_service - .check_permission(HR_PRIVILEGE, context.clone()), - self.permission_service - .check_permission(SALES_PRIVILEGE, context.clone()), - ); - hr_permission.or(sales_person_permission)?; - - let mut extra_hours_entity = self - .extra_hours_dao - .find_by_id(extra_hours_id) - .await? - .ok_or(ServiceError::EntityNotFound(extra_hours_id))?; - - let (hr_permission, user_permission) = join!( - self.permission_service - .check_permission(HR_PRIVILEGE, context.clone()), - self.sales_person_service - .verify_user_is_sales_person(extra_hours_entity.sales_person_id, context), - ); - hr_permission.or(user_permission)?; - - extra_hours_entity.deleted = Some(self.clock_service.date_time_now()); - - self.extra_hours_dao - .update(&extra_hours_entity, "extra_hours_service::delete") - .await?; - - Ok(()) + _id: Uuid, + _context: Authentication, + ) -> Result { + unimplemented!() } } diff --git a/service_impl/src/reporting.rs b/service_impl/src/reporting.rs index 6c4a065..14dd26c 100644 --- a/service_impl/src/reporting.rs +++ b/service_impl/src/reporting.rs @@ -178,10 +178,9 @@ where .sum(); let extra_hours = self .extra_hours_dao - .find_by_sales_person_id_and_year(paid_employee.id, year) + .find_by_sales_person_id_and_year(paid_employee.id, year, until_week) .await? .iter() - .filter(|eh| eh.date_time.iso_week() <= until_week) .map(|eh| eh.amount) .sum::(); let balance_hours = shiftplan_hours + extra_hours - planned_hours; @@ -222,7 +221,7 @@ where .await?; let extra_hours = self .extra_hours_dao - .find_by_sales_person_id_and_year(*sales_person_id, year) + .find_by_sales_person_id_and_year(*sales_person_id, year, until_week) .await?; let planned_hours: f32 = (1..=until_week) @@ -233,11 +232,7 @@ where }) .sum(); let shiftplan_hours = shiftplan_report.iter().map(|r| r.hours).sum::() as f32; - let overall_extra_hours = extra_hours - .iter() - .filter(|eh| eh.date_time.iso_week() <= until_week) - .map(|eh| eh.amount) - .sum::(); + let overall_extra_hours = extra_hours.iter().map(|eh| eh.amount).sum::(); let employee_report = EmployeeReport { sales_person: Arc::new(sales_person),