-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquoteResource.h
142 lines (106 loc) · 4.25 KB
/
quoteResource.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef _QUOTE_RESOURCE_H_
#define _QUOTE_RESOURCE_H_
#include "util/error.h"
#include "util/tokenExtractor.h"
#include "util/bodyExtractor.h"
#include "util/responseGenerator.h"
#include "util/urlAnalyzer.h"
#include "dbo/dbo.h"
#include "dbo/kalematieSession.h"
#include "Author.h"
#include "Quote.h"
#include "Rating.h"
#include "Fave.h"
#include "Token.h"
#include <regex>
#include <ctime>
#include <chrono>
#include <map>
#include <Wt/Dbo/SqlConnectionPool>
#include <Wt/WLocalDateTime>
#include <Wt/Utils>
#include <Wt/Dbo/weak_ptr>
#include <Wt/Mail/Client>
#include <Wt/Mail/Message>
#include <Wt/Http/Client>
typedef Wt::Json::Object WJO;
typedef Wt::Json::Value WJV;
class quoteResource {
public:
quoteResource(Wt::Dbo::SqlConnectionPool& connectionPool,
const Wt::Http::Request& request,
Wt::Http::Response& response);
bool authenticate();
/* the following function compare the request.pathInfo()
* with to regexes to determine what response generating
* functions to call and actually call them
*/
void initiateGet();
void initiatePost();
void initiatePut();
void initiateDelete();
/* functions that take care of generating
* the response based on the clients request
*/
// the GET group
void _getQuoteRating_(); // implemented
void _getQuoteFaves_(); // implemented
void _getQuote_(); // implemented
void _getQuoteCollection_(); // implemented
void _getAuthor_(); // implemented TODO : test it
void _getAuthorCollection_();
// the POST group
void _getAccessToken_(); // implemented
void _invalidateAccessToken_(); // implemented
void _createQuote_(); // implemented
void _postRating_(); // implemented
void _postFave_(); // implemeted
void _addAuthor_(); // planned
// the PUT group
void _modifyQuote_(); // implemented
void _modifyAuthor_();
// the DELETE group
void _deleteQuote_(); // implemented
void _deleteAuthor_(); // planned
// test
void handle(boost::system::error_code err,
const Wt::Http::Message& res);
private:
const Wt::Http::Request& _request;
Wt::Http::Response& _response;
// User Role and id
author::role _role;
int _authorId;
// the connection pool
Wt::Dbo::SqlConnectionPool& _connectionPool;
// These regex objects are used to determine
// what member function to call
static std::regex __getAccessToken;
static std::regex __invalidateAccessToken;
static std::regex __createQuote;
// The function call corresponding to this regex match
// will be different based on the request method
// if get -> rating is retrieved
// if post -> a quote gets rated
static std::regex __getOrPostQuoteRating;
static std::regex __getOrPostQuoteFaves;
// The function call corresponding to this regex match
// will be different based on the request method
// if get -> a quote is retrieved
// if put -> a quote is updated
// if delete -> a quote is deleted
static std::regex __getOrPutOrDeleteQuote;
// This function call is used to search quotes as well
static std::regex __getQuoteCollection;
static std::regex __addAuthor;
// The function call corresponding to this regex match
// will be different based on the request method
// if get -> the author's info will be retrieved
// if put -> the autho's information will be updated
// if delete -> the author will be deleted
static std::regex __getOrPutOrDeleteAuthor;
static std::regex __getAuthorCollection;
// token search regex
static std::regex __tokenSearchReg;
};
#endif