42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use actix_identity::Identity;
|
|
use actix_web::{http::header::LOCATION, web, HttpResponse, Responder};
|
|
use askama::Template;
|
|
use askama_actix::TemplateToResponse;
|
|
use chrono::NaiveDate;
|
|
use serde::Deserialize;
|
|
use sqlx::PgPool;
|
|
|
|
use crate::models::{role::Role, user::User};
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "availabillity_new.html")]
|
|
struct AvailabillityNewTemplate {
|
|
user_role: Role,
|
|
date: NaiveDate
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct AvailabillityNewQuery {
|
|
date: NaiveDate,
|
|
}
|
|
|
|
#[actix_web::get("/availabillity/new")]
|
|
pub async fn get_availabillity_new(
|
|
user: Option<Identity>,
|
|
pool: web::Data<PgPool>,
|
|
query: web::Query<AvailabillityNewQuery>,
|
|
) -> impl Responder {
|
|
|
|
if let Some(user) = user {
|
|
let current_user = User::read_by_id(pool.as_ref(), user.id().unwrap().parse().unwrap()).await.unwrap();
|
|
|
|
let template = AvailabillityNewTemplate { user_role: current_user.role, date: query.date };
|
|
|
|
template.to_response()
|
|
} else {
|
|
HttpResponse::PermanentRedirect()
|
|
.insert_header((LOCATION, "/login"))
|
|
.finish()
|
|
}
|
|
}
|