-
Notifications
You must be signed in to change notification settings - Fork 0
/
PastEvent.cpp
59 lines (51 loc) · 1.51 KB
/
PastEvent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "PastEvent.h"
#include <stdlib.h>
#include <time.h>
using namespace std;
extern map<string, Artist> artistMap;
extern map<string, Venue> venueMap;
PastEvent::PastEvent(std::string id, Artist artist, Venue location, std::string date, std::string time) : Event(id, artist, location, date, time){
}
PastEvent::PastEvent(crow::json::rvalue readValueJson)
{
updateFromJson(readValueJson);
}
std::string PastEvent::getReview()
{
return reviews.at(rand()%reviews.size());
}
std::string PastEvent::addReview(string review)
{
reviews.push_back(review);
return reviews.back();
}
crow::json::wvalue PastEvent::convertToJson()
{
crow::json::wvalue writeValueJson;
writeValueJson["id"] = id;
writeValueJson["artist"]["name"] = artist.getName();
writeValueJson["venue"]["city"]= location.getCity();
writeValueJson["date"] = date;
writeValueJson["time"] = time;
int index = 0;
for(string review : reviews)
{
writeValueJson["reviews"][index] = review;
index++;
}
return writeValueJson;
return writeValueJson;
}
void PastEvent::updateFromJson(crow::json::rvalue readValueJson)
{
setId(readValueJson["id"].s());
setArtist(artistMap.at(readValueJson["artist"]["name"].s()));
setWhere(venueMap.at(readValueJson["venue"]["city"].s()));
setWhen(readValueJson["date"].s(), readValueJson["time"].s());
reviews.clear();
for(crow::json::rvalue review : readValueJson["reviews"])
{
reviews.push_back(review.s());
}
return;
}