Add endpoint to add extra_hours
This commit is contained in:
parent
d4adcb182f
commit
c8f28e1f7b
11 changed files with 335 additions and 38 deletions
34
rest/src/extra_hours.rs
Normal file
34
rest/src/extra_hours.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use axum::{
|
||||
body::Body, extract::State, response::Response, routing::post, Extension, Json, Router,
|
||||
};
|
||||
use rest_types::ExtraHoursTO;
|
||||
|
||||
use service::extra_hours::ExtraHoursService;
|
||||
|
||||
use crate::{error_handler, Context, RestStateDef};
|
||||
|
||||
pub fn generate_route<RestState: RestStateDef>() -> Router<RestState> {
|
||||
Router::new().route("/", post(create_extra_hours::<RestState>))
|
||||
}
|
||||
|
||||
pub async fn create_extra_hours<RestState: RestStateDef>(
|
||||
rest_state: State<RestState>,
|
||||
Extension(context): Extension<Context>,
|
||||
Json(sales_person): Json<ExtraHoursTO>,
|
||||
) -> Response {
|
||||
error_handler(
|
||||
(async {
|
||||
let extra_hours = ExtraHoursTO::from(
|
||||
&rest_state
|
||||
.extra_hours_service()
|
||||
.create(&(&sales_person).into(), context.into())
|
||||
.await?,
|
||||
);
|
||||
Ok(Response::builder()
|
||||
.status(200)
|
||||
.body(Body::new(serde_json::to_string(&extra_hours).unwrap()))
|
||||
.unwrap())
|
||||
})
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
use std::{convert::Infallible, sync::Arc};
|
||||
|
||||
mod booking;
|
||||
mod extra_hours;
|
||||
mod permission;
|
||||
mod report;
|
||||
mod sales_person;
|
||||
|
|
@ -231,6 +232,10 @@ pub trait RestStateDef: Clone + Send + Sync + 'static {
|
|||
+ Send
|
||||
+ Sync
|
||||
+ 'static;
|
||||
type ExtraHoursService: service::extra_hours::ExtraHoursService<Context = Context>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static;
|
||||
|
||||
fn user_service(&self) -> Arc<Self::UserService>;
|
||||
fn permission_service(&self) -> Arc<Self::PermissionService>;
|
||||
|
|
@ -239,6 +244,7 @@ pub trait RestStateDef: Clone + Send + Sync + 'static {
|
|||
fn booking_service(&self) -> Arc<Self::BookingService>;
|
||||
fn reporting_service(&self) -> Arc<Self::ReportingService>;
|
||||
fn working_hours_service(&self) -> Arc<Self::WorkingHoursService>;
|
||||
fn extra_hours_service(&self) -> Arc<Self::ExtraHoursService>;
|
||||
}
|
||||
|
||||
pub struct OidcConfig {
|
||||
|
|
@ -344,6 +350,7 @@ pub async fn start_server<RestState: RestStateDef>(rest_state: RestState) {
|
|||
.nest("/booking", booking::generate_route())
|
||||
.nest("/report", report::generate_route())
|
||||
.nest("/working-hours", working_hours::generate_route())
|
||||
.nest("/extra-hours", extra_hours::generate_route())
|
||||
.with_state(rest_state)
|
||||
.layer(middleware::from_fn(context_extractor));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue