Add basic employee hour balance report

This commit is contained in:
Simon Goller 2024-06-23 18:12:54 +02:00
parent 0eb885216a
commit d4adcb182f
31 changed files with 2155 additions and 5 deletions

34
rest/src/working_hours.rs Normal file
View file

@ -0,0 +1,34 @@
use axum::{
body::Body, extract::State, response::Response, routing::post, Extension, Json, Router,
};
use rest_types::WorkingHoursTO;
use service::working_hours::WorkingHoursService;
use crate::{error_handler, Context, RestStateDef};
pub fn generate_route<RestState: RestStateDef>() -> Router<RestState> {
Router::new().route("/", post(create_working_hours::<RestState>))
}
pub async fn create_working_hours<RestState: RestStateDef>(
rest_state: State<RestState>,
Extension(context): Extension<Context>,
Json(working_hours): Json<WorkingHoursTO>,
) -> Response {
error_handler(
(async {
let working_hours = WorkingHoursTO::from(
&rest_state
.working_hours_service()
.create(&(&working_hours).into(), context.into())
.await?,
);
Ok(Response::builder()
.status(200)
.body(Body::new(serde_json::to_string(&working_hours).unwrap()))
.unwrap())
})
.await,
)
}