more on articles
This commit is contained in:
parent
c1c7e32291
commit
f42855dc50
5 changed files with 34 additions and 19 deletions
|
@ -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<Sale> salePtr) { salePtr_ = salePtr; }
|
||||
std::string Article::getDescription() { return description_; }
|
||||
|
||||
void Article::setSale(std::shared_ptr<Sale> salePtr) { salePtr_ = salePtr; }
|
||||
|
||||
bool Article::isSold() { return salePtr_ ? true : false; }
|
|
@ -2,26 +2,28 @@
|
|||
#define ARTICLE_H
|
||||
|
||||
#include "entity.h"
|
||||
#include "seller.h"
|
||||
#include "sale.h"
|
||||
#include "seller.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Seller;
|
||||
|
||||
class Article : public Entity
|
||||
{
|
||||
public:
|
||||
public:
|
||||
Article();
|
||||
Article(std::shared_ptr<Seller> 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<Sale> salePtr);
|
||||
void setSale(std::shared_ptr<Sale> salePtr);
|
||||
void setSeller(std::shared_ptr<Seller> sellerPtr);
|
||||
private:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Seller> sellerPtr_{};
|
||||
std::shared_ptr<Sale> salePtr_{};
|
||||
int articleNo_{};
|
||||
|
|
|
@ -22,16 +22,19 @@ inline void Seller::setNumberOfOfferedArticles(int number) { numberOfOfferedArti
|
|||
|
||||
inline size_t Seller::getNumberOfOfferedArticles() { return articles_.size(); }
|
||||
|
||||
std::vector<Article> Seller::getArticles(bool onlySold) {
|
||||
if (onlySold) {
|
||||
std::vector<Article> soldArticles;
|
||||
for (auto article: articles_) {
|
||||
if (article.isSold()) {
|
||||
soldArticles.push_back(article);
|
||||
}
|
||||
}
|
||||
return soldArticles;
|
||||
} else {
|
||||
return articles_;
|
||||
}
|
||||
void Seller::addArticle(Article article) {
|
||||
articles_.push_back(article);
|
||||
}
|
||||
|
||||
std::vector<Article*> Seller::getArticles(bool onlySold)
|
||||
{
|
||||
std::vector<Article*> articles;
|
||||
for (auto& article : articles_) {
|
||||
if (onlySold && article.isSold()) {
|
||||
articles.push_back(&article);
|
||||
} else if (!onlySold) {
|
||||
articles.push_back(&article);
|
||||
}
|
||||
}
|
||||
return articles;
|
||||
}
|
|
@ -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<Article> getArticles(bool onlySold = false);
|
||||
void addArticle(Article article);
|
||||
|
||||
std::vector<Article*> getArticles(bool onlySold = false);
|
||||
size_t getNumberOfOfferedArticles();
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
// using namespace boost::unit_test;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(create_uuid_nil)
|
||||
{
|
||||
Seller seller{};
|
||||
|
@ -30,3 +28,11 @@ BOOST_AUTO_TEST_CASE(create_many)
|
|||
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");
|
||||
}
|
Loading…
Reference in a new issue