diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 79057d2..e238864 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/src/core/article.cpp b/src/core/article.cpp index b56c413..b798fbb 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -16,4 +16,6 @@ bool Article::isSold() { return salePtr_ ? true : false; } std::string Article::getDescription() { return description_; } -Seller* Article::getSeller() { return sellerPtr_.get(); } \ No newline at end of file +Seller* Article::getSeller() { return sellerPtr_.get(); } + +int Article::getPrice() { return price_; } \ No newline at end of file diff --git a/src/core/article.h b/src/core/article.h index 4042924..03ceaf0 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -9,6 +9,7 @@ #include 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 sellerPtr_{}; diff --git a/src/core/database.cpp b/src/core/database.cpp index 086dfc9..bec8d37 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -184,7 +184,7 @@ unsigned int Database::storeSellers(std::vector& sellers) sqlite3_finalize(stmt); throw std::runtime_error(errMsg); } - seller.setState(Seller::State::CLEAN); + seller.setState(Seller::State::OK); ++count; sqlite3_finalize(stmt); } diff --git a/src/core/entity.h b/src/core/entity.h index 786d393..8f1f63f 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -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_; }; diff --git a/src/core/sale.cpp b/src/core/sale.cpp new file mode 100644 index 0000000..8407232 --- /dev/null +++ b/src/core/sale.cpp @@ -0,0 +1,10 @@ +#include "sale.h" + +#include + +int Sale::sumInCents() +{ + int test = std::accumulate(articles_.begin(), articles_.end(), 0, + [](int a, Article* b) { return a + b->getPrice(); }); + return test; +} \ No newline at end of file diff --git a/src/core/sale.h b/src/core/sale.h index 06f350d..e4d016e 100644 --- a/src/core/sale.h +++ b/src/core/sale.h @@ -1,8 +1,21 @@ #ifndef SALE_H #define SALE_H -class Sale : public Entity { +#include "article.h" +#include + +#include + +class Article; + +class Sale : public Entity +{ + public: + int sumInCents(); + private: + boost::posix_time::ptime systemTime_{boost::posix_time::second_clock::local_time()}; + std::vector articles_{}; }; #endif \ No newline at end of file diff --git a/test/test_database.cpp b/test/test_database.cpp index b2b4bf3..e4052c4 100644 --- a/test/test_database.cpp +++ b/test/test_database.cpp @@ -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); } \ No newline at end of file diff --git a/test/test_seller.cpp b/test/test_seller.cpp index b389820..2c0468f 100644 --- a/test/test_seller.cpp +++ b/test/test_seller.cpp @@ -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); } \ No newline at end of file