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) {
|
||||
++count;
|
||||
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->setSourceNo(sqlite3_column_int(stmt, 1));
|
||||
article->setArticleNo(sqlite3_column_int(stmt, 2));
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include <fstream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using json = nlohmann::json;
|
||||
|
||||
void JsonUtil::exportSellers(const std::filesystem::path &filePath, Marketplace *market)
|
||||
|
|
|
@ -6,38 +6,38 @@
|
|||
void Sale::addArticle(Article *articlePtr)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)->setState(
|
||||
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 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(); });
|
||||
return sum;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ class Sale : public EntityUuid
|
|||
void removeArticle(const Article *articlePtr);
|
||||
|
||||
private:
|
||||
std::string timestamp_{
|
||||
std::string m_timestamp{
|
||||
boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time())};
|
||||
mutable ArticlesVec articles_{};
|
||||
mutable ArticlesVec m_articles{};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,28 +9,28 @@ Seller::Seller(const std::string& firstName, const std::string& lastName, int se
|
|||
int numArticlesOffered)
|
||||
: EntityInt(sellerNo)
|
||||
{
|
||||
firstName_ = firstName;
|
||||
lastName_ = lastName;
|
||||
numArticlesOffered_ = numArticlesOffered;
|
||||
m_firstName = firstName;
|
||||
m_lastName = lastName;
|
||||
m_numArticlesOffered = numArticlesOffered;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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(); }
|
||||
|
||||
|
@ -47,7 +47,7 @@ std::string Seller::getSellerNoAsString() const
|
|||
std::vector<Article *> Seller::getArticles(bool onlySold) const
|
||||
{
|
||||
std::vector<Article *> articles;
|
||||
for (const auto& article : articles_) {
|
||||
for (const auto &article : m_articles) {
|
||||
if (onlySold && article->isSold()) {
|
||||
articles.push_back(article.get());
|
||||
} else if (!onlySold) {
|
||||
|
@ -59,44 +59,44 @@ std::vector<Article*> Seller::getArticles(bool onlySold) const
|
|||
|
||||
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;
|
||||
});
|
||||
if (iter == articles_.end())
|
||||
if (iter == m_articles.end())
|
||||
return nullptr;
|
||||
return (*iter).get();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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(); });
|
||||
if (iter == articles_.end())
|
||||
if (iter == m_articles.end())
|
||||
return 0;
|
||||
return (*iter)->getArticleNo();
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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(); });
|
||||
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);
|
||||
|
||||
private:
|
||||
int numArticlesOffered_{};
|
||||
std::string firstName_{};
|
||||
std::string lastName_{};
|
||||
std::vector<std::unique_ptr<Article>> articles_{};
|
||||
int m_numArticlesOffered{};
|
||||
std::string m_firstName{};
|
||||
std::string m_lastName{};
|
||||
std::vector<std::unique_ptr<Article>> m_articles{};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue