You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductExport.scala 938B

123456789101112131415161718192021222324252627282930313233
  1. package de.codingchallenge.models
  2. import java.text.DecimalFormat
  3. import java.util.Locale
  4. import de.codingchallenge.csv.CsvColumnWrites
  5. /**
  6. * Data structure representing the CSV export
  7. * @param productId product group identifier
  8. * @param name name of the product
  9. * @param description description of the product
  10. * @param price price
  11. * @param stockSum stock over group
  12. */
  13. case class ProductExport(productId: String, name: String, description: String, price:Float, stockSum: Int)
  14. object ProductExport {
  15. implicit val columnWrites: CsvColumnWrites[ProductExport] = (p: ProductExport) => Seq(
  16. p.productId, p.name, p.description,"%.2f".formatLocal(java.util.Locale.US, p.price), p.stockSum.toString
  17. )
  18. def apply(a: Article, stockSum: Int): ProductExport = new ProductExport(
  19. productId = a.productId,
  20. name = a.name,
  21. description = a.description.getOrElse(""),
  22. price = a.price,
  23. stockSum = stockSum
  24. )
  25. }