2017-08-06 22:46:42 +02:00
|
|
|
module event;
|
|
|
|
|
|
|
|
import std.datetime.date;
|
|
|
|
import std.typecons : Nullable;
|
|
|
|
|
2017-08-07 01:09:45 +02:00
|
|
|
import vibe.core.file: existsFile, readFileUTF8, writeFileUTF8;
|
2017-08-07 01:33:17 +02:00
|
|
|
import vibe.core.path : Path;
|
2017-08-07 01:09:45 +02:00
|
|
|
import vibe.data.json : deserializeJson, parseJsonString, serializeToPrettyJson;
|
2017-08-07 01:33:17 +02:00
|
|
|
import vibe.data.serialization : serializationName = name;
|
2017-08-06 22:46:42 +02:00
|
|
|
|
|
|
|
enum EventType
|
|
|
|
{
|
|
|
|
Holiday,
|
|
|
|
Birthday,
|
|
|
|
FSI_Event,
|
|
|
|
General_University_Event,
|
|
|
|
Any
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
2017-08-07 01:33:17 +02:00
|
|
|
@serializationName("date") Date begin;
|
|
|
|
@serializationName("end_date") Nullable!Date end;
|
2017-08-06 22:46:42 +02:00
|
|
|
Event event;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Event
|
|
|
|
{
|
2017-08-07 01:33:17 +02:00
|
|
|
@serializationName("eid") string id;
|
2017-08-06 22:46:42 +02:00
|
|
|
string name;
|
2017-08-07 01:33:17 +02:00
|
|
|
@serializationName("desc") string[] description;
|
|
|
|
@serializationName("etype") EventType type;
|
2017-08-06 22:46:42 +02:00
|
|
|
bool shout;
|
|
|
|
}
|
2017-08-07 01:09:45 +02:00
|
|
|
|
|
|
|
Entry[] getEntriesFromFile(in Path fileName)
|
|
|
|
{
|
|
|
|
Entry[] entries;
|
|
|
|
if (fileName.existsFile)
|
|
|
|
{
|
|
|
|
deserializeJson(entries, fileName.readFileUTF8.parseJsonString);
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeEntriesToFile(in Entry[] entries, in Path fileName)
|
|
|
|
{
|
|
|
|
fileName.writeFileUTF8(entries.serializeToPrettyJson);
|
|
|
|
}
|