code formatting
This commit is contained in:
parent
d677dfd628
commit
acc3095e60
23 changed files with 215 additions and 215 deletions
|
@ -594,7 +594,8 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
||||||
while (retCode != SQLITE_DONE) {
|
while (retCode != SQLITE_DONE) {
|
||||||
++count;
|
++count;
|
||||||
auto article = std::make_unique<Article>();
|
auto article = std::make_unique<Article>();
|
||||||
article->setUuidFromString(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
|
article->setUuidFromString(
|
||||||
|
reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)));
|
||||||
article->setSeller(seller.get());
|
article->setSeller(seller.get());
|
||||||
article->setSourceNo(sqlite3_column_int(stmt, 1));
|
article->setSourceNo(sqlite3_column_int(stmt, 1));
|
||||||
article->setArticleNo(sqlite3_column_int(stmt, 2));
|
article->setArticleNo(sqlite3_column_int(stmt, 2));
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
void JsonUtil::exportSellers(const std::filesystem::path &filePath, Marketplace *market)
|
void JsonUtil::exportSellers(const std::filesystem::path &filePath, Marketplace *market)
|
||||||
|
|
|
@ -6,38 +6,38 @@
|
||||||
void Sale::addArticle(Article *articlePtr)
|
void Sale::addArticle(Article *articlePtr)
|
||||||
{
|
{
|
||||||
articlePtr->setSale(this);
|
articlePtr->setSale(this);
|
||||||
articles_.push_back(articlePtr);
|
m_articles.push_back(articlePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArticlesVec& Sale::getArticles() { return articles_; }
|
ArticlesVec &Sale::getArticles() { return m_articles; }
|
||||||
|
|
||||||
void Sale::removeArticle(const Article *articlePtr)
|
void Sale::removeArticle(const Article *articlePtr)
|
||||||
{
|
{
|
||||||
auto it = std::find(articles_.begin(), articles_.end(), articlePtr);
|
auto it = std::find(m_articles.begin(), m_articles.end(), articlePtr);
|
||||||
|
|
||||||
if (it != articles_.end()) {
|
if (it != m_articles.end()) {
|
||||||
(*it)->setSale(nullptr);
|
(*it)->setSale(nullptr);
|
||||||
(*it)->setState(
|
(*it)->setState(
|
||||||
Article::State::DELETE); // since we only have ad-hoc articles, that have all been sold
|
Article::State::DELETE); // since we only have ad-hoc articles, that have all been sold
|
||||||
articles_.erase(it);
|
m_articles.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sale::sumInCents()
|
int Sale::sumInCents()
|
||||||
{
|
{
|
||||||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
int sum = std::accumulate(m_articles.begin(), m_articles.end(), 0,
|
||||||
[](int a, const Article *b) { return a + b->getPrice(); });
|
[](int a, const Article *b) { return a + b->getPrice(); });
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Sale::sumAsString() { return formatCentAsEuroString(sumInCents()); }
|
std::string Sale::sumAsString() { return formatCentAsEuroString(sumInCents()); }
|
||||||
|
|
||||||
std::string Sale::getTimestamp() const { return timestamp_; }
|
std::string Sale::getTimestamp() const { return m_timestamp; }
|
||||||
|
|
||||||
void Sale::setTimestamp(const std::string& timestamp) { timestamp_ = timestamp; }
|
void Sale::setTimestamp(const std::string ×tamp) { m_timestamp = timestamp; }
|
||||||
|
|
||||||
std::string Sale::getTimestampFormatted() const
|
std::string Sale::getTimestampFormatted() const
|
||||||
{
|
{
|
||||||
boost::posix_time::ptime time = boost::posix_time::from_iso_extended_string(timestamp_);
|
boost::posix_time::ptime time = boost::posix_time::from_iso_extended_string(m_timestamp);
|
||||||
return boost::posix_time::to_simple_string(time);
|
return boost::posix_time::to_simple_string(time);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ class Sale : public EntityUuid
|
||||||
void removeArticle(const Article *articlePtr);
|
void removeArticle(const Article *articlePtr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string timestamp_{
|
std::string m_timestamp{
|
||||||
boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())};
|
boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())};
|
||||||
mutable ArticlesVec articles_{};
|
mutable ArticlesVec m_articles{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,28 +9,28 @@ Seller::Seller(const std::string& firstName, const std::string& lastName, int se
|
||||||
int numArticlesOffered)
|
int numArticlesOffered)
|
||||||
: EntityInt(sellerNo)
|
: EntityInt(sellerNo)
|
||||||
{
|
{
|
||||||
firstName_ = firstName;
|
m_firstName = firstName;
|
||||||
lastName_ = lastName;
|
m_lastName = lastName;
|
||||||
numArticlesOffered_ = numArticlesOffered;
|
m_numArticlesOffered = numArticlesOffered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Seller::setSellerNo(int seller_no) { setId(seller_no); }
|
void Seller::setSellerNo(int seller_no) { setId(seller_no); }
|
||||||
|
|
||||||
void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; }
|
void Seller::setFirstName(const std::string &firstName) { m_firstName = firstName; }
|
||||||
|
|
||||||
void Seller::setLastName(const std::string& lastName) { lastName_ = lastName; }
|
void Seller::setLastName(const std::string &lastName) { m_lastName = lastName; }
|
||||||
|
|
||||||
void Seller::setNumArticlesOffered(int number) { numArticlesOffered_ = number; }
|
void Seller::setNumArticlesOffered(int number) { m_numArticlesOffered = number; }
|
||||||
|
|
||||||
void Seller::addArticle(std::unique_ptr<Article> article)
|
void Seller::addArticle(std::unique_ptr<Article> article)
|
||||||
{
|
{
|
||||||
article->setSeller(this);
|
article->setSeller(this);
|
||||||
articles_.push_back(std::move(article));
|
m_articles.push_back(std::move(article));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Seller::getFirstName() const { return firstName_; }
|
std::string Seller::getFirstName() const { return m_firstName; }
|
||||||
|
|
||||||
std::string Seller::getLastName() const { return lastName_; }
|
std::string Seller::getLastName() const { return m_lastName; }
|
||||||
|
|
||||||
int Seller::getSellerNo() const { return getId(); }
|
int Seller::getSellerNo() const { return getId(); }
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ std::string Seller::getSellerNoAsString() const
|
||||||
std::vector<Article *> Seller::getArticles(bool onlySold) const
|
std::vector<Article *> Seller::getArticles(bool onlySold) const
|
||||||
{
|
{
|
||||||
std::vector<Article *> articles;
|
std::vector<Article *> articles;
|
||||||
for (const auto& article : articles_) {
|
for (const auto &article : m_articles) {
|
||||||
if (onlySold && article->isSold()) {
|
if (onlySold && article->isSold()) {
|
||||||
articles.push_back(article.get());
|
articles.push_back(article.get());
|
||||||
} else if (!onlySold) {
|
} else if (!onlySold) {
|
||||||
|
@ -59,44 +59,44 @@ std::vector<Article*> Seller::getArticles(bool onlySold) const
|
||||||
|
|
||||||
Article *Seller::getArticleByUuid(const std::string &uuidString)
|
Article *Seller::getArticleByUuid(const std::string &uuidString)
|
||||||
{
|
{
|
||||||
auto iter = std::find_if(articles_.begin(), articles_.end(), [&uuidString](const auto& art) {
|
auto iter = std::find_if(m_articles.begin(), m_articles.end(), [&uuidString](const auto &art) {
|
||||||
return art->getUuidAsString() == uuidString;
|
return art->getUuidAsString() == uuidString;
|
||||||
});
|
});
|
||||||
if (iter == articles_.end())
|
if (iter == m_articles.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Seller::numArticlesSold() const { return static_cast<int>(getArticles(true).size()); }
|
int Seller::numArticlesSold() const { return static_cast<int>(getArticles(true).size()); }
|
||||||
|
|
||||||
int Seller::numArticlesOffered() const { return numArticlesOffered_; }
|
int Seller::numArticlesOffered() const { return m_numArticlesOffered; }
|
||||||
|
|
||||||
int Seller::getMaxArticleNo() const
|
int Seller::getMaxArticleNo() const
|
||||||
{
|
{
|
||||||
auto iter = std::max_element(
|
auto iter = std::max_element(
|
||||||
articles_.begin(), articles_.end(),
|
m_articles.begin(), m_articles.end(),
|
||||||
[](const auto &a, const auto &b) -> bool { return a->getArticleNo() < b->getArticleNo(); });
|
[](const auto &a, const auto &b) -> bool { return a->getArticleNo() < b->getArticleNo(); });
|
||||||
if (iter == articles_.end())
|
if (iter == m_articles.end())
|
||||||
return 0;
|
return 0;
|
||||||
return (*iter)->getArticleNo();
|
return (*iter)->getArticleNo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Seller::cleanupArticles()
|
void Seller::cleanupArticles()
|
||||||
{
|
{
|
||||||
articles_.erase(std::remove_if(articles_.begin(), articles_.end(),
|
m_articles.erase(std::remove_if(m_articles.begin(), m_articles.end(),
|
||||||
[](const auto &article) {
|
[](const auto &article) {
|
||||||
return article->getState() == Article::State::DELETE;
|
return article->getState() == Article::State::DELETE;
|
||||||
}),
|
}),
|
||||||
articles_.end());
|
m_articles.end());
|
||||||
|
|
||||||
for (auto& article : articles_) {
|
for (auto &article : m_articles) {
|
||||||
article->setState(Article::State::OK);
|
article->setState(Article::State::OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Seller::sumInCents()
|
int Seller::sumInCents()
|
||||||
{
|
{
|
||||||
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
|
int sum = std::accumulate(m_articles.begin(), m_articles.end(), 0,
|
||||||
[](int a, const auto &b) { return a + b->getPrice(); });
|
[](int a, const auto &b) { return a + b->getPrice(); });
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,10 @@ class Seller : public EntityInt
|
||||||
friend bool operator<(const std::unique_ptr<Seller> &li, const std::unique_ptr<Seller> &re);
|
friend bool operator<(const std::unique_ptr<Seller> &li, const std::unique_ptr<Seller> &re);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int numArticlesOffered_{};
|
int m_numArticlesOffered{};
|
||||||
std::string firstName_{};
|
std::string m_firstName{};
|
||||||
std::string lastName_{};
|
std::string m_lastName{};
|
||||||
std::vector<std::unique_ptr<Article>> articles_{};
|
std::vector<std::unique_ptr<Article>> m_articles{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue