remove article from sale
This commit is contained in:
parent
2fb72f1701
commit
91357d7c7f
3 changed files with 24 additions and 1 deletions
|
@ -8,9 +8,19 @@ void Sale::addArticle(std::shared_ptr<Article> articlePtr)
|
|||
articles_.push_back(articlePtr);
|
||||
}
|
||||
|
||||
void Sale::removeArticle(const Article* articlePtr)
|
||||
{
|
||||
auto it = std::find_if(articles_.begin(), articles_.end(),
|
||||
[&articlePtr](auto art) { return art.get() == articlePtr; });
|
||||
if (it != articles_.end()) {
|
||||
(*it)->setSale(nullptr);
|
||||
articles_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
int Sale::sumInCents()
|
||||
{
|
||||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
||||
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
|
||||
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
|
||||
return sum;
|
||||
}
|
|
@ -14,6 +14,8 @@ class Sale : public Entity
|
|||
public:
|
||||
int sumInCents();
|
||||
void addArticle(std::shared_ptr<Article> articlePtr);
|
||||
void removeArticle(const Article* articlePtr);
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()};
|
||||
std::vector<std::shared_ptr<Article>> articles_{};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue