Added functionality to delete events
This commit is contained in:
parent
54a1663330
commit
b97bfea099
3 changed files with 18 additions and 3 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue