Feature: remove appointments, insert created appointment in list
This commit is contained in:
parent
2736772e42
commit
afeaa4159f
|
@ -2,7 +2,7 @@ $( document ).ready(function() {
|
|||
Scheduler.refresh_appointment_types();
|
||||
$(".scheduler_add_appointment_button").on("click", function(){
|
||||
Scheduler.add_appointment(this);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Scheduler = ( function() {
|
||||
|
@ -44,7 +44,33 @@ Scheduler = ( function() {
|
|||
},
|
||||
success: function (data) {
|
||||
if(is_ok(data)) {
|
||||
alert("OK!");
|
||||
let type = resolve_appointment_type(data.type_id);
|
||||
|
||||
$(".scheduler-tbody").append("<tr><td>"+type.name+"</td><td>"+data.appointment_date+"</td><td><button class='iconbutton scheduler_remove_appointment_button' data-appointment-id=\""+data.id+"\"><svg width=\"1.5em\" height=\"1.5em\" fill=\"currentColor\">\n" +
|
||||
"<use xlink:href=\"/img/bootstrap-icons.svg#trash\"/>\n" +
|
||||
"</svg></button></td></tr>");
|
||||
$(".scheduler_remove_appointment_button").unbind().on("click", function(){
|
||||
Scheduler.remove_appointment(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
var remove_appointment = function(button){
|
||||
var ap_id = $(button).data("appointment-id");
|
||||
console.log(ap_id);
|
||||
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/api/appointments/"+ap_id,
|
||||
contentType: 'application/json',
|
||||
timeout: 3000,
|
||||
error: function () {
|
||||
alert("Verbindung zum Server unterbrochen!");
|
||||
},
|
||||
success: function (data) {
|
||||
if(is_ok(data)) {
|
||||
$(button).parent().parent().remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -63,10 +89,14 @@ Scheduler = ( function() {
|
|||
success: function (data) {
|
||||
if(is_ok(data)) {
|
||||
$(data).each(function(){
|
||||
console.log(this);
|
||||
type = resolve_appointment_type(this.type_id);
|
||||
$(".scheduler-tbody").append("<tr><td>"+type.name+"</td><td>"+this.appointment_date+"</td></tr>");
|
||||
})
|
||||
let type = resolve_appointment_type(this.type_id);
|
||||
$(".scheduler-tbody").append("<tr><td>"+type.name+"</td><td>"+this.appointment_date+"</td><td><button class='iconbutton scheduler_remove_appointment_button' data-appointment-id=\""+this.id+"\"><svg width=\"1.5em\" height=\"1.5em\" fill=\"currentColor\">\n" +
|
||||
"<use xlink:href=\"/img/bootstrap-icons.svg#trash\"/>\n" +
|
||||
"</svg></button></td></tr>");
|
||||
});
|
||||
$(".scheduler_remove_appointment_button").unbind().on("click", function(){
|
||||
Scheduler.remove_appointment(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -88,5 +118,6 @@ Scheduler = ( function() {
|
|||
refresh_appointment_types: refresh_appointment_types,
|
||||
add_appointment: add_appointment,
|
||||
list_appointments: list_appointments,
|
||||
remove_appointment: remove_appointment,
|
||||
}
|
||||
})();
|
|
@ -1 +1 @@
|
|||
v0.1-22-g081fd73
|
||||
v0.1-23-g2736772
|
||||
|
|
|
@ -5,6 +5,8 @@ use crate::database::controller::connector::establish_connection;
|
|||
use diesel::{RunQueryDsl, ExpressionMethods};
|
||||
use chrono::NaiveDate;
|
||||
use diesel::query_dsl::filter_dsl::FilterDsl;
|
||||
use diesel::result::Error;
|
||||
use diesel::query_dsl::limit_dsl::LimitDsl;
|
||||
|
||||
pub fn get_appointment_types(settings: &State<Settings>) -> Result<Vec<AppointmentType>, diesel::result::Error>{
|
||||
use crate::schema::appointment_types::dsl::*;
|
||||
|
@ -34,6 +36,20 @@ pub fn add_appointment(settings: &State<Settings>, type_id2: uuid::Uuid, entity_
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_appointment(settings: &State<Settings>, ap_entity_id: uuid::Uuid) -> Result<(), diesel::result::Error>{
|
||||
use crate::schema::appointments::dsl::*;
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
|
||||
match diesel::delete(appointments.filter(id.eq(ap_entity_id))).execute(&connection){
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => {
|
||||
error!("Coudn't remove appointment: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_appointment_for_entity(settings: &State<Settings>, entity_id2: uuid::Uuid) -> Result<Vec<Appointment>, diesel::result::Error>{
|
||||
use crate::schema::appointments::dsl::*;
|
||||
|
||||
|
@ -46,4 +62,18 @@ pub fn get_appointment_for_entity(settings: &State<Settings>, entity_id2: uuid::
|
|||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_appointment_with_id(settings: &State<Settings>, ap_id: uuid::Uuid) -> Result<Appointment, diesel::result::Error>{
|
||||
use crate::schema::appointments::dsl::*;
|
||||
|
||||
let connection = establish_connection(settings);
|
||||
|
||||
match appointments.filter(id.eq(ap_id)).get_result(&connection){
|
||||
Ok(appointment) => Ok(appointment),
|
||||
Err(e) => {
|
||||
error!("Couldn't get appointment: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@ use chrono::NaiveDate;
|
|||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize)]
|
||||
pub struct Appointment{
|
||||
id : uuid::Uuid,
|
||||
type_id: uuid::Uuid,
|
||||
entity_id: uuid::Uuid,
|
||||
appointment_date: NaiveDate,
|
||||
pub id : uuid::Uuid,
|
||||
pub type_id: uuid::Uuid,
|
||||
pub entity_id: uuid::Uuid,
|
||||
pub appointment_date: NaiveDate,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Clone, Deserialize, Serialize)]
|
||||
|
|
|
@ -157,6 +157,7 @@ fn main() {
|
|||
modules::api::appointments::read::read_appointment_types,
|
||||
modules::api::appointments::create::create_appointment,
|
||||
modules::api::appointments::read::read_appointments_for_entity,
|
||||
modules::api::appointments::delete::delete_appointment,
|
||||
modules::api::info::caller::check_caller_has_permission,
|
||||
],
|
||||
)
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
use rocket::State;
|
||||
use crate::helper::settings::Settings;
|
||||
use crate::helper::session_cookies::model::SessionCookie;
|
||||
use rocket_contrib::json::Json;
|
||||
use crate::modules::api::appointments::create::CreateAppointmentData;
|
||||
use crate::database::model::appointments::Appointment;
|
||||
use crate::modules::api::model::api_outcome::{ApiErrorWrapper, ApiError};
|
||||
use crate::modules::api::member_management::controller::parser::{parse_member_cookie, parse_uuid};
|
||||
use crate::database::controller::members::check_access_to_resource;
|
||||
use crate::helper::translate_diesel_error::translate_diesel;
|
||||
use crate::database::controller::appointments::{remove_appointment, get_appointment_for_entity, get_appointment_with_id};
|
||||
|
||||
/// Removes appointment
|
||||
///
|
||||
/// # Api Call
|
||||
/// * DELETE
|
||||
/// * /api/appointments/<appointment_id>
|
||||
///
|
||||
/// # Api Result
|
||||
/// * Api returns nothing or ApiError in ApiErrorWrapper
|
||||
///
|
||||
/// # Permission required
|
||||
/// * modules.scheduler.appointments.edit on specified entity
|
||||
#[delete("/api/appointments/<appointment_id>", format = "json")]
|
||||
pub fn delete_appointment(
|
||||
settings: State<Settings>,
|
||||
cookie: SessionCookie,
|
||||
appointment_id: String,
|
||||
) -> Result<(), Json<ApiErrorWrapper>> {
|
||||
let caller = parse_member_cookie(cookie.member)?;
|
||||
let ap_id : uuid::Uuid = parse_uuid(appointment_id)?;
|
||||
|
||||
let ap = match get_appointment_with_id(&settings, ap_id){
|
||||
Ok(ap) => ap,
|
||||
Err(e) => return Err(translate_diesel(e))
|
||||
};
|
||||
|
||||
if !check_access_to_resource(&settings, caller.entity_id, ap.entity_id, crate::permissions::modules::scheduler::appointments::EDIT){
|
||||
return Err(Json(
|
||||
ApiError::new(403, "Keine Berechtigung, Termine zu löschen!".to_string()).to_wrapper(),
|
||||
));
|
||||
}
|
||||
|
||||
match remove_appointment(&settings, ap_id){
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(translate_diesel(e))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue