Compare commits

...

5 commits

9 changed files with 36 additions and 7 deletions

View file

@ -1,6 +1,6 @@
find_package(Boost 1.62 REQUIRED)
find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
find_package(SQLite3 REQUIRED)
#set(CORE_HEADERS
@ -13,8 +13,9 @@ set(CORE_SOURCES
entity.cpp
seller.cpp
article.cpp
sale.cpp
)
add_library(core STATIC ${CORE_SOURCES})
target_link_libraries(core Boost::boost)
target_link_libraries(core Boost::boost Boost::date_time)
target_link_libraries(core sqlite3)

View file

@ -17,3 +17,5 @@ bool Article::isSold() { return salePtr_ ? true : false; }
std::string Article::getDescription() { return description_; }
Seller* Article::getSeller() { return sellerPtr_.get(); }
int Article::getPrice() { return price_; }

View file

@ -9,6 +9,7 @@
#include <string>
class Seller;
class Sale;
class Article : public Entity
{
@ -24,6 +25,7 @@ class Article : public Entity
std::string getDescription();
Seller* getSeller();
int getPrice();
private:
std::shared_ptr<Seller> sellerPtr_{};

View file

@ -184,7 +184,7 @@ unsigned int Database::storeSellers(std::vector<Seller>& sellers)
sqlite3_finalize(stmt);
throw std::runtime_error(errMsg);
}
seller.setState(Seller::State::CLEAN);
seller.setState(Seller::State::OK);
++count;
sqlite3_finalize(stmt);
}

View file

@ -9,7 +9,7 @@
class Entity
{
public:
enum class State { NEW, UPDATED, CLEAN };
enum class State { NEW, UPDATE, DELETE, OK };
virtual ~Entity() = 0;
const boost::uuids::uuid& getUuid() const { return uuid_; };

10
src/core/sale.cpp Normal file
View file

@ -0,0 +1,10 @@
#include "sale.h"
#include <numeric>
int Sale::sumInCents()
{
int test = std::accumulate(articles_.begin(), articles_.end(), 0,
[](int a, Article* b) { return a + b->getPrice(); });
return test;
}

View file

@ -1,8 +1,21 @@
#ifndef SALE_H
#define SALE_H
class Sale : public Entity {
#include "article.h"
#include <vector>
#include <boost/date_time.hpp>
class Article;
class Sale : public Entity
{
public:
int sumInCents();
private:
boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()};
std::vector<Article*> articles_{};
};
#endif

View file

@ -51,6 +51,6 @@ BOOST_AUTO_TEST_CASE(seller_states)
std::cout << "Anzahl sellers: " << sellers.size() << "\n";
BOOST_TEST((sellers.at(0).getState() == Entity::State::NEW));
BOOST_TEST(db.storeSellers(sellers) == 1);
BOOST_TEST((sellers.at(0).getState() == Entity::State::CLEAN));
BOOST_TEST((sellers.at(0).getState() == Entity::State::OK));
BOOST_TEST(db.storeSellers(sellers) == 0);
}

View file

@ -35,4 +35,5 @@ BOOST_AUTO_TEST_CASE(with_article) {
article->setDescription("Test article");
seller.addArticle(article);
BOOST_TEST(seller.getArticles().at(0)->getDescription() == "Test article");
BOOST_TEST(seller.soldArticles() == 0);
}