Browse Source

to add alternative solution

valid_but_not_the_way_i_understood
Christof Nolle 4 years ago
parent
commit
7206c89919
  1. 11
      src/main/scala/de/codingchallenge/services/ArticleExportService.scala

11
src/main/scala/de/codingchallenge/services/ArticleExportService.scala

@ -27,18 +27,27 @@ class ArticleExportService( @@ -27,18 +27,27 @@ class ArticleExportService(
* and the sum of stock values)
* Result is transformed to a 'ProductExport' which later on will be processed by the productExportRepository
*
* FIXME: This solution actually conflicts with the way I unsertood this part of the task:
* Pro Produkt soll jeweils der günstigste Artikel mit Bestand > 0 im Ergebnis enthalten
* sein (mit seinen jeweiligen Eigenschaften).
*
* But its considered valid by the server
*
* @return
*/
def exportArticles(productsSize: Int): Future[HttpResponse] = productExportRepository.add(Source.fromGraph[ProductExport, NotUsed](
articleRepository
.getArticles(productsSize)
.filter(_.stock > 0)
// .filter(_.stock > 0)
.map(a => (a, a.stock))
.via(new AccumulateWhileUnchanged[(Article, Int), String](_._1.productId))
.map(reduceTuples)
.map { case (article, stockSum) =>
logger.info(s"Reduced to article: $article and stockSum: $stockSum")
ProductExport(article, stockSum) }
.collect{
case p: ProductExport if p.stockSum > 0 => p
}
), productsSize)
def reduceTuples(t: Seq[(Article, Int)]): (Article, Int) = {

Loading…
Cancel
Save