Skip to content

Commit

Permalink
remove commercial BookOffersAPI (#26615)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii authored Oct 3, 2023
1 parent 12d02e7 commit 34570a9
Show file tree
Hide file tree
Showing 23 changed files with 4 additions and 739 deletions.
4 changes: 0 additions & 4 deletions commercial/app/AppLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import commercial.CommercialLifecycle
import commercial.controllers.{CommercialControllers, HealthCheck}
import commercial.model.capi.CapiAgent
import commercial.model.feeds.{FeedsFetcher, FeedsParser}
import commercial.model.merchandise.books.{BestsellersAgent, BookFinder, MagentoService}
import commercial.model.merchandise.events.{LiveEventAgent, MasterclassAgent}
import commercial.model.merchandise.jobs.{Industries, JobsAgent}
import commercial.model.merchandise.travel.TravelOffersAgent
Expand Down Expand Up @@ -38,12 +37,9 @@ trait CommercialServices {
def pekkoActorSystem: PekkoActorSystem
implicit val executionContext: ExecutionContext

lazy val magentoService = wire[MagentoService]
lazy val capiHttpClient: HttpClient = wire[CapiHttpClient]
lazy val contentApiClient = wire[ContentApiClient]

lazy val bookFinder = wire[BookFinder]
lazy val bestsellersAgent = wire[BestsellersAgent]
lazy val liveEventAgent = wire[LiveEventAgent]
lazy val masterclassAgent = wire[MasterclassAgent]
lazy val travelOffersAgent = wire[TravelOffersAgent]
Expand Down
55 changes: 0 additions & 55 deletions commercial/app/controllers/BookOffersController.scala

This file was deleted.

4 changes: 0 additions & 4 deletions commercial/app/controllers/CommercialControllers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commercial.controllers

import com.softwaremill.macwire._
import commercial.model.capi.CapiAgent
import commercial.model.merchandise.books.{BestsellersAgent, BookFinder}
import commercial.model.merchandise.events.{LiveEventAgent, MasterclassAgent}
import commercial.model.merchandise.jobs.JobsAgent
import commercial.model.merchandise.travel.TravelOffersAgent
Expand All @@ -12,16 +11,13 @@ import play.api.mvc.ControllerComponents

trait CommercialControllers {
def contentApiClient: ContentApiClient
def bestsellersAgent: BestsellersAgent
def liveEventAgent: LiveEventAgent
def bookFinder: BookFinder
def capiAgent: CapiAgent
def masterclassAgent: MasterclassAgent
def travelOffersAgent: TravelOffersAgent
def jobsAgent: JobsAgent
def controllerComponents: ControllerComponents
implicit def appContext: ApplicationContext
lazy val bookOffersController = wire[BookOffersController]
lazy val contentApiOffersController = wire[ContentApiOffersController]
lazy val creativeTestPage = wire[CreativeTestPage]
lazy val hostedContentController = wire[HostedContentController]
Expand Down
12 changes: 0 additions & 12 deletions commercial/app/controllers/Multi.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commercial.controllers

import commercial.model.Segment
import commercial.model.merchandise.books.BestsellersAgent
import commercial.model.merchandise.events.MasterclassAgent
import commercial.model.merchandise.jobs.JobsAgent
import commercial.model.merchandise.travel.TravelOffersAgent
Expand All @@ -12,7 +11,6 @@ import play.api.libs.json.{JsArray, Json}
import play.api.mvc._

class Multi(
bestsellersAgent: BestsellersAgent,
masterclassAgent: MasterclassAgent,
travelOffersAgent: TravelOffersAgent,
jobsAgent: JobsAgent,
Expand All @@ -28,16 +26,6 @@ class Multi(
val components: Seq[(String, Option[String])] = offerTypes zip offerIds

components flatMap {

case ("Book", Some(bookId)) =>
bestsellersAgent.getSpecificBooks(Seq(bookId)) match {
case Nil => bestsellersAgent.bestsellersTargetedAt(segment)
case books => books
}

case ("Book", None) =>
bestsellersAgent.bestsellersTargetedAt(segment)

case ("Job", Some(jobId)) =>
jobsAgent.specificJobs(Seq(jobId))

Expand Down
8 changes: 1 addition & 7 deletions commercial/app/model/feeds/FeedFetcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ class FeedsFetcher(wsClient: WSClient) {
}
}

private val bestsellers: Option[FeedFetcher] = {
Configuration.commercial.magento.domain map { domain =>
new SingleFeedFetcher(wsClient)(BestsellersFeedMetaData(domain))
}
}

private val masterclasses: Option[FeedFetcher] =
Configuration.commercial.masterclassesToken map (token =>
new EventbriteMultiPageFeedFetcher(wsClient)(EventsFeedMetaData("masterclasses", token)),
Expand All @@ -120,7 +114,7 @@ class FeedsFetcher(wsClient: WSClient) {
new SingleFeedFetcher(wsClient)(TravelOffersFeedMetaData(url))
}

val all: Seq[FeedFetcher] = Seq(bestsellers, masterclasses, travelOffers, jobs, liveEvents).flatten
val all: Seq[FeedFetcher] = Seq(masterclasses, travelOffers, jobs, liveEvents).flatten

}

Expand Down
8 changes: 0 additions & 8 deletions commercial/app/model/feeds/FeedMetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ case class JobsFeedMetaData(override val url: String) extends FeedMetaData {
override val responseEncoding = utf8
}

case class BestsellersFeedMetaData(domain: String) extends FeedMetaData {

val name = "bestsellers"
val url = s"https://$domain/bertrams/feed/independentsTop20"

override val responseEncoding = utf8
}

case class EventsFeedMetaData(
feedName: String,
accessToken: String,
Expand Down
17 changes: 2 additions & 15 deletions commercial/app/model/feeds/FeedParser.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package commercial.model.feeds

import commercial.model.merchandise.books.BestsellersAgent
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 All @@ -17,7 +16,6 @@ sealed trait FeedParser[+T] {
}

class FeedsParser(
bestsellersAgent: BestsellersAgent,
liveEventAgent: LiveEventAgent,
masterclassAgent: MasterclassAgent,
travelOffersAgent: TravelOffersAgent,
Expand All @@ -35,17 +33,6 @@ class FeedsParser(
}
}

private val bestsellers: Option[FeedParser[Book]] = {
Configuration.commercial.magento.domain map { domain =>
new FeedParser[Book] {

val feedMetaData = BestsellersFeedMetaData(domain)

def parse(feedContent: => Option[String]) = bestsellersAgent.refresh(feedMetaData, feedContent)
}
}
}

private val masterclasses: Option[FeedParser[Masterclass]] = {
Configuration.commercial.masterclassesToken map { accessToken =>
new FeedParser[Masterclass] {
Expand Down Expand Up @@ -79,7 +66,7 @@ class FeedsParser(
}
}

val all = Seq(jobs, bestsellers, masterclasses, liveEvents, travelOffers).flatten
val all = Seq(jobs, masterclasses, liveEvents, travelOffers).flatten
}

case class ParsedFeed[+T](contents: Seq[T], parseDuration: 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
37 changes: 0 additions & 37 deletions commercial/app/model/merchandise/books/BestsellersAgent.scala

This file was deleted.

Loading

0 comments on commit 34570a9

Please sign in to comment.