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.exception : enforce;
|
||||||
import std.typecons : Nullable;
|
import std.typecons : Nullable;
|
||||||
|
|
||||||
|
import vibe.data.bson : BsonObjectID;
|
||||||
import vibe.http.common : HTTPStatusException;
|
import vibe.http.common : HTTPStatusException;
|
||||||
import vibe.http.server : HTTPServerRequest, HTTPServerResponse;
|
import vibe.http.server : HTTPServerRequest, HTTPServerResponse;
|
||||||
import vibe.http.status : HTTPStatus;
|
import vibe.http.status : HTTPStatus;
|
||||||
|
@ -66,7 +67,6 @@ public:
|
||||||
Nullable!Date end, string description, string name, EventType type, bool shout)
|
Nullable!Date end, string description, string name, EventType type, bool shout)
|
||||||
{
|
{
|
||||||
import std.array : replace, split;
|
import std.array : replace, split;
|
||||||
import vibe.data.bson : BsonObjectID;
|
|
||||||
|
|
||||||
if (!end.isNull)
|
if (!end.isNull)
|
||||||
enforce(end - begin >= 1.days,
|
enforce(end - begin >= 1.days,
|
||||||
|
@ -79,6 +79,12 @@ public:
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@anyAuth void postRemove(BsonObjectID id)
|
||||||
|
{
|
||||||
|
eventStore.removeEvent(id);
|
||||||
|
redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ValidationErrorData
|
struct ValidationErrorData
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,16 +16,17 @@ import vibe.db.mongo.collection : MongoCollection;
|
||||||
|
|
||||||
interface EventStore
|
interface EventStore
|
||||||
{
|
{
|
||||||
Event getEvent(string id);
|
Event getEvent(BsonObjectID id);
|
||||||
InputRange!Event getAllEvents();
|
InputRange!Event getAllEvents();
|
||||||
void addEvent(Event);
|
void addEvent(Event);
|
||||||
InputRange!Event getEventsBeginningBetween(Date begin, Date end);
|
InputRange!Event getEventsBeginningBetween(Date begin, Date end);
|
||||||
|
void removeEvent(BsonObjectID id);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MongoDBEventStore : EventStore
|
class MongoDBEventStore : EventStore
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Event getEvent(string id)
|
Event getEvent(BsonObjectID id)
|
||||||
{
|
{
|
||||||
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
||||||
.findOne(["_id" : id]).deserializeBson!Event;
|
.findOne(["_id" : id]).deserializeBson!Event;
|
||||||
|
@ -54,6 +55,11 @@ public:
|
||||||
.inputRangeObject;
|
.inputRangeObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeEvent(BsonObjectID id)
|
||||||
|
{
|
||||||
|
mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName).remove(["_id" : id]);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@Autowire MongoClient mongoClient;
|
@Autowire MongoClient mongoClient;
|
||||||
|
|
||||||
|
|
|
@ -24,4 +24,7 @@ block content
|
||||||
tr
|
tr
|
||||||
td shout
|
td shout
|
||||||
td #{event.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
|
hr
|
||||||
|
|
Loading…
Reference in a new issue