1 module vibelog.config;
2 
3 import vibe.data.bson;
4 
5 class Config {
6 	BsonObjectID id;
7 	string name;
8 	string[] categories;
9 	string language = "en-us";
10 	string copyrightString;
11 	string feedTitle;
12 	string feedLink;
13 	string feedDescription;
14 	string feedImageTitle;
15 	string feedImageUrl;
16 
17 	this()
18 	{
19 		id  = BsonObjectID.generate();
20 	}
21 
22 	@property string[] groups() const { return ["admin"]; }
23 
24 	bool hasCategory(string cat) const {
25 		foreach( c; categories )
26 			if( c == cat )
27 				return true;
28 		return false;
29 	}
30 
31 	static Config fromBson(Bson bson)
32 	{
33 		auto ret = new Config;
34 		ret.id = bson["_id"].opt!BsonObjectID();
35 		ret.name = bson["name"].opt!string();
36 		foreach( grp; cast(Bson[])bson["categories"] )
37 			ret.categories ~= grp.opt!string();
38 		ret.language = bson["language"].opt!string("en-us");
39 		ret.copyrightString = bson["copyrightString"].opt!string();
40 		ret.feedTitle = bson["feedTitle"].opt!string();
41 		ret.feedLink = bson["feedLink"].opt!string();
42 		ret.feedDescription = bson["feedDescription"].opt!string();
43 		ret.feedImageTitle = bson["feedImageTitle"].opt!string();
44 		ret.feedImageUrl = bson["feedImageUrl"].opt!string();
45 		return ret;
46 	}
47 	
48 	Bson toBson()
49 	const {
50 		Bson[] bcategories;
51 		foreach( grp; categories )
52 			bcategories ~= Bson(grp);
53 
54 		Bson[string] ret;
55 		ret["_id"] = Bson(id);
56 		ret["name"] = Bson(name);
57 		ret["categories"] = Bson(bcategories);
58 		ret["language"] = Bson(language);
59 		ret["copyrightString"] = Bson(copyrightString);
60 		ret["feedTitle"] = Bson(feedTitle);
61 		ret["feedLink"] = Bson(feedLink);
62 		ret["feedDescription"] = Bson(feedDescription);
63 		ret["feedImageTitle"] = Bson(feedImageTitle);
64 		ret["feedImageUrl"] = Bson(feedImageUrl);
65 
66 		return Bson(ret);
67 	}
68 }