Skip to content

Commit

Permalink
delete book case class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii committed Sep 29, 2023
1 parent b601664 commit 426ba41
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions commercial/app/model/merchandise/Merchandise.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ import scala.xml.Node

sealed trait Merchandise

case class Book(
title: String,
author: Option[String],
isbn: String,
price: Option[Double] = None,
offerPrice: Option[Double] = None,
description: Option[String] = None,
jacketUrl: Option[String],
buyUrl: Option[String] = None,
position: Option[Int] = None,
category: Option[String] = None,
keywordIdSuffixes: Seq[String] = Nil,
) extends Merchandise

case class Masterclass(
id: String,
name: String,
Expand Down Expand Up @@ -175,39 +161,6 @@ object Merchandise {
}
}

object Book {

private val authorReads = ((JsPath \ "author_firstname").readNullable[String] and
(JsPath \ "author_lastname").readNullable[String]).tupled.map {
case (optFirstName, optLastName) =>
for {
firstName <- optFirstName
lastName <- optLastName
} yield s"$firstName $lastName"
}

private def stringOrDoubleAsDouble(value: String): Reads[Option[Double]] = {
val path = JsPath \ value
path.readNullable[Double] orElse path.readNullable[String].map(_.map(_.toDouble))
}

implicit val bookReads: Reads[Book] = (
(JsPath \ "name").read[String] and
authorReads and
(JsPath \ "isbn").read[String] and
stringOrDoubleAsDouble("regular_price_with_tax") and
stringOrDoubleAsDouble("final_price_with_tax") and
(JsPath \ "description").readNullable[String] and
(JsPath \ "images")(0).readNullable[String] and
(JsPath \ "product_url").readNullable[String] and
(JsPath \ "guardian_bestseller_rank").readNullable[String].map(_.map(_.toDouble.toInt)) and
((JsPath \ "categories")(0) \ "name").readNullable[String] and
(JsPath \ "keywordIds").readNullable[Seq[String]].map(_ getOrElse Nil)
)(Book.apply _)

implicit val bookWrites: Writes[Book] = Json.writes[Book]
}

object Masterclass {

def fromEvent(event: Event): Option[Masterclass] = {
Expand Down

0 comments on commit 426ba41

Please sign in to comment.