diff --git a/source/calendarwebapp.d b/source/calendarwebapp.d index 54ccc72..bcd1dfa 100644 --- a/source/calendarwebapp.d +++ b/source/calendarwebapp.d @@ -12,6 +12,7 @@ import std.datetime.date : Date; import std.exception : enforce; import std.typecons : Nullable; +import vibe.data.bson : BsonObjectID; import vibe.http.common : HTTPStatusException; import vibe.http.server : HTTPServerRequest, HTTPServerResponse; import vibe.http.status : HTTPStatus; @@ -66,7 +67,6 @@ public: Nullable!Date end, string description, string name, EventType type, bool shout) { import std.array : replace, split; - import vibe.data.bson : BsonObjectID; if (!end.isNull) enforce(end - begin >= 1.days, @@ -79,6 +79,12 @@ public: redirect("/"); } + @anyAuth void postRemove(BsonObjectID id) + { + eventStore.removeEvent(id); + redirect("/"); + } + private: struct ValidationErrorData { diff --git a/source/event.d b/source/event.d index 9e39e90..22dfe11 100644 --- a/source/event.d +++ b/source/event.d @@ -16,16 +16,17 @@ import vibe.db.mongo.collection : MongoCollection; interface EventStore { - Event getEvent(string id); + Event getEvent(BsonObjectID id); InputRange!Event getAllEvents(); void addEvent(Event); InputRange!Event getEventsBeginningBetween(Date begin, Date end); + void removeEvent(BsonObjectID id); } class MongoDBEventStore : EventStore { public: - Event getEvent(string id) + Event getEvent(BsonObjectID id) { return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName) .findOne(["_id" : id]).deserializeBson!Event; @@ -54,6 +55,11 @@ public: .inputRangeObject; } + void removeEvent(BsonObjectID id) + { + mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName).remove(["_id" : id]); + } + private: @Autowire MongoClient mongoClient; diff --git a/views/showevents.dt b/views/showevents.dt index bca670a..e3a7877 100644 --- a/views/showevents.dt +++ b/views/showevents.dt @@ -24,4 +24,7 @@ block content tr td shout td #{event.shout} + form(action="/remove", method="post") + input#id(value="#{event.id}", name="id", type="hidden") + input#submitButton(type="submit", value="Entfernen") hr