aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kusatz <max@trialserver.de>2020-10-27 17:42:26 +0100
committerMax Kusatz <max@trialserver.de>2020-10-27 17:42:26 +0100
commit56ac806aae1a0fbc034faa92d5bca694b58a4863 (patch)
treecf1c9a824dfbd19c254563c5f42458acf4e0da97
parent0064d0dd4e1be77714d60c4548294abd73391137 (diff)
downloadn_core-56ac806aae1a0fbc034faa92d5bca694b58a4863.tar.gz
n_core-56ac806aae1a0fbc034faa92d5bca694b58a4863.zip
'fixed' mensa function not working
-rw-r--r--README.md10
-rw-r--r--src/GetEssen.cpp17
-rw-r--r--src/main.cpp2
3 files changed, 22 insertions, 7 deletions
diff --git a/README.md b/README.md
index 22f8a05..c132183 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,17 @@
# N Core - the backend of N
+## Building
+
Build upon [crow](https://github.com/ipkn/crow) [forked](https://git.niklashalle.net/crow) to fix a deprecation in boost 1.7+
+ git submodule init
+ git submodule update
+
+ mkdir build
+ cd build
+ cmake ..
+ make -j 6
+
## N protocol
### request
Each message sent to the N core server must be valid JSON and have a `command` field. It contains the command for N to handle, sanitized (i.e. no leading '/' or trailing username etc).
diff --git a/src/GetEssen.cpp b/src/GetEssen.cpp
index 44dae59..e0208f6 100644
--- a/src/GetEssen.cpp
+++ b/src/GetEssen.cpp
@@ -5,8 +5,7 @@
using std::string;
-bool
-Handler::MensaHandler::db_update_mensa_message(const int &mensaID, const ptime &mensaDatum, const std::vector<crow::json::wvalue> &message) {
+bool Handler::MensaHandler::db_update_mensa_message(const int &mensaID, const ptime &mensaDatum, const std::vector<crow::json::wvalue> &message) {
sqdb::Db db("../main.sqlite");
std::string messageFromJSON;
@@ -26,8 +25,7 @@ Handler::MensaHandler::db_update_mensa_message(const int &mensaID, const ptime &
return true;
}
-bool
-Handler::MensaHandler::db_insert_mensa_message(const int &mensaID, const ptime &mensaDatum, const string &message) {
+bool Handler::MensaHandler::db_insert_mensa_message(const int &mensaID, const ptime &mensaDatum, const string &message) {
sqdb::Db db("../main.sqlite");
string newTime = to_simple_string(ptime(boost::posix_time::second_clock::local_time()));
string mensaDatumString =
@@ -39,8 +37,7 @@ Handler::MensaHandler::db_insert_mensa_message(const int &mensaID, const ptime &
return true;
}
-Handler::MensaHandler::MensaEssen
-Handler::MensaHandler::db_get_mensa_message(const int &mensaID, const ptime &mensaDatum) {
+Handler::MensaHandler::MensaEssen Handler::MensaHandler::db_get_mensa_message(const int &mensaID, const ptime &mensaDatum) {
MensaEssen out;
sqdb::Db db("../main.sqlite");
@@ -80,22 +77,27 @@ Handler::MensaHandler::db_get_mensa_message(const int &mensaID, const ptime &men
std::vector<crow::json::wvalue> Handler::MensaHandler::getEssen(const int mensa_ID, const int offset) {
std::vector<crow::json::wvalue> reply_vec;
+ std::string reply;
+
if (offset >= 0) {
if (offset > 28) {
reply_vec.emplace_back(Response::create_text(
"Ich fühle mich geschmeichelt, dass du denkst, dass ich so weit in die Zukunft gucken kann (0 bis 28 Tage)"));
return reply_vec;
+ //return "Ich fühle mich geschmeichelt, dass du denkst, dass ich so weit in die Zukunft gucken kann (0 bis 28 Tage)";
}
ptime datumNow = boost::posix_time::second_clock::local_time();
ptime datumEssen = datumNow + (boost::gregorian::days(offset));
MensaEssen Essen = db_get_mensa_message(mensa_ID, datumEssen);
+
if (Essen.ID == -2) { // SQL got nothing back :/
//log("sql got nothing back!");
return getEssenOnline(mensa_ID, datumEssen);
}
+
if (Essen.LastModified + boost::posix_time::hours(2) < datumNow) { // LastModified is more than 2 hours old
if (downloadMensaFile(mensa_ID, datumEssen) != CURLE_OK) {
std::cerr << "Error downloading file" << std::endl;
@@ -272,6 +274,8 @@ Handler::json Handler::mensaHandler(const std::string &arguments, const std::str
(void) payload;
Handler::MensaHandler::mensa Mensa_ID;
+ return Response::simple_response("Mensafunktion gerade nicht verfügbar. Bitte versuchen Sie es Später erneut.");
+/*
auto args = tokenizeArguments(arguments);
std::string mensa_name = (!args.empty() ? args.at(0) : "adlershof");
@@ -290,4 +294,5 @@ Handler::json Handler::mensaHandler(const std::string &arguments, const std::str
int offset = std::stoi(offset_request);
return Response::create_response(getEssen(Mensa_ID, offset));
+ */
}
diff --git a/src/main.cpp b/src/main.cpp
index 948bc1d..db05590 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,7 @@
#include <vector>
#include <iostream>
-#include "crow.h"
+//#include "crow.h"
#include "Handler.hpp"
#include "Response.hpp"