use actix_web::{web, HttpResponse, Responder};
use askama_actix::TemplateToResponse;

use crate::{endpoints::area::NewOrEditAreaTemplate, models::{Role, User}};

#[actix_web::get("/area/new")]
async fn get(user: web::ReqData<User>) -> impl Responder {
    if user.role != Role::Admin {
        return HttpResponse::Unauthorized().finish();
    }

    let template = NewOrEditAreaTemplate {
        user: user.into_inner(),
        area: None
    };

    template.to_response()
}
