aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-23 15:03:13 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-23 15:03:13 +0200
commit0a2d6fc06fc1988f860ab81fe53d1e6dae470407 (patch)
tree031cca26771c25a06c291a3c12551b8517451b72
parent129e8d34906584b5e6c3eeeb18958fc5e2c39c33 (diff)
downloadramaskrik-social-0a2d6fc06fc1988f860ab81fe53d1e6dae470407.tar.gz
ramaskrik-social-0a2d6fc06fc1988f860ab81fe53d1e6dae470407.tar.bz2
ramaskrik-social-0a2d6fc06fc1988f860ab81fe53d1e6dae470407.zip
Implement deleting screenings from web ui.
-rw-r--r--src/controllers/screening.rs13
-rw-r--r--src/db.rs6
-rw-r--r--src/lib.rs1
-rw-r--r--templates/screening/list.tera18
4 files changed, 34 insertions, 4 deletions
diff --git a/src/controllers/screening.rs b/src/controllers/screening.rs
index b76ae65..9e78130 100644
--- a/src/controllers/screening.rs
+++ b/src/controllers/screening.rs
@@ -22,7 +22,7 @@ use crate::{
};
use std::result::Result;
-use rocket::{get, post};
+use rocket::{delete, get, post};
use rocket::request::{Form, FromForm};
use rocket::response::Redirect;
use rocket_contrib::{
@@ -82,3 +82,14 @@ pub fn create_screening(db: db::Connection, screening: Form<NewScreeningForm>) -
db.create_screening(dbg!(screening.room_id), dbg!(screening.film_id), date, start_time, end_time)?;
Ok(Redirect::to("/screenings"))
}
+
+#[derive(FromForm)]
+pub struct DeleteScreeningForm {
+ screening_id: i32,
+}
+
+#[delete("/", format = "application/x-www-form-urlencoded", data = "<screening>")]
+pub fn delete(db: db::Connection, screening: Form<DeleteScreeningForm>) -> Result<Redirect, Box<dyn Error>> {
+ db.delete_screening(screening.screening_id)?;
+ Ok(Redirect::to("/screenings"))
+}
diff --git a/src/db.rs b/src/db.rs
index cf1c0fb..4297d25 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -71,6 +71,12 @@ impl Connection {
Ok(models::AggregatedScreening::from_query(s))
}
+ pub fn delete_screening(&self, screening_id: i32) -> QueryResult<usize> {
+ use crate::schema::screenings::dsl::*;
+ diesel::delete(screenings.filter(id.eq(screening_id)))
+ .execute(&**self)
+ }
+
pub fn create_room(&self, room_name: &String) -> QueryResult<usize> {
use crate::schema::rooms::dsl::*;
diesel::insert_into(rooms)
diff --git a/src/lib.rs b/src/lib.rs
index 4972205..0f9d7b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -51,5 +51,6 @@ pub fn build_rocket(db_url: &str) -> Result<rocket::Rocket, Box<dyn Error>> {
screening::list_screenings,
screening::new_screening,
screening::create_screening,
+ screening::delete,
]))
}
diff --git a/templates/screening/list.tera b/templates/screening/list.tera
index 7c92303..263d3ea 100644
--- a/templates/screening/list.tera
+++ b/templates/screening/list.tera
@@ -12,11 +12,23 @@
{% if screenings | length <= 0%}
No screenings defined.
{% else %}
-<ul>
+<table>
{% for s in screenings -%}
-<li>{{ s.date }} {{ s.start_time }} - {{ s.end_time }}: {{ s.film.title }} ({{ s.room.name }})</li>
+ <tr>
+ <td>{{ s.date }}</td>
+ <td>{{ s.start_time }} - {{ s.end_time }}:</td>
+ <td>{{ s.film.title }}</td>
+ <td>({{ s.room.name }})</td>
+ <td>
+ <form class="delete-item" id="delete-screening-{{ s.id }}" action="/screenings" method="POST">
+ <input name="_method" value="DELETE" type="hidden">
+ <input name="screening_id" value="{{ s.id }}" type="hidden">
+ <input type="submit" value="X">
+ </form>
+ </td>
+ </tr>
{% endfor -%}
-</ul>
+</table>
{% endif %}
</body>
</html>