more on sales

This commit is contained in:
Martin Brodbeck 2018-07-13 10:51:07 +02:00
parent 91357d7c7f
commit f838977283
2 changed files with 24 additions and 4 deletions

View file

@ -8,6 +8,16 @@ void Sale::addArticle(std::shared_ptr<Article> articlePtr)
articles_.push_back(articlePtr); articles_.push_back(articlePtr);
} }
std::vector<Article*> Sale::getArticles()
{
std::vector<Article*> articles(articles_.size());
for (const auto& article : articles_) {
articles.push_back(article.get());
}
return articles;
}
void Sale::removeArticle(const Article* articlePtr) void Sale::removeArticle(const Article* articlePtr)
{ {
auto it = std::find_if(articles_.begin(), articles_.end(), auto it = std::find_if(articles_.begin(), articles_.end(),
@ -24,3 +34,7 @@ int Sale::sumInCents()
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); }); [](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
return sum; return sum;
} }
std::string Sale::getTimestamp() { return timestamp_; }
void Sale::setTimestamp(const std::string& timestamp) { timestamp_ = timestamp; }

View file

@ -5,19 +5,25 @@
#include <vector> #include <vector>
#include <boost/date_time.hpp> #include "boost/date_time/posix_time/posix_time.hpp"
class Article; class Article;
class Sale : public Entity class Sale : public Entity
{ {
public: public:
int sumInCents();
void addArticle(std::shared_ptr<Article> articlePtr); void addArticle(std::shared_ptr<Article> articlePtr);
void setTimestamp(const std::string& timestamp);
std::vector<Article*> getArticles();
std::string getTimestamp();
int sumInCents();
void removeArticle(const Article* articlePtr); void removeArticle(const Article* articlePtr);
private: private:
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()}; std::string timestamp_{
boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())};
std::vector<std::shared_ptr<Article>> articles_{}; std::vector<std::shared_ptr<Article>> articles_{};
}; };