From 70ce0ceb190f116432e6979e188a5cb79beaee66 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 12:18:51 +0200 Subject: [PATCH 1/5] flags changed --- src/core/database.cpp | 2 +- src/core/entity.h | 2 +- test/test_database.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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 From b84bc5bff010a69b028b5d0fcb6eaa9eb34264a9 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 13:34:00 +0200 Subject: [PATCH 2/5] check for number of sold articles --- test/test_seller.cpp | 1 + 1 file changed, 1 insertion(+) 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 From 6b6dddcaaad8a951bc2832c4468baa7fbe18f085 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 13:34:17 +0200 Subject: [PATCH 3/5] initial commit --- src/core/sale.cpp | 10 ++++++++++ src/core/sale.h | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/core/sale.cpp 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 From 7063637ad4ac2295a209d20ec606b03465a14131 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 13:34:38 +0200 Subject: [PATCH 4/5] Added boost::date_time dependency --- src/core/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 2c5368c621b8ee95c338e6fbe70c74bdfde3e2f3 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 12 Jul 2018 13:36:13 +0200 Subject: [PATCH 5/5] more on article --- src/core/article.cpp | 4 +++- src/core/article.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) 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_{};