-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.cpp
78 lines (69 loc) · 1.98 KB
/
session.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <time.h>
#include <boost/smart_ptr.hpp>
using namespace std;
using namespace boost;
#include "site.h"
#include "context.h"
#include "logger.h"
#include "response.h"
#include "session.h"
Session::Session(boost::shared_ptr<Site> s) {
site = s;
createdAt = time(NULL);
}
json Session::createInfo(const int32_t responseId, const string& query) {
boost::shared_ptr<Response> parent;
if (responseId) {
if (responses.size() >= responseId) {
parent = responses[responseId-1];
} else {
throw VaeDbInternalError("Invalid responseId");
}
} else {
parent = boost::shared_ptr<Response>();
}
boost::shared_ptr<Response> response(new Response(site, parent, query));
return response->getCreateInfo();
}
json Session::data(const int32_t responseId) {
boost::shared_ptr<Response> response;
if (responses.size() >= responseId) {
response = responses[responseId-1];
} else {
throw VaeDbInternalError("Invalid responseId");
}
return response->getData();
}
json Session::get(const int32_t responseId, const std::string& query, const std::map<std::string, std::string> & options) {
boost::shared_ptr<Response> parent;
if (responseId) {
if (responses.size() >= responseId) {
parent = responses[responseId-1];
} else {
throw VaeDbInternalError("Invalid responseId");
}
} else {
parent = boost::shared_ptr<Response>();
}
boost::shared_ptr<Response> response(new Response(site, parent, query, options));
json res = response->getJson();
res["id"] = responses.size()+1;
responses.push_back(response);
return res;
}
time_t Session::getCreatedAt() {
return createdAt;
}
boost::shared_ptr<Site> Session::getSite() {
return site;
}
json Session::structure(const int32_t responseId) {
boost::shared_ptr<Response> response;
if (responses.size() >= responseId) {
response = responses[responseId-1];
} else {
throw VaeDbInternalError("Invalid responseId");
}
return response->getStructure();
}