calendar-webapp/source/event.d

50 lines
1 KiB
D
Raw Normal View History

module event;
import std.datetime.date;
import std.typecons : Nullable;
import vibe.core.file: existsFile, readFileUTF8, writeFileUTF8;
2017-08-07 01:33:17 +02:00
import vibe.core.path : Path;
import vibe.data.json : deserializeJson, parseJsonString, serializeToPrettyJson;
2017-08-07 01:33:17 +02:00
import vibe.data.serialization : serializationName = name;
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;
Event event;
}
struct Event
{
2017-08-07 01:33:17 +02:00
@serializationName("eid") string id;
string name;
2017-08-07 01:33:17 +02:00
@serializationName("desc") string[] description;
@serializationName("etype") EventType type;
bool shout;
}
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);
}