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::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; }
|
bool Article::isSold() { return salePtr_ ? true : false; }
|
|
@ -2,26 +2,28 @@
|
||||||
#define ARTICLE_H
|
#define ARTICLE_H
|
||||||
|
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
#include "seller.h"
|
|
||||||
#include "sale.h"
|
#include "sale.h"
|
||||||
|
#include "seller.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class Seller;
|
class Seller;
|
||||||
|
|
||||||
class Article : public Entity
|
class Article : public Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Article();
|
Article();
|
||||||
Article(std::shared_ptr<Seller> sellerPtr);
|
Article(std::shared_ptr<Seller> sellerPtr);
|
||||||
void setArticleNo(int articleNo);
|
void setArticleNo(int articleNo);
|
||||||
void setPrice(int price);
|
void setPrice(int price);
|
||||||
void setDescription(const std::string& description);
|
void setDescription(const std::string& description);
|
||||||
|
std::string getDescription();
|
||||||
bool isSold();
|
bool isSold();
|
||||||
void setSale(const std::shared_ptr<Sale> salePtr);
|
void setSale(std::shared_ptr<Sale> salePtr);
|
||||||
void setSeller(std::shared_ptr<Seller> sellerPtr);
|
void setSeller(std::shared_ptr<Seller> sellerPtr);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
std::shared_ptr<Seller> sellerPtr_{};
|
std::shared_ptr<Seller> sellerPtr_{};
|
||||||
std::shared_ptr<Sale> salePtr_{};
|
std::shared_ptr<Sale> salePtr_{};
|
||||||
int articleNo_{};
|
int articleNo_{};
|
||||||
|
|
|
@ -22,16 +22,19 @@ inline void Seller::setNumberOfOfferedArticles(int number) { numberOfOfferedArti
|
||||||
|
|
||||||
inline size_t Seller::getNumberOfOfferedArticles() { return articles_.size(); }
|
inline size_t Seller::getNumberOfOfferedArticles() { return articles_.size(); }
|
||||||
|
|
||||||
std::vector<Article> Seller::getArticles(bool onlySold) {
|
void Seller::addArticle(Article article) {
|
||||||
if (onlySold) {
|
articles_.push_back(article);
|
||||||
std::vector<Article> soldArticles;
|
}
|
||||||
for (auto article: articles_) {
|
|
||||||
if (article.isSold()) {
|
std::vector<Article*> Seller::getArticles(bool onlySold)
|
||||||
soldArticles.push_back(article);
|
{
|
||||||
}
|
std::vector<Article*> articles;
|
||||||
}
|
for (auto& article : articles_) {
|
||||||
return soldArticles;
|
if (onlySold && article.isSold()) {
|
||||||
} else {
|
articles.push_back(&article);
|
||||||
return articles_;
|
} else if (!onlySold) {
|
||||||
}
|
articles.push_back(&article);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return articles;
|
||||||
}
|
}
|
|
@ -15,12 +15,14 @@ class Seller : public Entity
|
||||||
Seller();
|
Seller();
|
||||||
Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0,
|
Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0,
|
||||||
int numberOfArticles = 0);
|
int numberOfArticles = 0);
|
||||||
|
|
||||||
void setSellerNo(int sellerNo);
|
void setSellerNo(int sellerNo);
|
||||||
void setFirstName(const std::string& firstName);
|
void setFirstName(const std::string& firstName);
|
||||||
void setLastName(const std::string& lastName);
|
void setLastName(const std::string& lastName);
|
||||||
void setNumberOfOfferedArticles(int number);
|
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();
|
size_t getNumberOfOfferedArticles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
#include <boost/test/included/unit_test.hpp>
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
||||||
// using namespace boost::unit_test;
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(create_uuid_nil)
|
BOOST_AUTO_TEST_CASE(create_uuid_nil)
|
||||||
{
|
{
|
||||||
Seller seller{};
|
Seller seller{};
|
||||||
|
@ -30,3 +28,11 @@ BOOST_AUTO_TEST_CASE(create_many)
|
||||||
sellers[i].createUuid();
|
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