From f2b04de9f43492788469276c7aff6bcd8370c1b6 Mon Sep 17 00:00:00 2001 From: Jonas Natten Date: Tue, 10 Dec 2024 10:11:20 +0100 Subject: [PATCH] oembed-proxy: Add DTO suffix to all DTO types --- .../oembedproxy/controller/OEmbedProxyController.scala | 2 +- .../oembedproxy/model/{OEmbed.scala => OEmbedDTO.scala} | 8 ++++---- .../scala/no/ndla/oembedproxy/model/OEmbedProvider.scala | 2 +- .../ndla/oembedproxy/service/OEmbedConverterService.scala | 4 ++-- .../ndla/oembedproxy/service/OEmbedServiceComponent.scala | 8 ++++---- .../controller/OEmbedProxyControllerTest.scala | 4 ++-- .../oembedproxy/service/OEmbedConverterServiceTest.scala | 6 +++--- .../no/ndla/oembedproxy/service/OEmbedServiceTest.scala | 6 +++--- .../no/ndla/oembedproxy/service/ProviderServiceTest.scala | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) rename oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/{OEmbed.scala => OEmbedDTO.scala} (93%) diff --git a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/controller/OEmbedProxyController.scala b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/controller/OEmbedProxyController.scala index b8ff986731..f23d1fd5eb 100644 --- a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/controller/OEmbedProxyController.scala +++ b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/controller/OEmbedProxyController.scala @@ -36,7 +36,7 @@ trait OEmbedProxyController { .in(query[Option[String]]("maxwidth").description("The maximum width of the embedded resource")) .in(query[Option[String]]("maxheight").description("The maximum height of the embedded resource")) .errorOut(errorOutputsFor(400, 401, 403, 404, 410, 422, 502)) - .out(jsonBody[OEmbed]) + .out(jsonBody[OEmbedDTO]) .serverLogicPure { case (url, maxWidth, maxHeight) => oEmbedService.get(url, maxWidth, maxHeight) match { case Success(oembed) => oembed.asRight diff --git a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbed.scala b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedDTO.scala similarity index 93% rename from oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbed.scala rename to oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedDTO.scala index ca3a7084d7..410dc1809e 100644 --- a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbed.scala +++ b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedDTO.scala @@ -14,7 +14,7 @@ import sttp.tapir.Schema.annotations.description // format: off @description("oEmbed information for an url.") -case class OEmbed( +case class OEmbedDTO( @description("The resource type") `type`: String, @description("The oEmbed version number. This must be 1.0.") version: String, @description("A text title, describing the resource.") title: Option[String], @@ -34,7 +34,7 @@ case class OEmbed( ) // format: on -object OEmbed { - implicit val encoder: Encoder[OEmbed] = deriveEncoder - implicit val decoder: Decoder[OEmbed] = deriveDecoder +object OEmbedDTO { + implicit val encoder: Encoder[OEmbedDTO] = deriveEncoder + implicit val decoder: Decoder[OEmbedDTO] = deriveDecoder } diff --git a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedProvider.scala b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedProvider.scala index 977084ca5a..13959cddfe 100644 --- a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedProvider.scala +++ b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/model/OEmbedProvider.scala @@ -17,7 +17,7 @@ case class OEmbedProvider( providerUrl: String, endpoints: List[OEmbedEndpoint], urlParser: String => String = identity, - postProcessor: (String, OEmbed) => OEmbed = (_: String, o: OEmbed) => o + postProcessor: (String, OEmbedDTO) => OEmbedDTO = (_: String, o: OEmbedDTO) => o ) { def supports(url: String): Boolean = { diff --git a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedConverterService.scala b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedConverterService.scala index 5211fbcfb7..dc2c4e49ac 100644 --- a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedConverterService.scala +++ b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedConverterService.scala @@ -8,13 +8,13 @@ package no.ndla.oembedproxy.service import io.lemonlabs.uri.Url -import no.ndla.oembedproxy.model.OEmbed +import no.ndla.oembedproxy.model.OEmbedDTO import io.lemonlabs.uri.typesafe.dsl._ import org.jsoup.Jsoup object OEmbedConverterService { - def addYoutubeTimestampIfdefinedInRequest(requestUrl: String, oembed: OEmbed): OEmbed = { + def addYoutubeTimestampIfdefinedInRequest(requestUrl: String, oembed: OEmbedDTO): OEmbedDTO = { val paramTypesToTransfer = List("start", "time_continue", "t", "end", "rel") val queryParamsToTransfer = requestUrl.query.filterNames(pn => paramTypesToTransfer.contains(pn)).params diff --git a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedServiceComponent.scala b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedServiceComponent.scala index 744fc36633..c3e5a31447 100644 --- a/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedServiceComponent.scala +++ b/oembed-proxy/src/main/scala/no/ndla/oembedproxy/service/OEmbedServiceComponent.scala @@ -11,7 +11,7 @@ package no.ndla.oembedproxy.service import com.typesafe.scalalogging.StrictLogging import no.ndla.network.NdlaClient import no.ndla.network.model.HttpRequestException -import no.ndla.oembedproxy.model.{InvalidUrlException, OEmbed, OEmbedProvider, ProviderNotSupportedException} +import no.ndla.oembedproxy.model.{InvalidUrlException, OEmbedDTO, OEmbedProvider, ProviderNotSupportedException} import org.log4s.MDC import sttp.client3.quick.* import sttp.model.HttpVersion @@ -41,9 +41,9 @@ trait OEmbedServiceComponent { maxWidth: Option[String], maxHeight: Option[String], retryCount: Int - ): Try[OEmbed] = { + ): Try[OEmbedDTO] = { val uri = uri"${provider.requestUrl(url, maxWidth, maxHeight)}" - ndlaClient.fetch[OEmbed]( + ndlaClient.fetch[OEmbedDTO]( quickRequest .get(uri) .followRedirects(true) @@ -68,7 +68,7 @@ trait OEmbedServiceComponent { } } - def get(url: String, maxWidth: Option[String], maxHeight: Option[String]): Try[OEmbed] = { + def get(url: String, maxWidth: Option[String], maxHeight: Option[String]): Try[OEmbedDTO] = { io.lemonlabs.uri.Uri.parseTry(url) match { case Failure(_) => Failure(InvalidUrlException(s"$url does not seem to be a valid url.")) case Success(_) => diff --git a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/controller/OEmbedProxyControllerTest.scala b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/controller/OEmbedProxyControllerTest.scala index 7bc6029d5a..0599e2f72d 100644 --- a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/controller/OEmbedProxyControllerTest.scala +++ b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/controller/OEmbedProxyControllerTest.scala @@ -9,7 +9,7 @@ package no.ndla.oembedproxy.controller import no.ndla.network.model.HttpRequestException -import no.ndla.oembedproxy.model.OEmbed +import no.ndla.oembedproxy.model.OEmbedDTO import no.ndla.oembedproxy.{TestEnvironment, UnitSuite} import no.ndla.tapirtesting.TapirControllerTest import org.mockito.ArgumentMatchers.{any, anyString} @@ -23,7 +23,7 @@ import scala.util.{Failure, Success} class OEmbedProxyControllerTest extends UnitSuite with TestEnvironment with TapirControllerTest { val controller: OEmbedProxyController = new OEmbedProxyController - val oembed: OEmbed = OEmbed( + val oembed: OEmbedDTO = OEmbedDTO( `type` = "rich", version = "1.0", title = Some("Title"), diff --git a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedConverterServiceTest.scala b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedConverterServiceTest.scala index 207d790fff..f23886f5fb 100644 --- a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedConverterServiceTest.scala +++ b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedConverterServiceTest.scala @@ -7,7 +7,7 @@ package no.ndla.oembedproxy.service -import no.ndla.oembedproxy.model.OEmbed +import no.ndla.oembedproxy.model.OEmbedDTO import no.ndla.oembedproxy.{TestEnvironment, UnitSuite} class OEmbedConverterServiceTest extends UnitSuite with TestEnvironment { @@ -22,7 +22,7 @@ class OEmbedConverterServiceTest extends UnitSuite with TestEnvironment { "https://www.youtube.com/watch?start=43&end=58&v=vZCsuV7Rb_w" val requestUrlWithtoutTimestamp = "https://www.youtube.com/watch?v=vZCsuV7Rb_w" - val oembed = OEmbed( + val oembed = OEmbedDTO( "video", "1.0", Some("ESSĀ® expandable sand screen"), @@ -75,7 +75,7 @@ class OEmbedConverterServiceTest extends UnitSuite with TestEnvironment { test("That rel=0 also is added to youtube url if defined in request") { val requestUrl = "https://www.youtube.com/watch?v=vZCsuV7Rb_w&rel=0&time_continue=5&meh=1" - val oembed = OEmbed( + val oembed = OEmbedDTO( "video", "1.0", Some("ESSĀ® expandable sand screen"), diff --git a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedServiceTest.scala b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedServiceTest.scala index f587e4118c..bc471d5feb 100644 --- a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedServiceTest.scala +++ b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/OEmbedServiceTest.scala @@ -40,7 +40,7 @@ class OEmbedServiceTest extends UnitSuite with TestEnvironment { ) ) - val OEmbedResponse: OEmbed = OEmbed( + val OEmbedResponse: OEmbedDTO = OEmbedDTO( "rich", "1.0", Some("A Confectioner in the UK"), @@ -73,7 +73,7 @@ class OEmbedServiceTest extends UnitSuite with TestEnvironment { } test("That get returns a failure with HttpRequestException when receiving http error") { - when(ndlaClient.fetch[OEmbed](any[NdlaRequest])(any)) + when(ndlaClient.fetch[OEmbedDTO](any[NdlaRequest])(any)) .thenReturn(Failure(new HttpRequestException("An error occured"))) val oembedTry = oEmbedService.get("https://www.youtube.com/abc", None, None) oembedTry.isFailure should be(true) @@ -81,7 +81,7 @@ class OEmbedServiceTest extends UnitSuite with TestEnvironment { } test("That get returns a Success with an oEmbed when http call is successful") { - when(ndlaClient.fetch[OEmbed](any[NdlaRequest])(any)) + when(ndlaClient.fetch[OEmbedDTO](any[NdlaRequest])(any)) .thenReturn(Success(OEmbedResponse)) val oembedTry = oEmbedService.get("https://ndla.no/abc", None, None) oembedTry.isSuccess should be(true) diff --git a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/ProviderServiceTest.scala b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/ProviderServiceTest.scala index b8b77a7654..0b1059d257 100644 --- a/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/ProviderServiceTest.scala +++ b/oembed-proxy/src/test/scala/no/ndla/oembedproxy/service/ProviderServiceTest.scala @@ -43,7 +43,7 @@ class ProviderServiceTest extends UnitSuite with TestEnvironment { test("That loadProvidersFromRequest fails on invalid url/bad response") { val invalidUrl = "invalidUrl123" - when(ndlaClient.fetch[OEmbed](any[NdlaRequest])(any)) + when(ndlaClient.fetch[OEmbedDTO](any[NdlaRequest])(any)) .thenReturn(Failure(new HttpRequestException("An error occured"))) intercept[DoNotUpdateMemoizeException] { providerService.loadProvidersFromRequest(quickRequest.get(uri"$invalidUrl"))