Seperate daily menu from permanent menu in json
This commit is contained in:
parent
0fbba2c010
commit
0702c6ebb1
13
menu.cpp
13
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<Meal> &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();
|
||||
|
1
menu.hpp
1
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<Meal> &permanent) const;
|
||||
void setDay(const std::string &day);
|
||||
const std::string &getDay() const;
|
||||
private:
|
||||
|
@ -33,12 +33,18 @@ public:
|
||||
}
|
||||
std::string jsonify(const std::vector<int> &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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user