66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
use rocket::State;
|
|
use crate::helper::settings::Settings;
|
|
use crate::helper::session_cookies::model::SessionCookie;
|
|
use crate::database::model::appointments::{AppointmentType, Appointment};
|
|
use rocket::serde::json::Json;
|
|
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
|
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid_string};
|
|
use crate::database::controller::appointments::{get_appointment_types, get_appointment_for_entity};
|
|
use crate::helper::translate_diesel_error::translate_diesel;
|
|
use crate::database::controller::members::check_access_to_resource;
|
|
|
|
/// Get list of all appointment types
|
|
///
|
|
/// # Api Call
|
|
/// * GET
|
|
/// * /api/appointments/types
|
|
///
|
|
/// # Api Result
|
|
/// *
|
|
///
|
|
/// # Required permissions
|
|
/// * None
|
|
#[get("/api/appointments/types", format = "json")]
|
|
pub fn read_appointment_types(
|
|
settings: &State<Settings>,
|
|
cookie: SessionCookie,
|
|
) -> Result<Json<Vec<AppointmentType>>, Json<ApiErrorWrapper>> {
|
|
parse_member_cookie(cookie.member)?;
|
|
|
|
match get_appointment_types(settings){
|
|
Ok(at) => Ok(Json(at)),
|
|
Err(e) => Err(translate_diesel(e)),
|
|
}
|
|
}
|
|
|
|
/// Get list of all appointments for specified entity
|
|
///
|
|
/// # Api Call
|
|
/// * GET
|
|
/// * /api/appointments?entity_id=<entity id>
|
|
///
|
|
/// # Api Result
|
|
/// *
|
|
///
|
|
/// # Required permissions
|
|
/// * modules.scheduler.appointments.view
|
|
#[get("/api/appointments?<entity_id>", format = "json")]
|
|
pub fn read_appointments_for_entity(
|
|
settings: &State<Settings>,
|
|
cookie: SessionCookie,
|
|
entity_id: String,
|
|
) -> Result<Json<Vec<Appointment>>, Json<ApiErrorWrapper>> {
|
|
let caller = parse_member_cookie(cookie.member)?;
|
|
let entity_id = parse_uuid_string(entity_id)?;
|
|
|
|
if !check_access_to_resource(settings, caller.entity_id, entity_id, crate::permissions::modules::scheduler::appointments::VIEW){
|
|
return Err(Json(
|
|
ApiError::new(403, "Keine Berechtigung, Termine anzuzeigen!".to_string()).to_wrapper(),
|
|
));
|
|
}
|
|
|
|
match get_appointment_for_entity(settings, entity_id){
|
|
Ok(at) => Ok(Json(at)),
|
|
Err(e) => Err(translate_diesel(e)),
|
|
}
|
|
} |