Skip to content

Commit 7049968

Browse files
committed
Order History now returns valid JSON
1 parent 047fa8c commit 7049968

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

src/Database.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ int Database::ordersCallback(void *data, int argc, char **argv, char **keyCol)
8080
canceled = argv[3],
8181
key = argv[4];
8282

83-
//TODO: Use Order Object
84-
cout << "Order ID: " << orderID
85-
<< " Movie ID: " << movieID
86-
<< " Location ID:" << locationID
87-
<< " Canceled: " << canceled
88-
<< " User Key: " << key << endl;
83+
Order order(orderID,movieID,locationID,canceled=="1"?"true":"false",key);
8984

85+
cout << order.ToJson();
86+
if (++selectCounter != counter)
87+
cout << ",";
9088
return 0;
9189
};
9290

@@ -252,9 +250,9 @@ void Database::selectOrdersByKey(string key){
252250
string query = "SELECT * FROM ORDERS WHERE USERKEY = '" + key + "'";
253251
rc = sqlite3_exec(dbFile, query.c_str(), countCallback, (void *)data, &errMsg);
254252

255-
//cout << "{\"status\":\"success\",\"key\":";
253+
cout << "{\"status\":\"success\",\"orders\":[";
256254
rc = sqlite3_exec(dbFile, query.c_str(), ordersCallback, (void *)data, &errMsg);
257-
//cout << "}";
255+
cout << "]}";
258256

259257
if (rc != SQLITE_OK)
260258
sqlite3_free(errMsg);

src/Database.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdlib.h>
66
#include "Location.h"
77
#include "Movie.h"
8+
#include "Order.h"
89

910
using namespace std;
1011

src/Order.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "Order.h"
2+
3+
Order::Order(string _id, string _movieID, string _locationID, bool _canceled, string _userKey)
4+
: id(_id), movieID(_movieID), locationID(_locationID), canceled(_canceled), userKey(_userKey)
5+
{
6+
}
7+
8+
Order::~Order()
9+
{
10+
}
11+
12+
string Order::ToJson() const
13+
{
14+
string result = "{\n\t\t\"id\":\"" + id + "\",\n\t\t\"movieID\":\"" + movieID + "\",\n\t\t\"locationID\":\"" + locationID + "\",\n\t\t\"canceled\":\"";
15+
if (canceled)
16+
result += "true";
17+
else
18+
result += "false";
19+
20+
result += "\",\n\t\t\"userKey\":\"" + userKey + "\"\n\t}";
21+
return result;
22+
}

src/Order.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef ORDER_H
2+
#define ORDER_H
3+
4+
#include <string>
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
class Order {
10+
private:
11+
string id, movieID, locationID, userKey;
12+
bool canceled;
13+
public:
14+
Order(string,string,string,bool,string);
15+
~Order();
16+
string ToJson()const;
17+
};
18+
#endif

src/fcgi

4.66 KB
Binary file not shown.

0 commit comments

Comments
 (0)