From 54ac86a043212bba5b89e9991f2f75485bda4502 Mon Sep 17 00:00:00 2001 From: Jonas Natten Date: Thu, 5 Dec 2024 12:42:57 +0100 Subject: [PATCH] search-api: Rename `Title` to `HtmlTitle` to avoid conflict A little bit more descriptive to avoid conflict with a regular title object. --- .../searchapi/model/api/ArticleResult.scala | 2 +- .../searchapi/model/api/AudioResult.scala | 2 +- .../searchapi/model/api/ImageResult.scala | 2 +- .../model/api/LearningpathResult.scala | 2 +- .../model/api/MultiSearchSummary.scala | 2 +- .../no/ndla/searchapi/model/api/Title.scala | 1 - .../searchapi/model/api/TitleWithHtml.scala | 28 ++++++++++++++++ .../model/api/article/ArticleSummary.scala | 25 --------------- .../model/api/draft/DraftSummary.scala | 28 ---------------- .../learningpath/LearningPathSummary.scala | 32 ------------------- .../searchapi/service/ConverterService.scala | 8 ++--- .../search/SearchConverterService.scala | 20 ++++++------ 12 files changed, 48 insertions(+), 104 deletions(-) create mode 100644 search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala delete mode 100644 search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleSummary.scala delete mode 100644 search-api/src/main/scala/no/ndla/searchapi/model/api/draft/DraftSummary.scala delete mode 100644 search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathSummary.scala diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResult.scala index 4d0a806392..116f4ae85a 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResult.scala @@ -13,7 +13,7 @@ import sttp.tapir.Schema.annotations.description @description("Search result for article api") case class ArticleResult( @description("The unique id of this article") id: Long, - @description("The title of the article") title: Title, + @description("The title of the article") title: TitleWithHtml, @description("The introduction of the article") introduction: Option[ArticleIntroduction], @description("The type of the article") articleType: String, @description("List of supported languages") supportedLanguages: Seq[String] diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResult.scala index c77e92c4ea..9813a0cd54 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResult.scala @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description @description("Search result for audio api") case class AudioResult( @description("The unique id of this audio") id: Long, - @description("The title of this audio") title: Title, + @description("The title of this audio") title: TitleWithHtml, @description("A direct link to the audio") url: String, @description("List of supported languages") supportedLanguages: Seq[String] ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResult.scala index 35a9f35afb..88e3703f38 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResult.scala @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description @description("Search result for image api") case class ImageResult( @description("The unique id of this image") id: Long, - @description("The title of this image") title: Title, + @description("The title of this image") title: TitleWithHtml, @description("The alt text of this image") altText: ImageAltText, @description("A direct link to the image") previewUrl: String, @description("A link to get meta data related to the image") metaUrl: String, diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResult.scala index 40ee90d373..8d672746ee 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResult.scala @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description @description("Search result for learningpath api") case class LearningpathResult( @description("The unique id of this learningpath") id: Long, - @description("The title of the learningpath") title: Title, + @description("The title of the learningpath") title: TitleWithHtml, @description("The introduction of the learningpath") introduction: LearningPathIntroduction, @description("List of supported languages") supportedLanguages: Seq[String] ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummary.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummary.scala index 338ae239ae..a9a095e7a0 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummary.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummary.scala @@ -30,7 +30,7 @@ object HighlightedField { @description("Short summary of information about the resource") case class MultiSearchSummary( @description("The unique id of the resource") id: Long, - @description("The title of the resource") title: Title, + @description("The title of the resource") title: TitleWithHtml, @description("The meta description of the resource") metaDescription: MetaDescription, @description("The meta image for the resource") metaImage: Option[MetaImage], @description("Url pointing to the resource") url: String, diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/Title.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/Title.scala index c68f843208..3da3b056c7 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/Title.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/Title.scala @@ -15,7 +15,6 @@ import sttp.tapir.Schema.annotations.description @description("Title of resource") case class Title( @description("The freetext title of the resource") title: String, - @description("The freetext html-version title of the article") htmlTitle: String, @description("ISO 639-1 code that represents the language used in title") language: String ) extends LanguageField[String] { override def value: String = title diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala new file mode 100644 index 0000000000..e9a310babf --- /dev/null +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala @@ -0,0 +1,28 @@ +/* + * Part of NDLA search-api + * Copyright (C) 2018 NDLA + * + * See LICENSE + */ + +package no.ndla.searchapi.model.api + +import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} +import io.circe.{Decoder, Encoder} +import no.ndla.language.model.LanguageField +import sttp.tapir.Schema.annotations.description + +@description("Title of resource") +case class TitleWithHtml( + @description("The freetext title of the resource") title: String, + @description("The freetext html-version title of the article") htmlTitle: String, + @description("ISO 639-1 code that represents the language used in title") language: String +) extends LanguageField[String] { + override def value: String = title + override def isEmpty: Boolean = title.isEmpty +} + +object TitleWithHtml { + implicit val encoder: Encoder[TitleWithHtml] = deriveEncoder + implicit val decoder: Decoder[TitleWithHtml] = deriveDecoder +} diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleSummary.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleSummary.scala deleted file mode 100644 index a38c247392..0000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleSummary.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2018 NDLA - * - * See LICENSE - */ - -package no.ndla.searchapi.model.api.article - -import no.ndla.searchapi.model.api.{MetaDescription, Title} -import sttp.tapir.Schema.annotations.description - -@description("Short summary of information about the article") -case class ArticleSummary( - @description("The unique id of the article") id: Long, - @description("The title of the article") title: Title, - @description("A visual element article") visualElement: Option[VisualElement], - @description("An introduction for the article") introduction: Option[ArticleIntroduction], - @description("A metaDescription for the article") metaDescription: Option[MetaDescription], - @description("A meta image for the article") metaImage: Option[ArticleMetaImage], - @description("The full url to where the complete information about the article can be found") url: String, - @description("Describes the license of the article") license: String, - @description("The type of article this is. Possible values are topic-article,standard") articleType: String, - @description("A list of available languages for this article") supportedLanguages: Seq[String] -) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/draft/DraftSummary.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/draft/DraftSummary.scala deleted file mode 100644 index 172d1e61a6..0000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/draft/DraftSummary.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2018 NDLA - * - * See LICENSE - */ - -package no.ndla.searchapi.model.api.draft - -import no.ndla.common.model.api.draft.Comment -import no.ndla.searchapi.model.api.Title -import no.ndla.searchapi.model.api.article.{ArticleIntroduction, VisualElement} -import sttp.tapir.Schema.annotations.description - -// format: off -@description("Short summary of information about the article") -case class DraftSummary( - @description("The unique id of the article") id: Long, - @description("The title of the article") title: Title, - @description("A visual element article") visualElement: Option[VisualElement], - @description("An introduction for the article") introduction: Option[ArticleIntroduction], - @description("The full url to where the complete information about the article can be found") url: String, - @description("Describes the license of the article") license: String, - @description("The type of article this is. Possible values are topic-article,standard") articleType: String, - @description("A list of available languages for this audio") supportedLanguages: Seq[String], - @description("The notes for this draft article") notes: Seq[String], - @description("Information about comments attached to the article") comments: Seq[Comment] -) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathSummary.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathSummary.scala deleted file mode 100644 index c1b9caca3c..0000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathSummary.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2018 NDLA - * - * See LICENSE - */ - -package no.ndla.searchapi.model.api.learningpath - -import no.ndla.searchapi.model.api.Title -import sttp.tapir.Schema.annotations.description - -import java.time.LocalDateTime - -@description("Summary of meta information for a learningpath") -case class LearningPathSummary( - @description("The unique id of the learningpath") id: Long, - @description("The titles of the learningpath") title: Title, - @description("The descriptions of the learningpath") description: Description, - @description("The introductions of the learningpath") introduction: Introduction, - @description( - "The full url to where the complete metainformation about the learningpath can be found" - ) metaUrl: String, - @description("Url to where a cover photo can be found") coverPhotoUrl: Option[String], - @description("The duration of the learningpath in minutes") duration: Option[Int], - @description("The publishing status of the learningpath.") status: String, - @description("The date when this learningpath was last updated.") lastUpdated: LocalDateTime, - @description("Searchable tags for the learningpath") tags: LearningPathTags, - @description("The contributors of this learningpath") copyright: Copyright, - @description("A list of available languages for this audio") supportedLanguages: Seq[String], - @description("The id this learningpath is based on, if any") isBasedOn: Option[Long] -) diff --git a/search-api/src/main/scala/no/ndla/searchapi/service/ConverterService.scala b/search-api/src/main/scala/no/ndla/searchapi/service/ConverterService.scala index 893be3c1b1..eb6bead073 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/service/ConverterService.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/service/ConverterService.scala @@ -45,7 +45,7 @@ trait ConverterService { private def articleSearchResultToApi(article: ArticleApiSearchResult): api.ArticleResult = { api.ArticleResult( article.id, - api.Title(article.title.title, article.title.htmlTitle, article.title.language), + api.TitleWithHtml(article.title.title, article.title.htmlTitle, article.title.language), article.introduction.map(i => ArticleIntroduction(i.introduction, i.htmlIntroduction, i.language)), article.articleType, article.supportedLanguages @@ -66,7 +66,7 @@ trait ConverterService { private def learningpathSearchResultToApi(learningpath: LearningpathApiSearchResult): api.LearningpathResult = { api.LearningpathResult( learningpath.id, - api.Title(learningpath.title.title, learningpath.title.title, learningpath.title.language), + api.TitleWithHtml(learningpath.title.title, learningpath.title.title, learningpath.title.language), LearningPathIntroduction(learningpath.introduction.introduction, learningpath.introduction.language), learningpath.supportedLanguages ) @@ -92,7 +92,7 @@ trait ConverterService { api.ImageResult( image.id.toLong, - api.Title(image.title.title, image.title.title, image.title.language), + api.TitleWithHtml(image.title.title, image.title.title, image.title.language), api.ImageAltText(image.altText.alttext, image.altText.language), previewUrl.toString, metaUrl.toString, @@ -118,7 +118,7 @@ trait ConverterService { val url = audio.url.withHost(host).withScheme(scheme).toString api.AudioResult( audio.id, - api.Title(audio.title.title, audio.title.title, audio.title.language), + api.TitleWithHtml(audio.title.title, audio.title.title, audio.title.language), url, audio.supportedLanguages ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchConverterService.scala b/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchConverterService.scala index 924c71598c..e4a6bffaef 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchConverterService.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchConverterService.scala @@ -591,7 +591,7 @@ trait SearchConverterService { val contexts = filterContexts(searchableArticle.contexts, language, filterInactive) val titles = searchableArticle.domainObject.title.map(title => - api.Title(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) + api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) ) val introductions = searchableArticle.domainObject.introduction.map(intro => api.article @@ -611,7 +611,7 @@ trait SearchConverterService { }) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( api.MetaDescription("", UnknownLanguage.toString) ) @@ -657,7 +657,7 @@ trait SearchConverterService { val contexts = filterContexts(searchableDraft.contexts, language, filterInactive) val titles = searchableDraft.domainObject.title.map(title => - api.Title(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) + api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) ) val introductions = searchableDraft.domainObject.introduction.map(intro => api.article @@ -677,7 +677,7 @@ trait SearchConverterService { }) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( api.MetaDescription("", UnknownLanguage.toString) ) @@ -731,7 +731,8 @@ trait SearchConverterService { val searchableLearningPath = CirceUtil.unsafeParseAs[SearchableLearningPath](hit.sourceAsString) val contexts = filterContexts(searchableLearningPath.contexts, language, filterInactive) - val titles = searchableLearningPath.title.languageValues.map(lv => api.Title(lv.value, lv.value, lv.language)) + val titles = + searchableLearningPath.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language)) val metaDescriptions = searchableLearningPath.description.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) val tags = @@ -740,7 +741,7 @@ trait SearchConverterService { val supportedLanguages = getSupportedLanguages(titles, metaDescriptions, tags) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( api.MetaDescription("", UnknownLanguage.toString) ) @@ -788,15 +789,16 @@ trait SearchConverterService { def conceptHitAsMultiSummary(hit: SearchHit, language: String): MultiSearchSummary = { val searchableConcept = CirceUtil.unsafeParseAs[SearchableConcept](hit.sourceAsString) - val titles = searchableConcept.title.languageValues.map(lv => api.Title(lv.value, lv.value, lv.language)) + val titles = searchableConcept.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language)) val content = searchableConcept.content.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) val tags = searchableConcept.tags.languageValues.map(lv => Tag(lv.value, lv.language)) val supportedLanguages = getSupportedLanguages(titles, content, tags) - val title = findByLanguageOrBestEffort(titles, language).getOrElse(api.Title("", "", UnknownLanguage.toString)) - val url = s"${props.ExternalApiUrls("concept-api")}/${searchableConcept.id}" + val title = + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) + val url = s"${props.ExternalApiUrls("concept-api")}/${searchableConcept.id}" val metaImages = searchableConcept.domainObject.metaImage.map(image => { val metaImageUrl = s"${props.ExternalApiUrls("raw-image")}/${image.imageId}" api.MetaImage(metaImageUrl, image.altText, image.language)