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 Oct 2, 2023
1 parent b601664 commit fcb2f6f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
2 changes: 1 addition & 1 deletion commercial/app/model/feeds/FeedParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import commercial.model.merchandise.events.{LiveEventAgent, MasterclassAgent}
import commercial.model.merchandise.jobs.JobsAgent
import commercial.model.merchandise.travel.TravelOffersAgent
import conf.Configuration
import commercial.model.merchandise.{Book, Job, LiveEvent, Masterclass, TravelOffer}
import commercial.model.merchandise.{Job, LiveEvent, Masterclass, TravelOffer}

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.Duration
Expand Down
48 changes: 0 additions & 48 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 @@ -160,7 +146,6 @@ object Merchandise {
val merchandiseWrites: Writes[Merchandise] = new Writes[Merchandise] {
def writes(m: Merchandise) =
m match {
case b: Book => Json.toJson(b)
case j: Job => Json.toJson(j)
case m: Masterclass => Json.toJson(m)
case m: Member => Json.toJson(m)
Expand All @@ -175,39 +160,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 fcb2f6f

Please sign in to comment.