diff --git a/menu.cpp b/menu.cpp index 8b12628..9741cfc 100644 --- a/menu.cpp +++ b/menu.cpp @@ -55,27 +55,18 @@ bool LunchRest::Menu::isValid() const { } std::string LunchRest::Menu::jsonify() const { - return jsonify({}); -} - -std::string LunchRest::Menu::jsonify(const std::vector &permanent) const { - if(!isValid() && permanent.empty()) + if(!isValid()) return "{\"day\": \"" + getDay() + "\", \"meals\": []}"; std::stringstream ss{}; - bool atleastone = false; ss << "{\"day\": \"" << getDay() << "\", \"meals\": ["; auto soupInd = getSoupIndex(); if(soupInd != (unsigned long int)-1) ss << getMeals()[soupInd].jsonify() << ","; for(unsigned long int i = 0; i < getMeals().size(); i++) { - atleastone = true; if(i != soupInd) ss << getMeals()[i].jsonify() << ","; } - for(auto &meal : permanent) { - ss << meal.jsonify() << ","; - } - if(atleastone) + if(getMeals().size() > 0) ss.seekp(-1, ss.cur); ss << "]}"; return ss.str(); diff --git a/menu.hpp b/menu.hpp index ebbfc27..ad75032 100644 --- a/menu.hpp +++ b/menu.hpp @@ -22,7 +22,6 @@ public: void setInvalidMenu( bool invalid = true ); bool isValid() const; std::string jsonify() const; - std::string jsonify(const std::vector &permanent) const; void setDay(const std::string &day); const std::string &getDay() const; private: diff --git a/restaurant.hpp b/restaurant.hpp index c2b22e2..08eef38 100644 --- a/restaurant.hpp +++ b/restaurant.hpp @@ -33,12 +33,18 @@ public: } std::string jsonify(const std::vector &days = {0,1,2,3,4}) { std::stringstream ss{}; - ss << "{\"restaurant\": \"" << getRestaurant() << "\", \"menus\": ["; + ss << "{\"restaurant\": \"" << getRestaurant() << "\", \"dailymenus\": ["; for(auto &day : days) { - ss << menus[day].jsonify(permanent) << ","; + ss << menus[day].jsonify() << ","; } if(!days.empty()) ss.seekp(-1, ss.cur); + ss << "], \"permanentmeals\": ["; + for(auto &meal : permanent) { + ss << meal.jsonify() << ","; + } + if(permanent.size() > 0) + ss.seekp(-1, ss.cur); ss << "]}"; return ss.str(); }