diff --git a/src/core/article.cpp b/src/core/article.cpp index 5d046ff..3270da7 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -10,6 +10,8 @@ void Article::setPrice(int price) { price_ = price; } void Article::setDescription(const std::string& description) { description_ = description; } -void Article::setSale(const std::shared_ptr salePtr) { salePtr_ = salePtr; } +std::string Article::getDescription() { return description_; } + +void Article::setSale(std::shared_ptr salePtr) { salePtr_ = salePtr; } bool Article::isSold() { return salePtr_ ? true : false; } \ No newline at end of file diff --git a/src/core/article.h b/src/core/article.h index dd93e89..1d0487b 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -2,26 +2,28 @@ #define ARTICLE_H #include "entity.h" -#include "seller.h" #include "sale.h" +#include "seller.h" -#include #include +#include class Seller; class Article : public Entity { -public: + public: Article(); Article(std::shared_ptr sellerPtr); void setArticleNo(int articleNo); void setPrice(int price); void setDescription(const std::string& description); + std::string getDescription(); bool isSold(); - void setSale(const std::shared_ptr salePtr); + void setSale(std::shared_ptr salePtr); void setSeller(std::shared_ptr sellerPtr); -private: + + private: std::shared_ptr sellerPtr_{}; std::shared_ptr salePtr_{}; int articleNo_{}; diff --git a/src/core/seller.cpp b/src/core/seller.cpp index 1a205d0..634e585 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -22,16 +22,19 @@ inline void Seller::setNumberOfOfferedArticles(int number) { numberOfOfferedArti inline size_t Seller::getNumberOfOfferedArticles() { return articles_.size(); } -std::vector
Seller::getArticles(bool onlySold) { - if (onlySold) { - std::vector
soldArticles; - for (auto article: articles_) { - if (article.isSold()) { - soldArticles.push_back(article); - } +void Seller::addArticle(Article article) { + articles_.push_back(article); +} + +std::vector Seller::getArticles(bool onlySold) +{ + std::vector articles; + for (auto& article : articles_) { + if (onlySold && article.isSold()) { + articles.push_back(&article); + } else if (!onlySold) { + articles.push_back(&article); } - return soldArticles; - } else { - return articles_; } + return articles; } \ No newline at end of file diff --git a/src/core/seller.h b/src/core/seller.h index b5ccb54..4ac6a98 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -15,12 +15,14 @@ class Seller : public Entity Seller(); Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0, int numberOfArticles = 0); + void setSellerNo(int sellerNo); void setFirstName(const std::string& firstName); void setLastName(const std::string& lastName); void setNumberOfOfferedArticles(int number); - std::vector
getArticles(bool onlySold = false); + void addArticle(Article article); + std::vector getArticles(bool onlySold = false); size_t getNumberOfOfferedArticles(); private: diff --git a/test/test_seller.cpp b/test/test_seller.cpp index e9254c7..5de2ed2 100644 --- a/test/test_seller.cpp +++ b/test/test_seller.cpp @@ -6,8 +6,6 @@ #include -// using namespace boost::unit_test; - BOOST_AUTO_TEST_CASE(create_uuid_nil) { Seller seller{}; @@ -29,4 +27,12 @@ BOOST_AUTO_TEST_CASE(create_many) sellers[i] = Seller(); sellers[i].createUuid(); } +} + +BOOST_AUTO_TEST_CASE(with_article) { + Seller seller("Max", "Mustermann"); + Article article{}; + article.setDescription("Test article"); + seller.addArticle(article); + BOOST_TEST(seller.getArticles().at(0)->getDescription() == "Test article"); } \ No newline at end of file