Do not ignore seller entries with empty names.

fixes #23
This commit is contained in:
Martin Brodbeck 2022-09-24 20:25:33 +02:00
parent ecd1111391
commit 01577d02a0
2 changed files with 26 additions and 17 deletions

View file

@ -39,11 +39,6 @@ std::size_t CsvReader::readSellersFromFile(const fs::path &filePath, Marketplace
continue; continue;
} }
if (row[2].get<std::string>().empty() && row[3].get<std::string>().empty()) {
++rowCount;
continue;
}
auto seller = std::make_unique<Seller>(); auto seller = std::make_unique<Seller>();
seller->setSellerNo(row[0].get<int>()); seller->setSellerNo(row[0].get<int>());
if (row[1].is_int()) { if (row[1].is_int()) {
@ -51,10 +46,19 @@ std::size_t CsvReader::readSellersFromFile(const fs::path &filePath, Marketplace
} else { } else {
seller->setNumArticlesOffered(0); seller->setNumArticlesOffered(0);
} }
// If both, first name and last name, are empty, use N. N.
// Else, use the real values.
if (row[2].get<std::string>().empty() && row[3].get<std::string>().empty()) {
seller->setFirstName("N.");
seller->setLastName("N.");
} else {
std::string firstName = row[2].get<std::string>(); std::string firstName = row[2].get<std::string>();
seller->setFirstName(trim(firstName)); seller->setFirstName(trim(firstName));
std::string lastName = row[3].get<std::string>(); std::string lastName = row[3].get<std::string>();
seller->setLastName(trim(lastName)); seller->setLastName(trim(lastName));
}
market->getSellers().push_back(std::move(seller)); market->getSellers().push_back(std::move(seller));
rowCount++; rowCount++;
} }

View file

@ -28,17 +28,22 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path &filePath, Marketpla
continue; continue;
} }
// Skip the row if the seller has neither a first name nor a surname
if (row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
continue;
}
auto seller = std::make_unique<Seller>(); auto seller = std::make_unique<Seller>();
seller->setSellerNo(row[0].value<int>()); seller->setSellerNo(row[0].value<int>());
seller->setNumArticlesOffered(row[1].value<int>()); seller->setNumArticlesOffered(row[1].value<int>());
// If both, first name and last name, are empty, use N. N.
// Else, use the real values.
if (row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
seller->setFirstName("N.");
seller->setLastName("N.");
} else {
std::string firstName = row[2].value<std::string>(); std::string firstName = row[2].value<std::string>();
seller->setFirstName(trim(firstName)); seller->setFirstName(trim(firstName));
std::string lastName = row[3].value<std::string>(); std::string lastName = row[3].value<std::string>();
seller->setLastName(trim(lastName)); seller->setLastName(trim(lastName));
}
market->getSellers().push_back(std::move(seller)); market->getSellers().push_back(std::move(seller));
} }