|
|
|
@ -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) = { |
|
|
|
|