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.

Article.scala 891B

12345678910111213141516171819202122232425262728
  1. package de.codingchallenge.models
  2. import de.codingchallenge.csv.CsvColumnReads
  3. import scala.util.{Success, Try}
  4. /**
  5. * Represents a record of the article list
  6. * @param id identifier of the article
  7. * @param productId identifier of the product the article is a variant of
  8. * @param description some descriptive text
  9. * @param price the articles price
  10. * @param stock the current stock
  11. */
  12. case class Article(id: String, productId: String, name: String, description: Option[String], price: Float, stock: Int)
  13. object Article {
  14. /**
  15. * Reads an article from a sequence of columns. Returns an Option with article in success case
  16. */
  17. implicit val csvColumnReads: CsvColumnReads[Article] = (s: Seq[String]) =>
  18. Try{ (s.head, s(1), s(2), Try(s(3)).toOption, s(4).toFloat, s(5).toInt) } match {
  19. case Success(t) => Some((Article.apply _).tupled(t))
  20. case _ => None
  21. }
  22. }