diff --git a/project/searchapi.scala b/project/searchapi.scala index 249b3f5ba..5191b2582 100644 --- a/project/searchapi.scala +++ b/project/searchapi.scala @@ -27,24 +27,23 @@ object searchapi extends Module { "no.ndla.searchapi.controller.parameters._" ), exports = Seq( - "ApiTaxonomyContext", - "ArticleResult", - "AudioResult", - "GroupSearchResult", - "ImageResult", - "LearningpathResult", - "MultiSearchResult", - "ArticleResults", - "AudioResults", - "ImageResults", - "LearningpathResults", - "SearchError", - "SearchParams", - "DraftSearchParams", - "SubjectAggregations", - "SubjectAggsInput", - "GrepSearchInput", - "grep.GrepSearchResults" + "ApiTaxonomyContextDTO", + "ArticleResultDTO", + "AudioResultDTO", + "GroupSearchResultDTO", + "ImageResultDTO", + "LearningpathResultDTO", + "MultiSearchResultDTO", + "ArticleResultsDTO", + "AudioResultsDTO", + "ImageResultsDTO", + "LearningpathResultsDTO", + "SearchParamsDTO", + "DraftSearchParamsDTO", + "SubjectAggregationsDTO", + "SubjectAggsInputDTO", + "GrepSearchInputDTO", + "grep.GrepSearchResultsDTO" ) ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/SearchController.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/SearchController.scala index d9d0937e1..ba813b0b7 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/controller/SearchController.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/controller/SearchController.scala @@ -21,11 +21,16 @@ import no.ndla.network.tapir.Parameters.feideHeader import no.ndla.network.tapir.{AllErrors, DynamicHeaders, NonEmptyString, TapirController} import no.ndla.network.tapir.TapirUtil.errorOutputsFor import no.ndla.network.tapir.auth.Permission.DRAFT_API_WRITE -import no.ndla.searchapi.controller.parameters.{DraftSearchParams, GrepSearchInput, SearchParams, SubjectAggsInput} +import no.ndla.searchapi.controller.parameters.{ + DraftSearchParamsDTO, + GrepSearchInputDTO, + SearchParamsDTO, + SubjectAggsInputDTO +} import no.ndla.searchapi.Props import no.ndla.searchapi.integration.SearchApiClient -import no.ndla.searchapi.model.api.grep.GrepSearchResults -import no.ndla.searchapi.model.api.{ErrorHandling, GroupSearchResult, MultiSearchResult, SubjectAggregations} +import no.ndla.searchapi.model.api.grep.GrepSearchResultsDTO +import no.ndla.searchapi.model.api.{ErrorHandling, GroupSearchResultDTO, MultiSearchResultDTO, SubjectAggregationsDTO} import no.ndla.searchapi.model.domain.{LearningResourceType, Sort} import no.ndla.searchapi.model.search.SearchType import no.ndla.searchapi.model.search.settings.{MultiDraftSearchSettings, SearchSettings} @@ -169,8 +174,8 @@ trait SearchController { .summary("List subjects with aggregated data about their contents") .description("List subjects with aggregated data about their contents") .in("subjects") - .in(jsonBody[SubjectAggsInput]) - .out(jsonBody[SubjectAggregations]) + .in(jsonBody[SubjectAggsInputDTO]) + .out(jsonBody[SubjectAggregationsDTO]) .errorOut(errorOutputsFor(400, 401, 403)) .requirePermission(DRAFT_API_WRITE) .serverLogicPure { _ => input => @@ -202,7 +207,7 @@ trait SearchController { .in(embedId) .in(filterInactive) .in(feideHeader) - .out(jsonBody[Seq[GroupSearchResult]]) + .out(jsonBody[Seq[GroupSearchResultDTO]]) .errorOut(errorOutputsFor(401, 403)) .serverLogicPure { case ( @@ -263,7 +268,7 @@ trait SearchController { } } - private def searchInGroup(group: String, settings: SearchSettings): Try[GroupSearchResult] = { + private def searchInGroup(group: String, settings: SearchSettings): Try[GroupSearchResultDTO] = { multiSearchService .matchingQuery(settings) .map(res => searchConverterService.toApiGroupMultiSearchResult(group, res)) @@ -275,7 +280,7 @@ trait SearchController { private def groupSearch( settings: SearchSettings, includeMissingResourceTypeGroup: Boolean - ): Either[AllErrors, Seq[GroupSearchResult]] = { + ): Either[AllErrors, Seq[GroupSearchResultDTO]] = { val numMissingRtThreads = if (includeMissingResourceTypeGroup) 1 else 0 val numGroups = settings.resourceTypes.size + settings.learningResourceTypes.size + numMissingRtThreads if (numGroups >= 1) { @@ -342,8 +347,8 @@ trait SearchController { * A Try with scroll result, or the return of the orFunction (Usually a try with a search result). */ private def scrollWithOr[T <: SearchService](scrollId: Option[String], language: String, scroller: T)( - orFunction: => Try[(MultiSearchResult, DynamicHeaders)] - ): Try[(MultiSearchResult, DynamicHeaders)] = { + orFunction: => Try[(MultiSearchResultDTO, DynamicHeaders)] + ): Try[(MultiSearchResultDTO, DynamicHeaders)] = { scrollId match { case Some(scroll) if !InitialScrollContextKeywords.contains(scroll) => for { @@ -359,7 +364,7 @@ trait SearchController { .summary("Find learning resources") .description("Shows all learning resources. You can search too.") .errorOut(errorOutputsFor(400, 401, 403)) - .out(jsonBody[MultiSearchResult]) + .out(jsonBody[MultiSearchResultDTO]) .out(EndpointOutput.derived[DynamicHeaders]) .in(pageNo) .in(pageSize) @@ -452,9 +457,9 @@ trait SearchController { .summary("Find learning resources") .description("Shows all learning resources. You can search too.") .errorOut(errorOutputsFor(400)) - .out(jsonBody[MultiSearchResult]) + .out(jsonBody[MultiSearchResultDTO]) .out(EndpointOutput.derived[DynamicHeaders]) - .in(jsonBody[Option[SearchParams]].schema(SearchParams.schema.asOption)) + .in(jsonBody[Option[SearchParamsDTO]].schema(SearchParamsDTO.schema.asOption)) .in(feideHeader) .serverLogicPure { case (searchParams, feideToken) => getAvailability(feideToken) @@ -520,14 +525,14 @@ trait SearchController { .in("editorial") .in(queryParams) .errorOut(errorOutputsFor(400, 401, 403)) - .out(jsonBody[MultiSearchResult]) + .out(jsonBody[MultiSearchResultDTO]) .out(EndpointOutput.derived[DynamicHeaders]) .requirePermission(DRAFT_API_WRITE) .serverLogicPure { _ => { implicit queryParams => val searchParams = Some( - DraftSearchParams( + DraftSearchParamsDTO( page = intParamOrNone("page"), pageSize = intParamOrNone("page-size"), articleTypes = stringListParam("article-types").some, @@ -580,9 +585,9 @@ trait SearchController { .summary("Find draft learning resources") .description("Shows all draft learning resources. You can search too.") .in("editorial") - .in(jsonBody[Option[DraftSearchParams]].schema(DraftSearchParams.schema.asOption)) + .in(jsonBody[Option[DraftSearchParamsDTO]].schema(DraftSearchParamsDTO.schema.asOption)) .errorOut(errorOutputsFor(400, 401, 403)) - .out(jsonBody[MultiSearchResult]) + .out(jsonBody[MultiSearchResultDTO]) .out(EndpointOutput.derived[DynamicHeaders]) .requirePermission(DRAFT_API_WRITE) .serverLogicPure { _ => searchParams => @@ -600,8 +605,8 @@ trait SearchController { .summary("Search for grep codes") .description("Search for grep codes") .in("grep") - .in(jsonBody[GrepSearchInput]) - .out(jsonBody[GrepSearchResults]) + .in(jsonBody[GrepSearchInputDTO]) + .out(jsonBody[GrepSearchResultsDTO]) .errorOut(errorOutputsFor(400, 401, 403)) .requirePermission(DRAFT_API_WRITE) .serverLogicPure { _ => input => grepSearchService.searchGreps(input) } @@ -628,7 +633,7 @@ trait SearchController { } } - def asSettings(p: Option[SearchParams], availability: List[Availability]): SearchSettings = { + def asSettings(p: Option[SearchParamsDTO], availability: List[Availability]): SearchSettings = { p match { case None => SearchSettings.default case Some(params) => @@ -662,7 +667,7 @@ trait SearchController { } - def asDraftSettings(p: Option[DraftSearchParams]): MultiDraftSearchSettings = { + def asDraftSettings(p: Option[DraftSearchParamsDTO]): MultiDraftSearchSettings = { p match { case None => MultiDraftSearchSettings.default case Some(params) => diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParams.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParams.scala deleted file mode 100644 index 57b300f26..000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParams.scala +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2024 NDLA - * - * See LICENSE - */ - -package no.ndla.searchapi.controller.parameters - -import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} -import io.circe.{Decoder, Encoder} -import no.ndla.common.model.NDLADate -import no.ndla.network.tapir.NonEmptyString -import no.ndla.searchapi.model.domain.Sort -import no.ndla.searchapi.model.search.SearchType -import sttp.tapir.Schema -import sttp.tapir.Schema.annotations.description - - // format: off - case class DraftSearchParams( - @description("The page number of the search hits to display.") - page: Option[Int], - - @description(s"The number of search hits to display for each page.") - pageSize: Option[Int], - - @description("A list of article-types the search should be filtered by.") - articleTypes: Option[List[String]], - - @description("A list of context-types the learning resources should be filtered by.") - contextTypes: Option[List[String]], - - @description("The ISO 639-1 language code describing language.") - language: Option[String], - - @description("Return only learning resources that have one of the provided ids.") - ids: Option[List[Long]], - - @description("Return only learning resources of specific type(s).") - resourceTypes: Option[List[String]], - - @description("Return only results with provided license.") - license: Option[String], - - @description("Return only results with content matching the specified query.") - query: Option[NonEmptyString], - - @description("Return only results with notes matching the specified note-query.") - noteQuery: Option[NonEmptyString], - - @description("The sorting used on results.") - sort: Option[Sort], - - @description("Fallback to existing language if language is specified.") - fallback: Option[Boolean], - - @description("A comma separated list of subjects the learning resources should be filtered by.") - subjects: Option[List[String]], - - @description("A list of ISO 639-1 language codes that the learning resource can be available in.") - languageFilter: Option[List[String]], - - @description( - """A list of relevances the learning resources should be filtered by. - |If subjects are specified the learning resource must have specified relevances in relation to a specified subject. - |If levels are specified the learning resource must have specified relevances in relation to a specified level.""".stripMargin) - relevance: Option[List[String]], - - - @description( - s"""A unique string obtained from a search you want to keep scrolling in. To obtain one from a search, provide one of the following values: ["0", "initial", "start", "first"]. - |When scrolling, the parameters from the initial search is used, except in the case of 'language' and 'fallback'. - |This value may change between scrolls. Always use the one in the latest scroll result. - |""".stripMargin) - scrollId: Option[String], - - @description("List of statuses to filter by. A draft only needs to have one of the available statuses to be included in result (OR).") - draftStatus: Option[List[String]], - - @description( - s"""List of users to filter by. - |The value to search for is the user-id from Auth0. - |UpdatedBy on article and user in editorial-notes are searched.""".stripMargin) - users: Option[List[String]], - - @description("A list of codes from GREP API the resources should be filtered by.") - grepCodes: Option[List[String]], - - @description("List of index-paths that should be term-aggregated and returned in result.") - aggregatePaths: Option[List[String]], - - @description("Return only results with embed data-resource the specified resource. Can specify multiple with a comma separated list to filter for one of the embed types.") - embedResource: Option[List[String]], - - @description("Return only results with embed data-resource_id, data-videoid or data-url with the specified id.") - embedId: Option[String], - - @description("Whether or not to include the 'other' status field when filtering with 'status' param.") - includeOtherStatuses: Option[Boolean], - - @description("Return only results having next revision after this date.") - revisionDateFrom: Option[NDLADate], - - @description("Return only results having next revision before this date.") - revisionDateTo: Option[NDLADate], - - @description("Set to true to avoid including hits from the revision history log.") - excludeRevisionLog: Option[Boolean], - - @description("List of responsible ids to filter by (OR filter).") - responsibleIds: Option[List[String]], - - @description("Filter out inactive taxonomy contexts.") - filterInactive: Option[Boolean], - - @description("Set to true to only return prioritized articles") - prioritized: Option[Boolean], - - @description("List of priority-levels to filter by.") - priority: Option[List[String]], - - @description("A list of parent topics the learning resources should be filtered by.") - topics: Option[List[String]], - - @description("Return only results having published date after this date.") - publishedDateFrom: Option[NDLADate], - - @description("Return only results having published date before this date.") - publishedDateTo: Option[NDLADate], - - @description("Types of hits to appear in the result") - resultTypes: Option[List[SearchType]] - ) -// format: on - -object DraftSearchParams { - implicit val encoder: Encoder[DraftSearchParams] = deriveEncoder - implicit val decoder: Decoder[DraftSearchParams] = deriveDecoder - implicit val schema: Schema[DraftSearchParams] = Schema.derived[DraftSearchParams] -} diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParamsDTO.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParamsDTO.scala new file mode 100644 index 000000000..ced0e87ab --- /dev/null +++ b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/DraftSearchParamsDTO.scala @@ -0,0 +1,109 @@ +/* + * Part of NDLA search-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + */ + +package no.ndla.searchapi.controller.parameters + +import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} +import io.circe.{Decoder, Encoder} +import no.ndla.common.model.NDLADate +import no.ndla.network.tapir.NonEmptyString +import no.ndla.searchapi.model.domain.Sort +import no.ndla.searchapi.model.search.SearchType +import sttp.tapir.Schema +import sttp.tapir.Schema.annotations.description + +case class DraftSearchParamsDTO( + @description("The page number of the search hits to display.") + page: Option[Int], + @description(s"The number of search hits to display for each page.") + pageSize: Option[Int], + @description("A list of article-types the search should be filtered by.") + articleTypes: Option[List[String]], + @description("A list of context-types the learning resources should be filtered by.") + contextTypes: Option[List[String]], + @description("The ISO 639-1 language code describing language.") + language: Option[String], + @description("Return only learning resources that have one of the provided ids.") + ids: Option[List[Long]], + @description("Return only learning resources of specific type(s).") + resourceTypes: Option[List[String]], + @description("Return only results with provided license.") + license: Option[String], + @description("Return only results with content matching the specified query.") + query: Option[NonEmptyString], + @description("Return only results with notes matching the specified note-query.") + noteQuery: Option[NonEmptyString], + @description("The sorting used on results.") + sort: Option[Sort], + @description("Fallback to existing language if language is specified.") + fallback: Option[Boolean], + @description("A comma separated list of subjects the learning resources should be filtered by.") + subjects: Option[List[String]], + @description("A list of ISO 639-1 language codes that the learning resource can be available in.") + languageFilter: Option[List[String]], + @description( + """A list of relevances the learning resources should be filtered by. + |If subjects are specified the learning resource must have specified relevances in relation to a specified subject. + |If levels are specified the learning resource must have specified relevances in relation to a specified level.""".stripMargin + ) + relevance: Option[List[String]], + @description( + s"""A unique string obtained from a search you want to keep scrolling in. To obtain one from a search, provide one of the following values: ["0", "initial", "start", "first"]. + |When scrolling, the parameters from the initial search is used, except in the case of 'language' and 'fallback'. + |This value may change between scrolls. Always use the one in the latest scroll result. + |""".stripMargin + ) + scrollId: Option[String], + @description( + "List of statuses to filter by. A draft only needs to have one of the available statuses to be included in result (OR)." + ) + draftStatus: Option[List[String]], + @description(s"""List of users to filter by. + |The value to search for is the user-id from Auth0. + |UpdatedBy on article and user in editorial-notes are searched.""".stripMargin) + users: Option[List[String]], + @description("A list of codes from GREP API the resources should be filtered by.") + grepCodes: Option[List[String]], + @description("List of index-paths that should be term-aggregated and returned in result.") + aggregatePaths: Option[List[String]], + @description( + "Return only results with embed data-resource the specified resource. Can specify multiple with a comma separated list to filter for one of the embed types." + ) + embedResource: Option[List[String]], + @description("Return only results with embed data-resource_id, data-videoid or data-url with the specified id.") + embedId: Option[String], + @description("Whether or not to include the 'other' status field when filtering with 'status' param.") + includeOtherStatuses: Option[Boolean], + @description("Return only results having next revision after this date.") + revisionDateFrom: Option[NDLADate], + @description("Return only results having next revision before this date.") + revisionDateTo: Option[NDLADate], + @description("Set to true to avoid including hits from the revision history log.") + excludeRevisionLog: Option[Boolean], + @description("List of responsible ids to filter by (OR filter).") + responsibleIds: Option[List[String]], + @description("Filter out inactive taxonomy contexts.") + filterInactive: Option[Boolean], + @description("Set to true to only return prioritized articles") + prioritized: Option[Boolean], + @description("List of priority-levels to filter by.") + priority: Option[List[String]], + @description("A list of parent topics the learning resources should be filtered by.") + topics: Option[List[String]], + @description("Return only results having published date after this date.") + publishedDateFrom: Option[NDLADate], + @description("Return only results having published date before this date.") + publishedDateTo: Option[NDLADate], + @description("Types of hits to appear in the result") + resultTypes: Option[List[SearchType]] +) + +object DraftSearchParamsDTO { + implicit val encoder: Encoder[DraftSearchParamsDTO] = deriveEncoder + implicit val decoder: Decoder[DraftSearchParamsDTO] = deriveDecoder + implicit val schema: Schema[DraftSearchParamsDTO] = Schema.derived[DraftSearchParamsDTO] +} diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInput.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInputDTO.scala similarity index 79% rename from search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInput.scala rename to search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInputDTO.scala index fae25ad11..a3f46f89c 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInput.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/GrepSearchInputDTO.scala @@ -11,35 +11,28 @@ package no.ndla.searchapi.controller.parameters import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} import no.ndla.network.tapir.NonEmptyString -import no.ndla.searchapi.model.api.grep.GrepSort +import no.ndla.searchapi.model.api.grep.GrepSortDTO import sttp.tapir.Schema.annotations.description -// format: off @description("Input parameters to subject aggregations endpoint") -case class GrepSearchInput( +case class GrepSearchInputDTO( @description("A comma separated list of prefixes that should be returned in the search.") prefixFilter: Option[List[String]], - @description("A comma separated list of codes that should be returned in the search.") codes: Option[List[String]], - @description("A query to filter the query by.") query: Option[NonEmptyString], - @description("The page number of the search hits to display.") page: Option[Int], - @description(s"The number of search hits to display for each page.") pageSize: Option[Int], - @description("The sort order of the search hits.") - sort: Option[GrepSort], - + sort: Option[GrepSortDTO], @description("The ISO 639-1 language code describing language used in query-params") language: Option[String] ) -object GrepSearchInput { - implicit val encoder: Encoder[GrepSearchInput] = deriveEncoder - implicit val decoder: Decoder[GrepSearchInput] = deriveDecoder +object GrepSearchInputDTO { + implicit val encoder: Encoder[GrepSearchInputDTO] = deriveEncoder + implicit val decoder: Decoder[GrepSearchInputDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParams.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParamsDTO.scala similarity index 83% rename from search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParams.scala rename to search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParamsDTO.scala index 528e37339..e05506c8c 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParams.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SearchParamsDTO.scala @@ -16,81 +16,66 @@ import no.ndla.searchapi.model.domain.Sort import sttp.tapir.Schema import sttp.tapir.Schema.annotations.description -// format: off -case class SearchParams ( +case class SearchParamsDTO( @description("The page number of the search hits to display.") page: Option[Int], - @description(s"The number of search hits to display for each page.") pageSize: Option[Int], - @description("A list of article-types the search should be filtered by.") articleTypes: Option[List[String]], - @description( s"""A unique string obtained from a search you want to keep scrolling in. To obtain one from a search, provide one of the following values: ["0", "initial", "start", "first"]. |When scrolling, the parameters from the initial search is used, except in the case of 'language' and 'fallback'. |This value may change between scrolls. Always use the one in the latest scroll result. - |""".stripMargin) + |""".stripMargin + ) scrollId: Option[String], - @description("Return only results with content matching the specified query.") query: Option[NonEmptyString], - @description("Fallback to existing language if language is specified.") fallback: Option[Boolean], - @description("The ISO 639-1 language code describing language.") language: Option[String], - @description("Return only results with provided license.") license: Option[String], - @description("The sorting used on results.") sort: Option[Sort], - @description("Return only learning resources that have one of the provided ids.") ids: Option[List[Long]], - @description("A comma separated list of subjects the learning resources should be filtered by.") subjects: Option[List[String]], - @description("Return only learning resources of specific type(s).") resourceTypes: Option[List[String]], - @description("A list of context-types the learning resources should be filtered by.") contextTypes: Option[List[String]], - @description( """A list of relevances the learning resources should be filtered by. |If subjects are specified the learning resource must have specified relevances in relation to a specified subject. - |If levels are specified the learning resource must have specified relevances in relation to a specified level.""".stripMargin) + |If levels are specified the learning resource must have specified relevances in relation to a specified level.""".stripMargin + ) relevance: Option[List[String]], - @description("A list of ISO 639-1 language codes that the learning resource can be available in.") languageFilter: Option[List[String]], - @description("A list of codes from GREP API the resources should be filtered by.") grepCodes: Option[List[String]], - @description("List of index-paths that should be term-aggregated and returned in result.") aggregatePaths: Option[List[String]], - - @description("Return only results with embed data-resource the specified resource. Can specify multiple with a comma separated list to filter for one of the embed types.") + @description( + "Return only results with embed data-resource the specified resource. Can specify multiple with a comma separated list to filter for one of the embed types." + ) embedResource: Option[List[String]], - @description("Return only results with embed data-resource_id, data-videoid or data-url with the specified id.") embedId: Option[String], - @description("Filter out inactive taxonomy contexts.") - filterInactive: Option[Boolean], + filterInactive: Option[Boolean] ) -object SearchParams { - implicit val encoder: Encoder[SearchParams] = deriveEncoder - implicit val decoder: Decoder[SearchParams] = deriveDecoder - implicit val schema: Schema[SearchParams] = Schema.derived[SearchParams] +object SearchParamsDTO { + implicit val encoder: Encoder[SearchParamsDTO] = deriveEncoder + implicit val decoder: Decoder[SearchParamsDTO] = deriveDecoder + implicit val schema: Schema[SearchParamsDTO] = Schema.derived[SearchParamsDTO] import com.scalatsi.dsl.* - implicit val tsType: TSIType[SearchParams] = TSType.fromCaseClass[SearchParams] - "sort" + ("sort", TSString | TSUndefined) + implicit val tsType: TSIType[SearchParamsDTO] = + TSType.fromCaseClass[SearchParamsDTO] - "sort" + ("sort", TSString | TSUndefined) } diff --git a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInput.scala b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInputDTO.scala similarity index 71% rename from search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInput.scala rename to search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInputDTO.scala index a4a4b59ae..a702958cc 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInput.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/controller/parameters/SubjectAggsInputDTO.scala @@ -13,12 +13,12 @@ import io.circe.{Decoder, Encoder} import sttp.tapir.Schema.annotations.description @description("Input parameters to subject aggregations endpoint") -case class SubjectAggsInput( +case class SubjectAggsInputDTO( @description("A comma separated list of subjects the learning resources should be filtered by.") subjects: Option[List[String]] ) -object SubjectAggsInput { - implicit val encoder: Encoder[SubjectAggsInput] = deriveEncoder - implicit val decoder: Decoder[SubjectAggsInput] = deriveDecoder +object SubjectAggsInputDTO { + implicit val encoder: Encoder[SubjectAggsInputDTO] = deriveEncoder + implicit val decoder: Decoder[SubjectAggsInputDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContext.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContextDTO.scala similarity index 84% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContext.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContextDTO.scala index 3fa796a5f..e779fb188 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContext.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/ApiTaxonomyContextDTO.scala @@ -12,7 +12,7 @@ import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import sttp.tapir.Schema.annotations.description @description("Taxonomy context for the resource") -case class ApiTaxonomyContext( +case class ApiTaxonomyContextDTO( @description("Id of the taxonomy object.") publicId: String, @description("Name of the root node this context is in.") root: String, @description("Id of the root node this context is in.") rootId: String, @@ -22,14 +22,14 @@ case class ApiTaxonomyContext( @description("Breadcrumbs of path to the resource in this context.") breadcrumbs: List[String], @description("Unique id of this context.") contextId: String, @description("Type in this context.") contextType: String, - @description("Resource-types of this context.") resourceTypes: List[TaxonomyResourceType], + @description("Resource-types of this context.") resourceTypes: List[TaxonomyResourceTypeDTO], @description("Language for this context.") language: String, @description("Whether this context is the primary connection") isPrimary: Boolean, @description("Whether this context is active") isActive: Boolean, @description("Unique url for this context.") url: String ) -object ApiTaxonomyContext { - implicit val encoder: Encoder[ApiTaxonomyContext] = deriveEncoder - implicit val decoder: Decoder[ApiTaxonomyContext] = deriveDecoder +object ApiTaxonomyContextDTO { + implicit val encoder: Encoder[ApiTaxonomyContextDTO] = deriveEncoder + implicit val decoder: Decoder[ApiTaxonomyContextDTO] = deriveDecoder } 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/ArticleResultDTO.scala similarity index 80% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/ArticleResultDTO.scala index 116f4ae85..f4f64a7fb 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/ArticleResultDTO.scala @@ -7,14 +7,14 @@ package no.ndla.searchapi.model.api -import no.ndla.searchapi.model.api.article.ArticleIntroduction +import no.ndla.searchapi.model.api.article.ArticleIntroductionDTO import sttp.tapir.Schema.annotations.description @description("Search result for article api") -case class ArticleResult( +case class ArticleResultDTO( @description("The unique id of this article") id: Long, - @description("The title of the article") title: TitleWithHtml, - @description("The introduction of the article") introduction: Option[ArticleIntroduction], + @description("The title of the article") title: TitleWithHtmlDTO, + @description("The introduction of the article") introduction: Option[ArticleIntroductionDTO], @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/AudioResultDTO.scala similarity index 82% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/AudioResultDTO.scala index c77e92c4e..ae64b47e4 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/AudioResultDTO.scala @@ -10,9 +10,9 @@ package no.ndla.searchapi.model.api import sttp.tapir.Schema.annotations.description @description("Search result for audio api") -case class AudioResult( +case class AudioResultDTO( @description("The unique id of this audio") id: Long, - @description("The title of this audio") title: Title, + @description("The title of this audio") title: TitleDTO, @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/DraftResponsible.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/DraftResponsibleDTO.scala similarity index 72% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/DraftResponsible.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/DraftResponsibleDTO.scala index 34d1b57e6..1aaadc033 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/DraftResponsible.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/DraftResponsibleDTO.scala @@ -13,12 +13,12 @@ import no.ndla.common.model.NDLADate import sttp.tapir.Schema.annotations.description @description("Information about the responsible") -case class DraftResponsible( +case class DraftResponsibleDTO( @description("NDLA ID of responsible editor") responsibleId: String, @description("Date of when the responsible editor was last updated") lastUpdated: NDLADate ) -object DraftResponsible { - implicit val encoder: Encoder[DraftResponsible] = deriveEncoder - implicit val decoder: Decoder[DraftResponsible] = deriveDecoder +object DraftResponsibleDTO { + implicit val encoder: Encoder[DraftResponsibleDTO] = deriveEncoder + implicit val decoder: Decoder[DraftResponsibleDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResultDTO.scala similarity index 79% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResultDTO.scala index f17f9410c..98b58c3ff 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/GroupSearchResultDTO.scala @@ -13,18 +13,18 @@ import no.ndla.search.api.MultiSearchTermsAggregationDTO import sttp.tapir.Schema.annotations.description @description("Search result for group search") -case class GroupSearchResult( +case class GroupSearchResultDTO( @description("The total number of resources matching this query") totalCount: Long, @description("For which page results are shown from") page: Option[Int], @description("The number of results per page") pageSize: Int, @description("The chosen search language") language: String, - @description("The search results") results: Seq[MultiSearchSummary], - @description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestion], + @description("The search results") results: Seq[MultiSearchSummaryDTO], + @description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestionDTO], @description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregationDTO], @description("Type of resources in this object") resourceType: String ) -object GroupSearchResult { - implicit val encoder: Encoder[GroupSearchResult] = deriveEncoder - implicit val decoder: Decoder[GroupSearchResult] = deriveDecoder +object GroupSearchResultDTO { + implicit val encoder: Encoder[GroupSearchResultDTO] = deriveEncoder + implicit val decoder: Decoder[GroupSearchResultDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltText.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltTextDTO.scala similarity index 93% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltText.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltTextDTO.scala index 74fafa8f7..db12b1590 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltText.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/ImageAltTextDTO.scala @@ -10,7 +10,7 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("Title of resource") -case class ImageAltText( +case class ImageAltTextDTO( @description("The freetext alttext of the image") altText: String, @description("ISO 639-1 code that represents the language used in alttext") language: String ) extends WithLanguage 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/ImageResultDTO.scala similarity index 85% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/ImageResultDTO.scala index 35a9f35af..9f1f2107f 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/ImageResultDTO.scala @@ -10,10 +10,10 @@ package no.ndla.searchapi.model.api import sttp.tapir.Schema.annotations.description @description("Search result for image api") -case class ImageResult( +case class ImageResultDTO( @description("The unique id of this image") id: Long, - @description("The title of this image") title: Title, - @description("The alt text of this image") altText: ImageAltText, + @description("The title of this image") title: TitleDTO, + @description("The alt text of this image") altText: ImageAltTextDTO, @description("A direct link to the image") previewUrl: String, @description("A link to get meta data related to the image") metaUrl: String, @description("List of supported languages") supportedLanguages: Seq[String] diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroduction.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroductionDTO.scala similarity index 92% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroduction.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroductionDTO.scala index 5247d8d57..8b0c9df12 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroduction.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/LearningPathIntroductionDTO.scala @@ -10,7 +10,7 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("Introduction of learningPath") -case class LearningPathIntroduction( +case class LearningPathIntroductionDTO( @description("The freetext introduction of the learningpath") introduction: String, @description("ISO 639-1 code that represents the language used in introduction") language: String ) extends WithLanguage 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/LearningpathResultDTO.scala similarity index 75% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/LearningpathResultDTO.scala index 40ee90d37..10bde36e4 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/LearningpathResultDTO.scala @@ -10,9 +10,9 @@ package no.ndla.searchapi.model.api import sttp.tapir.Schema.annotations.description @description("Search result for learningpath api") -case class LearningpathResult( +case class LearningpathResultDTO( @description("The unique id of this learningpath") id: Long, - @description("The title of the learningpath") title: Title, - @description("The introduction of the learningpath") introduction: LearningPathIntroduction, + @description("The title of the learningpath") title: TitleDTO, + @description("The introduction of the learningpath") introduction: LearningPathIntroductionDTO, @description("List of supported languages") supportedLanguages: Seq[String] ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescription.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescriptionDTO.scala similarity index 75% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescription.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescriptionDTO.scala index 55924a4ef..bca31f623 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescription.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaDescriptionDTO.scala @@ -13,14 +13,14 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("Meta description of the resource") -case class MetaDescription( +case class MetaDescriptionDTO( @description("The meta description") metaDescription: String, @description( "The ISO 639-1 language code describing which article translation this meta description belongs to" ) language: String ) extends WithLanguage -object MetaDescription { - implicit val encoder: Encoder[MetaDescription] = deriveEncoder - implicit val decoder: Decoder[MetaDescription] = deriveDecoder +object MetaDescriptionDTO { + implicit val encoder: Encoder[MetaDescriptionDTO] = deriveEncoder + implicit val decoder: Decoder[MetaDescriptionDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImage.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImageDTO.scala similarity index 81% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImage.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImageDTO.scala index f3bc67b9d..ebb702485 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImage.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MetaImageDTO.scala @@ -12,7 +12,7 @@ import no.ndla.language.model.LanguageField import sttp.tapir.Schema.annotations.description @description("Meta image of the resource") -case class MetaImage( +case class MetaImageDTO( @description("The meta image id") url: String, @description("The meta image alt text") alt: String, @description("The ISO 639-1 language code describing which translation this meta image belongs to") language: String @@ -21,7 +21,7 @@ case class MetaImage( override def isEmpty: Boolean = url.isEmpty || alt.isEmpty } -object MetaImage { - implicit val encoder: Encoder[MetaImage] = deriveEncoder - implicit val decoder: Decoder[MetaImage] = deriveDecoder +object MetaImageDTO { + implicit val encoder: Encoder[MetaImageDTO] = deriveEncoder + implicit val decoder: Decoder[MetaImageDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResultDTO.scala similarity index 78% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResultDTO.scala index 29fbb73ee..8aeaaf815 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchResultDTO.scala @@ -13,17 +13,17 @@ import no.ndla.search.api.MultiSearchTermsAggregationDTO import sttp.tapir.Schema.annotations.description @description("Information about search-results") -case class MultiSearchResult( +case class MultiSearchResultDTO( @description("The total number of resources matching this query") totalCount: Long, @description("For which page results are shown from") page: Option[Int], @description("The number of results per page") pageSize: Int, @description("The chosen search language") language: String, - @description("The search results") results: Seq[MultiSearchSummary], - @description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestion], + @description("The search results") results: Seq[MultiSearchSummaryDTO], + @description("The suggestions for other searches") suggestions: Seq[MultiSearchSuggestionDTO], @description("The aggregated fields if specified in query") aggregations: Seq[MultiSearchTermsAggregationDTO] ) -object MultiSearchResult { - implicit val encoder: Encoder[MultiSearchResult] = deriveEncoder - implicit val decoder: Decoder[MultiSearchResult] = deriveDecoder +object MultiSearchResultDTO { + implicit val encoder: Encoder[MultiSearchResultDTO] = deriveEncoder + implicit val decoder: Decoder[MultiSearchResultDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestion.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestionDTO.scala similarity index 59% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestion.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestionDTO.scala index 6e0e0d8b3..3e7e3bd89 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestion.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSuggestionDTO.scala @@ -12,36 +12,36 @@ import io.circe.{Decoder, Encoder} import sttp.tapir.Schema.annotations.description @description("Information about search-suggestions") -case class MultiSearchSuggestion( +case class MultiSearchSuggestionDTO( @description("The name of the field suggested for") name: String, - @description("The list of suggestions for given field") suggestions: Seq[SearchSuggestion] + @description("The list of suggestions for given field") suggestions: Seq[SearchSuggestionDTO] ) -object MultiSearchSuggestion { - implicit val encoder: Encoder[MultiSearchSuggestion] = deriveEncoder - implicit val decoder: Decoder[MultiSearchSuggestion] = deriveDecoder +object MultiSearchSuggestionDTO { + implicit val encoder: Encoder[MultiSearchSuggestionDTO] = deriveEncoder + implicit val decoder: Decoder[MultiSearchSuggestionDTO] = deriveDecoder } @description("Search suggestion for query-text") -case class SearchSuggestion( +case class SearchSuggestionDTO( @description("The search query suggestions are made for") text: String, @description("The offset in the search query") offset: Int, @description("The position index in the search query") length: Int, - @description("The list of suggest options for the field") options: Seq[SuggestOption] + @description("The list of suggest options for the field") options: Seq[SuggestOptionDTO] ) -object SearchSuggestion { - implicit val encoder: Encoder[SearchSuggestion] = deriveEncoder - implicit val decoder: Decoder[SearchSuggestion] = deriveDecoder +object SearchSuggestionDTO { + implicit val encoder: Encoder[SearchSuggestionDTO] = deriveEncoder + implicit val decoder: Decoder[SearchSuggestionDTO] = deriveDecoder } @description("Search suggestion options for the terms in the query") -case class SuggestOption( +case class SuggestOptionDTO( @description("The suggested text") text: String, @description("The score of the suggestion") score: Double ) -object SuggestOption { - implicit val encoder: Encoder[SuggestOption] = deriveEncoder - implicit val decoder: Decoder[SuggestOption] = deriveDecoder +object SuggestOptionDTO { + implicit val encoder: Encoder[SuggestOptionDTO] = deriveEncoder + implicit val decoder: Decoder[SuggestOptionDTO] = deriveDecoder } 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 deleted file mode 100644 index 89edf6c0b..000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummary.scala +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2018 NDLA - * - * See LICENSE - */ - -package no.ndla.searchapi.model.api - -import io.circe.{Decoder, Encoder} -import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} -import no.ndla.common.model.NDLADate -import no.ndla.common.model.api.draft.CommentDTO -import no.ndla.searchapi.model.domain.LearningResourceType -import no.ndla.searchapi.model.search.SearchType -import sttp.tapir.Schema.annotations.description - -@description("Object describing matched field with matching words emphasized") -case class HighlightedField( - @description("Field that matched") field: String, - @description("List of segments that matched in `field`") matches: Seq[String] -) - -object HighlightedField { - implicit val encoder: Encoder[HighlightedField] = deriveEncoder - implicit val decoder: Decoder[HighlightedField] = deriveDecoder -} - -// format: off -@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: 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, - @description("Contexts of the resource") contexts: List[ApiTaxonomyContext], - @description("Languages the resource exists in") supportedLanguages: Seq[String], - @description("Learning resource type") learningResourceType: LearningResourceType, - @description("Status information of the resource") status: Option[Status], - @description("Traits for the resource") traits: List[String], - @description("Relevance score. The higher the score, the better the document matches your search criteria.") score: Float, - @description("List of objects describing matched field with matching words emphasized") highlights: List[HighlightedField], - @description("The taxonomy paths for the resource") paths: List[String], - @description("The time and date of last update") lastUpdated: NDLADate, - @description("Describes the license of the resource") license: Option[String], - @description("A list of revisions planned for the article") revisions: Seq[RevisionMeta], - @description("Responsible field") responsible: Option[DraftResponsible], - @description("Information about comments attached to the article") comments: Option[Seq[CommentDTO]], - @description("If the article should be prioritized" ) prioritized: Option[Boolean], - @description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String], - @description("A combined resource type name if a standard article, otherwise the article type name") resourceTypeName: Option[String], - @description("Name of the parent topic if exists") parentTopicName: Option[String], - @description("Name of the primary context root if exists") primaryRootName: Option[String], - @description("When the article was last published") published: Option[NDLADate], - @description("Number of times favorited in MyNDLA") favorited: Option[Long], - @description("Type of the resource") resultType: SearchType, - @description("Subject ids for the resource, if a concept") conceptSubjectIds: Option[List[String]] -) -// format: on - -object MultiSearchSummary { - implicit val encoder: Encoder[MultiSearchSummary] = deriveEncoder - implicit val decoder: Decoder[MultiSearchSummary] = deriveDecoder -} diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummaryDTO.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummaryDTO.scala new file mode 100644 index 000000000..82e702d84 --- /dev/null +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/MultiSearchSummaryDTO.scala @@ -0,0 +1,65 @@ +/* + * Part of NDLA search-api + * Copyright (C) 2018 NDLA + * + * See LICENSE + */ + +package no.ndla.searchapi.model.api + +import io.circe.{Decoder, Encoder} +import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} +import no.ndla.common.model.NDLADate +import no.ndla.common.model.api.draft.CommentDTO +import no.ndla.searchapi.model.domain.LearningResourceType +import no.ndla.searchapi.model.search.SearchType +import sttp.tapir.Schema.annotations.description + +@description("Object describing matched field with matching words emphasized") +case class HighlightedFieldDTO( + @description("Field that matched") field: String, + @description("List of segments that matched in `field`") matches: Seq[String] +) + +object HighlightedFieldDTO { + implicit val encoder: Encoder[HighlightedFieldDTO] = deriveEncoder + implicit val decoder: Decoder[HighlightedFieldDTO] = deriveDecoder +} + +// format: off +@description("Short summary of information about the resource") +case class MultiSearchSummaryDTO( + @description("The unique id of the resource") id: Long, + @description("The title of the resource") title: TitleWithHtmlDTO, + @description("The meta description of the resource") metaDescription: MetaDescriptionDTO, + @description("The meta image for the resource") metaImage: Option[MetaImageDTO], + @description("Url pointing to the resource") url: String, + @description("Contexts of the resource") contexts: List[ApiTaxonomyContextDTO], + @description("Languages the resource exists in") supportedLanguages: Seq[String], + @description("Learning resource type") learningResourceType: LearningResourceType, + @description("Status information of the resource") status: Option[StatusDTO], + @description("Traits for the resource") traits: List[String], + @description("Relevance score. The higher the score, the better the document matches your search criteria.") score: Float, + @description("List of objects describing matched field with matching words emphasized") highlights: List[HighlightedFieldDTO], + @description("The taxonomy paths for the resource") paths: List[String], + @description("The time and date of last update") lastUpdated: NDLADate, + @description("Describes the license of the resource") license: Option[String], + @description("A list of revisions planned for the article") revisions: Seq[RevisionMetaDTO], + @description("Responsible field") responsible: Option[DraftResponsibleDTO], + @description("Information about comments attached to the article") comments: Option[Seq[CommentDTO]], + @description("If the article should be prioritized" ) prioritized: Option[Boolean], + @description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String], + @description("A combined resource type name if a standard article, otherwise the article type name") resourceTypeName: Option[String], + @description("Name of the parent topic if exists") parentTopicName: Option[String], + @description("Name of the primary context root if exists") primaryRootName: Option[String], + @description("When the article was last published") published: Option[NDLADate], + @description("Number of times favorited in MyNDLA") favorited: Option[Long], + @description("Type of the resource") resultType: SearchType, + @description("Subject ids for the resource, if a concept") conceptSubjectIds: Option[List[String]] +) +// format: on + +object MultiSearchSummaryDTO { + implicit val encoder: Encoder[MultiSearchSummaryDTO] = deriveEncoder + implicit val decoder: Decoder[MultiSearchSummaryDTO] = deriveDecoder +} diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMeta.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMetaDTO.scala similarity index 77% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMeta.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMetaDTO.scala index 5d1145a94..982612dd0 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMeta.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/RevisionMetaDTO.scala @@ -13,13 +13,13 @@ import no.ndla.common.model.NDLADate import sttp.tapir.Schema.annotations.description @description("Information about the editorial notes") -case class RevisionMeta( +case class RevisionMetaDTO( @description("A date on which the article would need to be revised") revisionDate: NDLADate, @description("Notes to keep track of what needs to happen before revision") note: String, @description("Status of a revision, either 'revised' or 'needs-revision'") status: String ) -object RevisionMeta { - implicit val encoder: Encoder[RevisionMeta] = deriveEncoder - implicit val decoder: Decoder[RevisionMeta] = deriveDecoder +object RevisionMetaDTO { + implicit val encoder: Encoder[RevisionMetaDTO] = deriveEncoder + implicit val decoder: Decoder[RevisionMetaDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultDTO.scala similarity index 94% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultDTO.scala index ac4054361..cd79acfd3 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultDTO.scala @@ -10,7 +10,7 @@ package no.ndla.searchapi.model.api import sttp.tapir.Schema.annotations.description @description("Information about search-results") -case class SearchResult[T]( +case class SearchResultDTO[T]( @description("The total number of articles matching this query") totalCount: Long, @description("For which page results are shown from") page: Int, @description("The number of results per page") pageSize: Int, diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResults.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultsDTO.scala similarity index 79% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResults.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultsDTO.scala index c4b656faf..96db34db5 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResults.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/SearchResultsDTO.scala @@ -9,50 +9,44 @@ package no.ndla.searchapi.model.api import sttp.tapir.Schema.annotations.description -sealed trait SearchResults +sealed trait SearchResultsDTO @description("Search result for article api") -case class ArticleResults( +case class ArticleResultsDTO( @description("The type of search results (articles)") `type`: String, @description("The language of the search results") language: String, @description("The total number of articles matching this query") totalCount: Long, @description("The page from which results are shown from") page: Int, @description("The number of results per page") pageSize: Int, - @description("The actual search results") results: Seq[ArticleResult] -) extends SearchResults + @description("The actual search results") results: Seq[ArticleResultDTO] +) extends SearchResultsDTO @description("Search result for learningpath api") -case class LearningpathResults( +case class LearningpathResultsDTO( @description("The type of search results (learningpaths)") `type`: String, @description("The language of the search results") language: String, @description("The total number of learningpaths matching this query") totalCount: Long, @description("The page from which results are shown from") page: Int, @description("The number of results per page") pageSize: Int, - @description("The actual search results") results: Seq[LearningpathResult] -) extends SearchResults + @description("The actual search results") results: Seq[LearningpathResultDTO] +) extends SearchResultsDTO @description("Search result for image api") -case class ImageResults( +case class ImageResultsDTO( @description("The type of search results (images)") `type`: String, @description("The language of the search results") language: String, @description("The total number of images matching this query") totalCount: Long, @description("The page from which results are shown from") page: Int, @description("The number of results per page") pageSize: Int, - @description("The actual search results") results: Seq[ImageResult] -) extends SearchResults + @description("The actual search results") results: Seq[ImageResultDTO] +) extends SearchResultsDTO @description("Search result for audio api") -case class AudioResults( +case class AudioResultsDTO( @description("The type of search results (audios)") `type`: String, @description("The language of the search results") language: String, @description("The total number of audios matching this query") totalCount: Long, @description("The page from which results are shown from") page: Int, @description("The number of results per page") pageSize: Int, - @description("The actual search results") results: Seq[AudioResult] -) extends SearchResults - -@description("Description of an error when communicating with an api") -case class SearchError( - @description("The api where the error occurred") `type`: String, - @description("An error message describing the error") errorMsg: String -) extends SearchResults + @description("The actual search results") results: Seq[AudioResultDTO] +) extends SearchResultsDTO diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/Status.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/StatusDTO.scala similarity index 75% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/Status.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/StatusDTO.scala index f260b154b..d4e67a8f3 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/Status.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/StatusDTO.scala @@ -12,12 +12,12 @@ import io.circe.{Decoder, Encoder} import sttp.tapir.Schema.annotations.description @description("Status information of the resource") -case class Status( +case class StatusDTO( @description("The current status of the resource") current: String, @description("Previous statuses this resource has been in") other: Seq[String] ) -object Status { - implicit val encoder: Encoder[Status] = deriveEncoder - implicit val decoder: Decoder[Status] = deriveDecoder +object StatusDTO { + implicit val encoder: Encoder[StatusDTO] = deriveEncoder + implicit val decoder: Decoder[StatusDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregations.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregationsDTO.scala similarity index 68% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregations.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregationsDTO.scala index b1d8c0c6a..3f9bd289e 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregations.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/SubjectAggregationsDTO.scala @@ -13,18 +13,18 @@ import io.circe.{Decoder, Encoder} import sttp.tapir.Schema.annotations.description @description("Result of subject aggregations") -case class SubjectAggregations( - subjects: List[SubjectAggregation] +case class SubjectAggregationsDTO( + subjects: List[SubjectAggregationDTO] ) -object SubjectAggregations { - implicit val encoder: Encoder[SubjectAggregations] = deriveEncoder - implicit val decoder: Decoder[SubjectAggregations] = deriveDecoder +object SubjectAggregationsDTO { + implicit val encoder: Encoder[SubjectAggregationsDTO] = deriveEncoder + implicit val decoder: Decoder[SubjectAggregationsDTO] = deriveDecoder } @description("Aggregations for a single subject'") -case class SubjectAggregation( +case class SubjectAggregationDTO( @description("Id of the aggregated subject") subjectId: String, @description("Number of resources in subject") @@ -39,7 +39,7 @@ case class SubjectAggregation( favoritedCount: Long ) -object SubjectAggregation { - implicit val encoder: Encoder[SubjectAggregation] = deriveEncoder - implicit val decoder: Decoder[SubjectAggregation] = deriveDecoder +object SubjectAggregationDTO { + implicit val encoder: Encoder[SubjectAggregationDTO] = deriveEncoder + implicit val decoder: Decoder[SubjectAggregationDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceType.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceTypeDTO.scala similarity index 71% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceType.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceTypeDTO.scala index 979f54410..39436bb6a 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceType.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/TaxonomyResourceTypeDTO.scala @@ -12,13 +12,13 @@ import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import sttp.tapir.Schema.annotations.description @description("Taxonomy resource type") -case class TaxonomyResourceType( +case class TaxonomyResourceTypeDTO( @description("Id of the taoxonomy resource type") id: String, @description("Name of the taoxonomy resource type") name: String, @description("The ISO 639-1 language code for the resource type") language: String ) -object TaxonomyResourceType { - implicit val encoder: Encoder[TaxonomyResourceType] = deriveEncoder - implicit val decoder: Decoder[TaxonomyResourceType] = deriveDecoder +object TaxonomyResourceTypeDTO { + implicit val encoder: Encoder[TaxonomyResourceTypeDTO] = deriveEncoder + implicit val decoder: Decoder[TaxonomyResourceTypeDTO] = deriveDecoder } 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/TitleDTO.scala similarity index 80% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/Title.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/TitleDTO.scala index 3da3b056c..28734539b 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/TitleDTO.scala @@ -13,7 +13,7 @@ import no.ndla.language.model.LanguageField import sttp.tapir.Schema.annotations.description @description("Title of resource") -case class Title( +case class TitleDTO( @description("The freetext title of the resource") title: String, @description("ISO 639-1 code that represents the language used in title") language: String ) extends LanguageField[String] { @@ -21,7 +21,7 @@ case class Title( override def isEmpty: Boolean = title.isEmpty } -object Title { - implicit val encoder: Encoder[Title] = deriveEncoder - implicit val decoder: Decoder[Title] = deriveDecoder +object TitleDTO { + implicit val encoder: Encoder[TitleDTO] = deriveEncoder + implicit val decoder: Decoder[TitleDTO] = deriveDecoder } 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/TitleWithHtmlDTO.scala similarity index 79% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtmlDTO.scala index e9a310bab..fe9605adf 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtml.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/TitleWithHtmlDTO.scala @@ -13,7 +13,7 @@ import no.ndla.language.model.LanguageField import sttp.tapir.Schema.annotations.description @description("Title of resource") -case class TitleWithHtml( +case class TitleWithHtmlDTO( @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 @@ -22,7 +22,7 @@ case class TitleWithHtml( override def isEmpty: Boolean = title.isEmpty } -object TitleWithHtml { - implicit val encoder: Encoder[TitleWithHtml] = deriveEncoder - implicit val decoder: Decoder[TitleWithHtml] = deriveDecoder +object TitleWithHtmlDTO { + implicit val encoder: Encoder[TitleWithHtmlDTO] = deriveEncoder + implicit val decoder: Decoder[TitleWithHtmlDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroduction.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroductionDTO.scala similarity index 94% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroduction.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroductionDTO.scala index f11eea955..368fb169e 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroduction.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleIntroductionDTO.scala @@ -11,7 +11,7 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("Description of the article introduction") -case class ArticleIntroduction( +case class ArticleIntroductionDTO( @description("The introduction content") introduction: String, @description("The html-version introduction content") htmlIntroduction: String, @description( diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImage.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImageDTO.scala similarity index 95% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImage.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImageDTO.scala index 39f2d0dd7..922e4c928 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImage.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/ArticleMetaImageDTO.scala @@ -11,7 +11,7 @@ import no.ndla.language.model.LanguageField import sttp.tapir.Schema.annotations.description @description("Meta description of the article") -case class ArticleMetaImage( +case class ArticleMetaImageDTO( @description("The meta image url") url: String, @description("The alt text for the meta image") alt: String, @description( diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElement.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElementDTO.scala similarity index 95% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElement.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElementDTO.scala index a64343293..2fc5ce5db 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElement.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/article/VisualElementDTO.scala @@ -11,7 +11,7 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("Description of a visual element") -case class VisualElement( +case class VisualElementDTO( @description( "Html containing the visual element. May contain any legal html element, including the embed-tag" ) visualElement: String, diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResultDTO.scala similarity index 59% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResult.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResultDTO.scala index 2d11ce2a7..53a1eb945 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepResultDTO.scala @@ -10,16 +10,16 @@ package no.ndla.searchapi.model.api.grep import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} -import no.ndla.searchapi.model.api.Title +import no.ndla.searchapi.model.api.TitleDTO import sttp.tapir.Schema.annotations.description @description("Information about a single grep search result entry") -case class GrepResult( +case class GrepResultDTO( @description("The grep code") code: String, - @description("The greps title") title: Title + @description("The greps title") title: TitleDTO ) -object GrepResult { - implicit val encoder: Encoder[GrepResult] = deriveEncoder - implicit val decoder: Decoder[GrepResult] = deriveDecoder +object GrepResultDTO { + implicit val encoder: Encoder[GrepResultDTO] = deriveEncoder + implicit val decoder: Decoder[GrepResultDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResults.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResultsDTO.scala similarity index 69% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResults.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResultsDTO.scala index beeff9867..e25ff2be9 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResults.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSearchResultsDTO.scala @@ -13,15 +13,15 @@ import io.circe.{Decoder, Encoder} import sttp.tapir.Schema.annotations.description @description("Information about search-results") -case class GrepSearchResults( +case class GrepSearchResultsDTO( @description("The total number of resources matching this query") totalCount: Long, @description("For which page results are shown from") page: Int, @description("The number of results per page") pageSize: Int, @description("The chosen search language") language: String, - @description("The search results") results: Seq[GrepResult] + @description("The search results") results: Seq[GrepResultDTO] ) -object GrepSearchResults { - implicit val encoder: Encoder[GrepSearchResults] = deriveEncoder - implicit val decoder: Decoder[GrepSearchResults] = deriveDecoder +object GrepSearchResultsDTO { + implicit val encoder: Encoder[GrepSearchResultsDTO] = deriveEncoder + implicit val decoder: Decoder[GrepSearchResultsDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSort.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSort.scala deleted file mode 100644 index af58421a9..000000000 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSort.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Part of NDLA search-api - * Copyright (C) 2024 NDLA - * - * See LICENSE - * - */ - -package no.ndla.searchapi.model.api.grep - -import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion} -import com.scalatsi.{TSNamedType, TSType} -import enumeratum.* -import sttp.tapir.Codec.PlainCodec -import sttp.tapir.Schema -import sttp.tapir.codec.enumeratum.* - -sealed abstract class GrepSort(override val entryName: String) extends EnumEntry -object GrepSort extends Enum[GrepSort] with CirceEnum[GrepSort] { - val values: IndexedSeq[GrepSort] = findValues - val all: Seq[String] = values.map(_.entryName) - - case object ByRelevanceDesc extends GrepSort("-relevance") - case object ByRelevanceAsc extends GrepSort("relevance") - case object ByTitleDesc extends GrepSort("-title") - case object ByTitleAsc extends GrepSort("title") - case object ByCodeDesc extends GrepSort("-code") - case object ByCodeAsc extends GrepSort("code") - - implicit val schema: Schema[GrepSort] = schemaForEnumEntry[GrepSort] - implicit val codec: PlainCodec[GrepSort] = plainCodecEnumEntry[GrepSort] - implicit val enumTsType: TSNamedType[GrepSort] = - TSType.alias[GrepSort]("GrepSort", TSUnion(all.map(s => TSLiteralString(s)))) - -} diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSortDTO.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSortDTO.scala new file mode 100644 index 000000000..9d4ebaae4 --- /dev/null +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/grep/GrepSortDTO.scala @@ -0,0 +1,35 @@ +/* + * Part of NDLA search-api + * Copyright (C) 2024 NDLA + * + * See LICENSE + * + */ + +package no.ndla.searchapi.model.api.grep + +import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion} +import com.scalatsi.{TSNamedType, TSType} +import enumeratum.* +import sttp.tapir.Codec.PlainCodec +import sttp.tapir.Schema +import sttp.tapir.codec.enumeratum.* + +sealed abstract class GrepSortDTO(override val entryName: String) extends EnumEntry +object GrepSortDTO extends Enum[GrepSortDTO] with CirceEnum[GrepSortDTO] { + val values: IndexedSeq[GrepSortDTO] = findValues + val all: Seq[String] = values.map(_.entryName) + + case object ByRelevanceDesc extends GrepSortDTO("-relevance") + case object ByRelevanceAsc extends GrepSortDTO("relevance") + case object ByTitleDesc extends GrepSortDTO("-title") + case object ByTitleAsc extends GrepSortDTO("title") + case object ByCodeDesc extends GrepSortDTO("-code") + case object ByCodeAsc extends GrepSortDTO("code") + + implicit val schema: Schema[GrepSortDTO] = schemaForEnumEntry[GrepSortDTO] + implicit val codec: PlainCodec[GrepSortDTO] = plainCodecEnumEntry[GrepSortDTO] + implicit val enumTsType: TSNamedType[GrepSortDTO] = + TSType.alias[GrepSortDTO]("GrepSort", TSUnion(all.map(s => TSLiteralString(s)))) + +} diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Copyright.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/CopyrightDTO.scala similarity index 75% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Copyright.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/CopyrightDTO.scala index e528b71cc..cd923c8e3 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Copyright.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/CopyrightDTO.scala @@ -13,12 +13,12 @@ import no.ndla.common.model.api.{AuthorDTO, LicenseDTO} import sttp.tapir.Schema.annotations.description @description("Description of copyright information") -case class Copyright( +case class CopyrightDTO( @description("Describes the license of the learningpath") license: LicenseDTO, @description("List of authors") contributors: Seq[AuthorDTO] ) -object Copyright { - implicit val encoder: Encoder[Copyright] = deriveEncoder - implicit val decoder: Decoder[Copyright] = deriveDecoder +object CopyrightDTO { + implicit val encoder: Encoder[CopyrightDTO] = deriveEncoder + implicit val decoder: Decoder[CopyrightDTO] = deriveDecoder } diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Description.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/DescriptionDTO.scala similarity index 95% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Description.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/DescriptionDTO.scala index 5c38189d5..892c59264 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Description.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/DescriptionDTO.scala @@ -11,7 +11,7 @@ import no.ndla.language.model.LanguageField import sttp.tapir.Schema.annotations.description @description("The description of the learningpath") -case class Description( +case class DescriptionDTO( @description("The description to the learningpath.") description: String, @description("ISO 639-1 code that represents the language used in introduction") language: String ) extends LanguageField[String] { diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Introduction.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/IntroductionDTO.scala similarity index 94% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Introduction.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/IntroductionDTO.scala index 383d0d707..8e2156c7e 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/Introduction.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/IntroductionDTO.scala @@ -11,7 +11,7 @@ import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description @description("The introduction of the learningpath") -case class Introduction( +case class IntroductionDTO( @description("The introduction to the learningpath. Basic HTML allowed") introduction: String, @description("ISO 639-1 code that represents the language used in introduction") language: String ) extends WithLanguage diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTags.scala b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTagsDTO.scala similarity index 92% rename from search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTags.scala rename to search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTagsDTO.scala index 89bdf3c1c..9dac52cab 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTags.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/api/learningpath/LearningPathTagsDTO.scala @@ -10,7 +10,7 @@ package no.ndla.searchapi.model.api.learningpath import no.ndla.language.model.WithLanguage import sttp.tapir.Schema.annotations.description -case class LearningPathTags( +case class LearningPathTagsDTO( @description("The searchable tags. Must be plain text") tags: Seq[String], @description("ISO 639-1 code that represents the language used in tag") language: String ) extends WithLanguage diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/domain/SearchResult.scala b/search-api/src/main/scala/no/ndla/searchapi/model/domain/SearchResult.scala index 36bc25ffe..2f8e0d4e2 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/domain/SearchResult.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/domain/SearchResult.scala @@ -7,15 +7,15 @@ package no.ndla.searchapi.model.domain import no.ndla.search.model.domain.TermAggregation -import no.ndla.searchapi.model.api.{MultiSearchSuggestion, MultiSearchSummary} +import no.ndla.searchapi.model.api.{MultiSearchSuggestionDTO, MultiSearchSummaryDTO} case class SearchResult( totalCount: Long, page: Option[Int], pageSize: Int, language: String, - results: Seq[MultiSearchSummary], - suggestions: Seq[MultiSearchSuggestion], + results: Seq[MultiSearchSummaryDTO], + suggestions: Seq[MultiSearchSuggestionDTO], aggregations: Seq[TermAggregation], scrollId: Option[String] = None ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableConcept.scala b/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableConcept.scala index 224ac96bd..74562e69b 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableConcept.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableConcept.scala @@ -13,7 +13,7 @@ import no.ndla.common.model.NDLADate import no.ndla.common.model.domain.Responsible import no.ndla.common.model.domain.concept.{Concept, ConceptMetaImage} import no.ndla.search.model.{SearchableLanguageList, SearchableLanguageValues} -import no.ndla.searchapi.model.api.Status +import no.ndla.searchapi.model.api.StatusDTO import no.ndla.searchapi.model.domain.LearningResourceType case class SearchableConcept( @@ -26,7 +26,7 @@ case class SearchableConcept( tags: SearchableLanguageList, subjectIds: List[String], lastUpdated: NDLADate, - draftStatus: Status, + draftStatus: StatusDTO, users: List[String], updatedBy: Seq[String], license: Option[String], diff --git a/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableLearningPath.scala b/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableLearningPath.scala index e29512f20..449f0da78 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableLearningPath.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/model/search/SearchableLearningPath.scala @@ -11,7 +11,7 @@ import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} import no.ndla.common.model.NDLADate import no.ndla.search.model.{SearchableLanguageList, SearchableLanguageValues} -import no.ndla.searchapi.model.api.learningpath.Copyright +import no.ndla.searchapi.model.api.learningpath.CopyrightDTO import no.ndla.searchapi.model.domain.LearningResourceType case class SearchableLearningPath( @@ -28,7 +28,7 @@ case class SearchableLearningPath( tags: SearchableLanguageList, learningsteps: List[SearchableLearningStep], license: String, - copyright: Copyright, + copyright: CopyrightDTO, isBasedOn: Option[Long], supportedLanguages: List[String], authors: List[String], 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 1bff81baa..cd7cb45c3 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 @@ -11,8 +11,8 @@ import io.lemonlabs.uri.typesafe.dsl.* import no.ndla.network.ApplicationUrl import no.ndla.searchapi.Props import no.ndla.searchapi.model.api -import no.ndla.searchapi.model.api.LearningPathIntroduction -import no.ndla.searchapi.model.api.article.ArticleIntroduction +import no.ndla.searchapi.model.api.LearningPathIntroductionDTO +import no.ndla.searchapi.model.api.article.ArticleIntroductionDTO import no.ndla.searchapi.model.domain.* trait ConverterService { @@ -22,7 +22,7 @@ trait ConverterService { class ConverterService { import props.Domain - def searchResultToApiModel(searchResults: ApiSearchResults): api.SearchResults = { + def searchResultToApiModel(searchResults: ApiSearchResults): api.SearchResultsDTO = { searchResults match { case a: ArticleApiSearchResults => articleSearchResultsToApi(a) case l: LearningpathApiSearchResults => learningpathSearchResultsToApi(l) @@ -31,8 +31,8 @@ trait ConverterService { } } - private def articleSearchResultsToApi(articles: ArticleApiSearchResults): api.ArticleResults = { - api.ArticleResults( + private def articleSearchResultsToApi(articles: ArticleApiSearchResults): api.ArticleResultsDTO = { + api.ArticleResultsDTO( "articles", articles.language, articles.totalCount, @@ -42,18 +42,20 @@ trait ConverterService { ) } - private def articleSearchResultToApi(article: ArticleApiSearchResult): api.ArticleResult = { - api.ArticleResult( + private def articleSearchResultToApi(article: ArticleApiSearchResult): api.ArticleResultDTO = { + api.ArticleResultDTO( article.id, - api.TitleWithHtml(article.title.title, article.title.htmlTitle, article.title.language), - article.introduction.map(i => ArticleIntroduction(i.introduction, i.htmlIntroduction, i.language)), + api.TitleWithHtmlDTO(article.title.title, article.title.htmlTitle, article.title.language), + article.introduction.map(i => ArticleIntroductionDTO(i.introduction, i.htmlIntroduction, i.language)), article.articleType, article.supportedLanguages ) } - private def learningpathSearchResultsToApi(learningpaths: LearningpathApiSearchResults): api.LearningpathResults = { - api.LearningpathResults( + private def learningpathSearchResultsToApi( + learningpaths: LearningpathApiSearchResults + ): api.LearningpathResultsDTO = { + api.LearningpathResultsDTO( "learningpaths", learningpaths.language, learningpaths.totalCount, @@ -63,17 +65,17 @@ trait ConverterService { ) } - private def learningpathSearchResultToApi(learningpath: LearningpathApiSearchResult): api.LearningpathResult = { - api.LearningpathResult( + private def learningpathSearchResultToApi(learningpath: LearningpathApiSearchResult): api.LearningpathResultDTO = { + api.LearningpathResultDTO( learningpath.id, - api.Title(learningpath.title.title, learningpath.title.language), - LearningPathIntroduction(learningpath.introduction.introduction, learningpath.introduction.language), + api.TitleDTO(learningpath.title.title, learningpath.title.language), + LearningPathIntroductionDTO(learningpath.introduction.introduction, learningpath.introduction.language), learningpath.supportedLanguages ) } - private def imageSearchResultsToApi(images: ImageApiSearchResults): api.ImageResults = { - api.ImageResults( + private def imageSearchResultsToApi(images: ImageApiSearchResults): api.ImageResultsDTO = { + api.ImageResultsDTO( "images", images.language, images.totalCount, @@ -83,25 +85,25 @@ trait ConverterService { ) } - private def imageSearchResultToApi(image: ImageApiSearchResult): api.ImageResult = { + private def imageSearchResultToApi(image: ImageApiSearchResult): api.ImageResultDTO = { val scheme = ApplicationUrl.get.schemeOption.getOrElse("https://") val host = ApplicationUrl.get.hostOption.map(_.toString).getOrElse(Domain) val previewUrl = image.previewUrl.withHost(host).withScheme(scheme) val metaUrl = image.metaUrl.withHost(host).withScheme(scheme) - api.ImageResult( + api.ImageResultDTO( image.id.toLong, - api.Title(image.title.title, image.title.language), - api.ImageAltText(image.altText.alttext, image.altText.language), + api.TitleDTO(image.title.title, image.title.language), + api.ImageAltTextDTO(image.altText.alttext, image.altText.language), previewUrl.toString, metaUrl.toString, image.supportedLanguages ) } - private def audioSearchResultsToApi(audios: AudioApiSearchResults): api.AudioResults = { - api.AudioResults( + private def audioSearchResultsToApi(audios: AudioApiSearchResults): api.AudioResultsDTO = { + api.AudioResultsDTO( "audios", audios.language, audios.totalCount, @@ -111,14 +113,14 @@ trait ConverterService { ) } - private def audioSearchResultToApi(audio: AudioApiSearchResult): api.AudioResult = { + private def audioSearchResultToApi(audio: AudioApiSearchResult): api.AudioResultDTO = { val scheme = ApplicationUrl.get.schemeOption.getOrElse("https://") val host = ApplicationUrl.get.hostOption.map(_.toString).getOrElse(Domain) val url = audio.url.withHost(host).withScheme(scheme).toString - api.AudioResult( + api.AudioResultDTO( audio.id, - api.Title(audio.title.title, audio.title.language), + api.TitleDTO(audio.title.title, audio.title.language), url, audio.supportedLanguages ) diff --git a/search-api/src/main/scala/no/ndla/searchapi/service/search/GrepSearchService.scala b/search-api/src/main/scala/no/ndla/searchapi/service/search/GrepSearchService.scala index 9db8d8629..71302f802 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/service/search/GrepSearchService.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/service/search/GrepSearchService.scala @@ -23,10 +23,10 @@ import no.ndla.language.model.Iso639 import no.ndla.search.model.LanguageValue import no.ndla.search.{BaseIndexService, Elastic4sClient} import no.ndla.searchapi.Props -import no.ndla.searchapi.controller.parameters.GrepSearchInput -import no.ndla.searchapi.model.api.Title -import no.ndla.searchapi.model.api.grep.GrepSort.* -import no.ndla.searchapi.model.api.grep.{GrepResult, GrepSearchResults, GrepSort} +import no.ndla.searchapi.controller.parameters.GrepSearchInputDTO +import no.ndla.searchapi.model.api.TitleDTO +import no.ndla.searchapi.model.api.grep.GrepSortDTO.* +import no.ndla.searchapi.model.api.grep.{GrepResultDTO, GrepSearchResultsDTO, GrepSortDTO} import no.ndla.searchapi.model.search.{SearchType, SearchableGrepElement} import scala.util.{Success, Try} @@ -40,7 +40,7 @@ trait GrepSearchService { override val searchIndex: List[String] = List(SearchType.Grep).map(SearchIndex) override val indexServices: List[BaseIndexService] = List(grepIndexService) - def grepSortDefinition(maybeSort: Option[GrepSort], language: String): FieldSort = maybeSort match { + def grepSortDefinition(maybeSort: Option[GrepSortDTO], language: String): FieldSort = maybeSort match { case Some(ByRelevanceAsc) => sortField("_score", Asc, missingLast = false) case Some(ByRelevanceDesc) | None => sortField("_score", Desc, missingLast = false) case Some(ByTitleAsc) => defaultSort("defaultTitle", "title", Asc, language) @@ -49,7 +49,7 @@ trait GrepSearchService { case Some(ByCodeDesc) => sortField("code", Desc, missingLast = false) } - protected def buildQuery(input: GrepSearchInput, searchLanguage: String): Query = { + protected def buildQuery(input: GrepSearchInputDTO, searchLanguage: String): Query = { val query = input.query .map { q => val langQueryFunc = (fieldName: String, boost: Double) => @@ -80,18 +80,18 @@ trait GrepSearchService { query.filter(getFilters(input)) } - private def getFilters(input: GrepSearchInput): List[Query] = + private def getFilters(input: GrepSearchInputDTO): List[Query] = List( idsFilter(input), prefixFilter(input) ).flatten - private def idsFilter(input: GrepSearchInput): Option[Query] = input.codes match { + private def idsFilter(input: GrepSearchInputDTO): Option[Query] = input.codes match { case Some(ids) if ids.nonEmpty => termsQuery("code", ids).some case _ => None } - private def prefixFilter(input: GrepSearchInput): Option[Query] = input.prefixFilter match { + private def prefixFilter(input: GrepSearchInputDTO): Option[Query] = input.prefixFilter match { case Some(prefixes) if prefixes.nonEmpty => Some( boolQuery().should( @@ -101,7 +101,7 @@ trait GrepSearchService { case _ => None } - def searchGreps(input: GrepSearchInput): Try[GrepSearchResults] = { + def searchGreps(input: GrepSearchInputDTO): Try[GrepSearchResultsDTO] = { val searchLanguage = input.language match { case Some(lang) if Iso639.get(lang).isSuccess => lang case _ => AllLanguages @@ -122,7 +122,7 @@ trait GrepSearchService { e4sClient.execute(searchToExecute).flatMap { response => getGrepHits(response, searchLanguage).map { results => - GrepSearchResults( + GrepSearchResultsDTO( totalCount = response.result.totalHits, page = pagination.page, pageSize = searchPageSize, @@ -133,22 +133,22 @@ trait GrepSearchService { } } - def hitToResult(hit: SearchHit, language: String): Try[GrepResult] = { + def hitToResult(hit: SearchHit, language: String): Try[GrepResultDTO] = { val jsonString = hit.sourceAsString val searchable = CirceUtil.tryParseAs[SearchableGrepElement](jsonString).? val titleLv = findByLanguageOrBestEffort(searchable.title.languageValues, language) .getOrElse(LanguageValue(Language.DefaultLanguage, "")) - val title = Title(title = titleLv.value, language = titleLv.language) + val title = TitleDTO(title = titleLv.value, language = titleLv.language) Success( - GrepResult( + GrepResultDTO( code = searchable.code, title = title ) ) } - def getGrepHits(response: RequestSuccess[SearchResponse], language: String): Try[List[GrepResult]] = { + def getGrepHits(response: RequestSuccess[SearchResponse], language: String): Try[List[GrepResultDTO]] = { response.result.hits.hits.toList.traverse { hit => hitToResult(hit, language) } } } diff --git a/search-api/src/main/scala/no/ndla/searchapi/service/search/MultiDraftSearchService.scala b/search-api/src/main/scala/no/ndla/searchapi/service/search/MultiDraftSearchService.scala index 31689a9a9..a500ee18e 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/service/search/MultiDraftSearchService.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/service/search/MultiDraftSearchService.scala @@ -23,7 +23,7 @@ import no.ndla.language.model.Iso639 import no.ndla.search.AggregationBuilder.{buildTermsAggregation, getAggregationsFromResult} import no.ndla.search.Elastic4sClient import no.ndla.searchapi.Props -import no.ndla.searchapi.model.api.{ErrorHandling, SubjectAggregation, SubjectAggregations} +import no.ndla.searchapi.model.api.{ErrorHandling, SubjectAggregationDTO, SubjectAggregationsDTO} import no.ndla.searchapi.model.domain.{LearningResourceType, SearchResult} import no.ndla.searchapi.model.search.SearchType import no.ndla.searchapi.model.search.settings.MultiDraftSearchSettings @@ -69,12 +69,12 @@ trait MultiDraftSearchService { } } - def aggregateSubjects(subjects: List[String]): Try[SubjectAggregations] = { + def aggregateSubjects(subjects: List[String]): Try[SubjectAggregationsDTO] = { val fiveYearsAgo = NDLADate.now().minusYears(5) val inOneYear = NDLADate.now().plusYears(1) val flowExcludeStatuses = List(DraftStatus.ARCHIVED, DraftStatus.PUBLISHED, DraftStatus.UNPUBLISHED) val flowStatuses = DraftStatus.values.filterNot(s => flowExcludeStatuses.contains(s)).toList - def aggregateSubject(subjectId: String): Try[SubjectAggregation] = for { + def aggregateSubject(subjectId: String): Try[SubjectAggregationDTO] = for { old <- filteredCountSearch( MultiDraftSearchSettings.default.copy( subjects = List(subjectId), @@ -100,7 +100,7 @@ trait MultiDraftSearchService { ) ) favorited <- aggregateFavorites(subjectId) - } yield SubjectAggregation( + } yield SubjectAggregationDTO( subjectId = subjectId, publishedArticleCount = publishedArticles, oldArticleCount = old, @@ -111,7 +111,7 @@ trait MultiDraftSearchService { subjects .traverse(subjectId => aggregateSubject(subjectId)) - .map(aggregations => SubjectAggregations(aggregations)) + .map(aggregations => SubjectAggregationsDTO(aggregations)) } private def getSearchIndexes(settings: MultiDraftSearchSettings): Try[List[String]] = { 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 04dd40b4c..1911a4f80 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 @@ -290,7 +290,7 @@ trait SearchConverterService { val supportedLanguages = getSupportedLanguages(lp.title, lp.description).toList val defaultTitle = lp.title.sortBy(title => ISO639.languagePriority.reverse.indexOf(title.language)).lastOption - val license = api.learningpath.Copyright( + val license = api.learningpath.CopyrightDTO( asLearningPathApiLicense(lp.copyright.license), lp.copyright.contributors.map(c => AuthorDTO(c.`type`, c.name)) ) @@ -352,7 +352,7 @@ trait SearchConverterService { val users: Seq[String] = c.updatedBy ++ c.editorNotes.map(_.user) - val status = Status(c.status.current.toString, c.status.other.map(_.toString).toSeq) + val status = StatusDTO(c.status.current.toString, c.status.other.map(_.toString).toSeq) Success( SearchableConcept( @@ -588,9 +588,9 @@ trait SearchConverterService { } } - private def getHighlights(highlights: Map[String, Seq[String]]): List[HighlightedField] = { + private def getHighlights(highlights: Map[String, Seq[String]]): List[HighlightedFieldDTO] = { highlights.map { case (field, matches) => - HighlightedField( + HighlightedFieldDTO( field = field, matches = matches ) @@ -605,39 +605,39 @@ trait SearchConverterService { contexts: List[SearchableTaxonomyContext], language: String, filterInactive: Boolean - ): List[ApiTaxonomyContext] = { + ): List[ApiTaxonomyContextDTO] = { val filtered = if (filterInactive) contexts.filter(c => c.isActive) else contexts filtered.sortBy(!_.isPrimary).map(c => searchableContextToApiContext(c, language)) } - def articleHitAsMultiSummary(hit: SearchHit, language: String, filterInactive: Boolean): MultiSearchSummary = { + def articleHitAsMultiSummary(hit: SearchHit, language: String, filterInactive: Boolean): MultiSearchSummaryDTO = { val searchableArticle = CirceUtil.unsafeParseAs[SearchableArticle](hit.sourceAsString) val contexts = filterContexts(searchableArticle.contexts, language, filterInactive) val titles = searchableArticle.domainObject.title.map(title => - api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) + api.TitleWithHtmlDTO(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) ) val introductions = searchableArticle.domainObject.introduction.map(intro => api.article - .ArticleIntroduction( + .ArticleIntroductionDTO( Jsoup.parseBodyFragment(intro.introduction).body().text(), intro.introduction, intro.language ) ) val metaDescriptions = - searchableArticle.metaDescription.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) + searchableArticle.metaDescription.languageValues.map(lv => api.MetaDescriptionDTO(lv.value, lv.language)) val visualElements = - searchableArticle.visualElement.languageValues.map(lv => api.article.VisualElement(lv.value, lv.language)) + searchableArticle.visualElement.languageValues.map(lv => api.article.VisualElementDTO(lv.value, lv.language)) val metaImages = searchableArticle.metaImage.map(image => { val metaImageUrl = s"${props.ExternalApiUrls("raw-image")}/${image.imageId}" - api.MetaImage(metaImageUrl, image.altText, image.language) + api.MetaImageDTO(metaImageUrl, image.altText, image.language) }) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtmlDTO("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( - api.MetaDescription("", UnknownLanguage.toString) + api.MetaDescriptionDTO("", UnknownLanguage.toString) ) val metaImage = findByLanguageOrBestEffort(metaImages, language) @@ -645,7 +645,7 @@ trait SearchConverterService { val url = s"${props.ExternalApiUrls("article-api")}/${searchableArticle.id}" - MultiSearchSummary( + MultiSearchSummaryDTO( id = searchableArticle.id, title = title, metaDescription = metaDescription, @@ -676,41 +676,41 @@ trait SearchConverterService { ) } - def draftHitAsMultiSummary(hit: SearchHit, language: String, filterInactive: Boolean): MultiSearchSummary = { + def draftHitAsMultiSummary(hit: SearchHit, language: String, filterInactive: Boolean): MultiSearchSummaryDTO = { val searchableDraft = CirceUtil.unsafeParseAs[SearchableDraft](hit.sourceAsString) val contexts = filterContexts(searchableDraft.contexts, language, filterInactive) val titles = searchableDraft.domainObject.title.map(title => - api.TitleWithHtml(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) + api.TitleWithHtmlDTO(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language) ) val introductions = searchableDraft.domainObject.introduction.map(intro => api.article - .ArticleIntroduction( + .ArticleIntroductionDTO( Jsoup.parseBodyFragment(intro.introduction).body().text(), intro.introduction, intro.language ) ) val metaDescriptions = - searchableDraft.metaDescription.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) + searchableDraft.metaDescription.languageValues.map(lv => api.MetaDescriptionDTO(lv.value, lv.language)) val visualElements = - searchableDraft.visualElement.languageValues.map(lv => api.article.VisualElement(lv.value, lv.language)) + searchableDraft.visualElement.languageValues.map(lv => api.article.VisualElementDTO(lv.value, lv.language)) val metaImages = searchableDraft.domainObject.metaImage.map(image => { val metaImageUrl = s"${props.ExternalApiUrls("raw-image")}/${image.imageId}" - api.MetaImage(metaImageUrl, image.altText, image.language) + api.MetaImageDTO(metaImageUrl, image.altText, image.language) }) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtmlDTO("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( - api.MetaDescription("", UnknownLanguage.toString) + api.MetaDescriptionDTO("", UnknownLanguage.toString) ) val metaImage = findByLanguageOrBestEffort(metaImages, language) val supportedLanguages = getSupportedLanguages(titles, visualElements, introductions, metaDescriptions) val url = s"${props.ExternalApiUrls("draft-api")}/${searchableDraft.id}" val revisions = - searchableDraft.revisionMeta.map(m => api.RevisionMeta(m.revisionDate, m.note, m.status.entryName)) - val responsible = searchableDraft.responsible.map(r => api.DraftResponsible(r.responsibleId, r.lastUpdated)) + searchableDraft.revisionMeta.map(m => api.RevisionMetaDTO(m.revisionDate, m.note, m.status.entryName)) + val responsible = searchableDraft.responsible.map(r => api.DraftResponsibleDTO(r.responsibleId, r.lastUpdated)) val comments = searchableDraft.domainObject.comments.map(c => CommentDTO(c.id.toString, c.content, c.created, c.updated, c.isOpen, c.solved) @@ -720,7 +720,7 @@ trait SearchConverterService { val parentTopicName = searchableDraft.parentTopicName.getLanguageOrDefault(language) val primaryRootName = searchableDraft.primaryRoot.getLanguageOrDefault(language) - MultiSearchSummary( + MultiSearchSummaryDTO( id = searchableDraft.id, title = title, metaDescription = metaDescription, @@ -729,7 +729,7 @@ trait SearchConverterService { contexts = contexts, supportedLanguages = supportedLanguages, learningResourceType = searchableDraft.learningResourceType, - status = Some(api.Status(searchableDraft.draftStatus.current, searchableDraft.draftStatus.other)), + status = Some(api.StatusDTO(searchableDraft.draftStatus.current, searchableDraft.draftStatus.other)), traits = searchableDraft.traits, score = hit.score, highlights = getHighlights(hit.highlight), @@ -751,35 +751,41 @@ trait SearchConverterService { ) } - def learningpathHitAsMultiSummary(hit: SearchHit, language: String, filterInactive: Boolean): MultiSearchSummary = { + def learningpathHitAsMultiSummary( + hit: SearchHit, + language: String, + filterInactive: Boolean + ): MultiSearchSummaryDTO = { val searchableLearningPath = CirceUtil.unsafeParseAs[SearchableLearningPath](hit.sourceAsString) val contexts = filterContexts(searchableLearningPath.contexts, language, filterInactive) val titles = - searchableLearningPath.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language)) + searchableLearningPath.title.languageValues.map(lv => api.TitleWithHtmlDTO(lv.value, lv.value, lv.language)) val metaDescriptions = - searchableLearningPath.description.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) + searchableLearningPath.description.languageValues.map(lv => api.MetaDescriptionDTO(lv.value, lv.language)) val tags = - searchableLearningPath.tags.languageValues.map(lv => api.learningpath.LearningPathTags(lv.value, lv.language)) + searchableLearningPath.tags.languageValues.map(lv => + api.learningpath.LearningPathTagsDTO(lv.value, lv.language) + ) val supportedLanguages = getSupportedLanguages(titles, metaDescriptions, tags) val title = - findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtml("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtmlDTO("", "", UnknownLanguage.toString)) val metaDescription = findByLanguageOrBestEffort(metaDescriptions, language).getOrElse( - api.MetaDescription("", UnknownLanguage.toString) + api.MetaDescriptionDTO("", UnknownLanguage.toString) ) val url = s"${props.ExternalApiUrls("learningpath-api")}/${searchableLearningPath.id}" val metaImage = searchableLearningPath.coverPhotoId.map(id => - api.MetaImage( + api.MetaImageDTO( url = s"${props.ExternalApiUrls("raw-image")}/$id", alt = "", language = language ) ) - MultiSearchSummary( + MultiSearchSummaryDTO( id = searchableLearningPath.id, title = title, metaDescription = metaDescription, @@ -788,7 +794,7 @@ trait SearchConverterService { contexts = contexts, supportedLanguages = supportedLanguages, learningResourceType = LearningResourceType.LearningPath, - status = Some(api.Status(searchableLearningPath.status, Seq.empty)), + status = Some(api.StatusDTO(searchableLearningPath.status, Seq.empty)), traits = List.empty, score = hit.score, highlights = getHighlights(hit.highlight), @@ -810,31 +816,32 @@ trait SearchConverterService { ) } - def conceptHitAsMultiSummary(hit: SearchHit, language: String): MultiSearchSummary = { + def conceptHitAsMultiSummary(hit: SearchHit, language: String): MultiSearchSummaryDTO = { val searchableConcept = CirceUtil.unsafeParseAs[SearchableConcept](hit.sourceAsString) - val titles = searchableConcept.title.languageValues.map(lv => api.TitleWithHtml(lv.value, lv.value, lv.language)) + val titles = + searchableConcept.title.languageValues.map(lv => api.TitleWithHtmlDTO(lv.value, lv.value, lv.language)) - val content = searchableConcept.content.languageValues.map(lv => api.MetaDescription(lv.value, lv.language)) + val content = searchableConcept.content.languageValues.map(lv => api.MetaDescriptionDTO(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.TitleWithHtml("", "", UnknownLanguage.toString)) + findByLanguageOrBestEffort(titles, language).getOrElse(api.TitleWithHtmlDTO("", "", 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) + api.MetaImageDTO(metaImageUrl, image.altText, image.language) }) val metaImage = findByLanguageOrBestEffort(metaImages, language) - val responsible = searchableConcept.responsible.map(r => api.DraftResponsible(r.responsibleId, r.lastUpdated)) + val responsible = searchableConcept.responsible.map(r => api.DraftResponsibleDTO(r.responsibleId, r.lastUpdated)) val metaDescription = findByLanguageOrBestEffort(content, language).getOrElse( - api.MetaDescription("", UnknownLanguage.toString) + api.MetaDescriptionDTO("", UnknownLanguage.toString) ) - MultiSearchSummary( + MultiSearchSummaryDTO( id = searchableConcept.id, title = title, metaDescription = metaDescription, @@ -868,7 +875,7 @@ trait SearchConverterService { private def searchableContextToApiContext( context: SearchableTaxonomyContext, language: String - ): ApiTaxonomyContext = { + ): ApiTaxonomyContextDTO = { val subjectName = findByLanguageOrBestEffort(context.root.languageValues, language).map(_.value).getOrElse("") val breadcrumbs = findByLanguageOrBestEffort(context.breadcrumbs.languageValues, language) .map(_.value) @@ -878,12 +885,12 @@ trait SearchConverterService { val resourceTypes = context.resourceTypes.map(rt => { val name = findByLanguageOrBestEffort(rt.name.languageValues, language) .getOrElse(LanguageValue(UnknownLanguage.toString, "")) - TaxonomyResourceType(id = rt.id, name = name.value, language = name.language) + TaxonomyResourceTypeDTO(id = rt.id, name = name.value, language = name.language) }) val relevance = findByLanguageOrBestEffort(context.relevance.languageValues, language).map(_.value).getOrElse("") - ApiTaxonomyContext( + ApiTaxonomyContextDTO( publicId = context.publicId, root = subjectName, rootId = context.rootId, @@ -959,8 +966,8 @@ trait SearchConverterService { } } - def toApiMultiSearchResult(searchResult: domain.SearchResult): MultiSearchResult = - api.MultiSearchResult( + def toApiMultiSearchResult(searchResult: domain.SearchResult): MultiSearchResultDTO = + api.MultiSearchResultDTO( searchResult.totalCount, searchResult.page, searchResult.pageSize, @@ -970,8 +977,8 @@ trait SearchConverterService { searchResult.aggregations.map(toApiMultiTermsAggregation) ) - def toApiGroupMultiSearchResult(group: String, searchResult: domain.SearchResult): GroupSearchResult = - api.GroupSearchResult( + def toApiGroupMultiSearchResult(group: String, searchResult: domain.SearchResult): GroupSearchResultDTO = + api.GroupSearchResultDTO( searchResult.totalCount, searchResult.page, searchResult.pageSize, diff --git a/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchService.scala b/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchService.scala index e78e1381a..23e099bc6 100644 --- a/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchService.scala +++ b/search-api/src/main/scala/no/ndla/searchapi/service/search/SearchService.scala @@ -25,10 +25,10 @@ import no.ndla.search.{BaseIndexService, Elastic4sClient, NdlaSearchException, S import no.ndla.searchapi.Props import no.ndla.searchapi.model.api.{ ErrorHandling, - MultiSearchSuggestion, - MultiSearchSummary, - SearchSuggestion, - SuggestOption + MultiSearchSuggestionDTO, + MultiSearchSummaryDTO, + SearchSuggestionDTO, + SuggestOptionDTO } import no.ndla.searchapi.model.domain.Sort.* import no.ndla.searchapi.model.domain.* @@ -55,7 +55,7 @@ trait SearchService { * @return * api-model summary of hit */ - private def hitToApiModel(hit: SearchHit, language: String, filterInactive: Boolean): Try[MultiSearchSummary] = { + private def hitToApiModel(hit: SearchHit, language: String, filterInactive: Boolean): Try[MultiSearchSummaryDTO] = { val indexName = hit.index.split("_").headOption.traverse(x => props.indexToSearchType(x)) indexName.flatMap { case Some(SearchType.Articles) => @@ -143,7 +143,7 @@ trait SearchService { response: SearchResponse, language: String, filterInactive: Boolean - ): Try[Seq[MultiSearchSummary]] = { + ): Try[Seq[MultiSearchSummaryDTO]] = { response.totalHits match { case count if count > 0 => val resultArray = response.hits.hits.toList @@ -181,15 +181,15 @@ trait SearchService { .text(query) } - protected def getSuggestions(response: SearchResponse): Seq[MultiSearchSuggestion] = { + protected def getSuggestions(response: SearchResponse): Seq[MultiSearchSuggestionDTO] = { response.suggestions.map { case (key, value) => - MultiSearchSuggestion(name = key, suggestions = getSuggestion(value)) + MultiSearchSuggestionDTO(name = key, suggestions = getSuggestion(value)) }.toSeq } - private def getSuggestion(results: Seq[SuggestionResult]): Seq[SearchSuggestion] = { + private def getSuggestion(results: Seq[SuggestionResult]): Seq[SearchSuggestionDTO] = { results.map(result => - SearchSuggestion( + SearchSuggestionDTO( text = result.text, offset = result.offset, length = result.length, @@ -198,10 +198,10 @@ trait SearchService { ) } - private def mapToSuggestOption(optionsMap: Map[String, Any]): SuggestOption = { + private def mapToSuggestOption(optionsMap: Map[String, Any]): SuggestOptionDTO = { val text = optionsMap.getOrElse("text", "") val score = optionsMap.getOrElse("score", 1) - SuggestOption( + SuggestOptionDTO( text.asInstanceOf[String], score.asInstanceOf[Double] ) diff --git a/search-api/src/test/scala/no/ndla/searchapi/model/search/SearchableLearningPathTest.scala b/search-api/src/test/scala/no/ndla/searchapi/model/search/SearchableLearningPathTest.scala index 419c124e3..8a78daf21 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/model/search/SearchableLearningPathTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/model/search/SearchableLearningPathTest.scala @@ -11,7 +11,7 @@ import no.ndla.common.CirceUtil import no.ndla.common.model.api.{AuthorDTO, LicenseDTO} import no.ndla.common.model.domain.learningpath.{LearningPathStatus, LearningPathVerificationStatus, StepType} import no.ndla.search.model.{LanguageValue, SearchableLanguageList, SearchableLanguageValues} -import no.ndla.searchapi.model.api.learningpath.Copyright +import no.ndla.searchapi.model.api.learningpath.CopyrightDTO import no.ndla.searchapi.{TestData, TestEnvironment, UnitSuite} import no.ndla.searchapi.TestData.* import no.ndla.searchapi.model.domain.LearningResourceType @@ -55,7 +55,7 @@ class SearchableLearningPathTest extends UnitSuite with TestEnvironment { defaultTitle = Some("Christian Tut"), tags = tags, learningsteps = learningsteps, - copyright = Copyright( + copyright = CopyrightDTO( LicenseDTO("by-sa", Some("bysasaa"), None), Seq(AuthorDTO("Supplier", "Jonas"), AuthorDTO("Originator", "Kakemonsteret")) ), diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/ConverterServiceTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/ConverterServiceTest.scala index d2bbe619c..94b5865ea 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/ConverterServiceTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/ConverterServiceTest.scala @@ -16,9 +16,9 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment { override val converterService = new ConverterService test("searchResultToApiModel should return the api model of the corresponding input domain model") { - converterService.searchResultToApiModel(TestData.sampleArticleSearch).isInstanceOf[api.ArticleResults] - converterService.searchResultToApiModel(TestData.sampleLearningpath).isInstanceOf[api.LearningpathResults] - converterService.searchResultToApiModel(TestData.sampleImageSearch).isInstanceOf[api.ImageResults] - converterService.searchResultToApiModel(TestData.sampleAudio).isInstanceOf[api.AudioResults] + converterService.searchResultToApiModel(TestData.sampleArticleSearch).isInstanceOf[api.ArticleResultsDTO] + converterService.searchResultToApiModel(TestData.sampleLearningpath).isInstanceOf[api.LearningpathResultsDTO] + converterService.searchResultToApiModel(TestData.sampleImageSearch).isInstanceOf[api.ImageResultsDTO] + converterService.searchResultToApiModel(TestData.sampleAudio).isInstanceOf[api.AudioResultsDTO] } } diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/search/DraftConceptIndexServiceTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/search/DraftConceptIndexServiceTest.scala index 91a1f86c5..021472c52 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/search/DraftConceptIndexServiceTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/search/DraftConceptIndexServiceTest.scala @@ -53,7 +53,7 @@ class DraftConceptIndexServiceTest tags = languageList, subjectIds = List("urn:subject:1"), lastUpdated = now, - draftStatus = api.Status("IN_PROGRESS", Seq("PUBLISHED")), + draftStatus = api.StatusDTO("IN_PROGRESS", Seq("PUBLISHED")), users = List("noen", "some-id"), updatedBy = Seq("noen"), license = Some("CC-BY-SA-4.0"), diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/search/GrepSearchServiceTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/search/GrepSearchServiceTest.scala index e62abe331..b434947cf 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/search/GrepSearchServiceTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/search/GrepSearchServiceTest.scala @@ -11,8 +11,8 @@ import cats.implicits.catsSyntaxOptionId import no.ndla.network.tapir.NonEmptyString import no.ndla.scalatestsuite.IntegrationSuite import no.ndla.searchapi.TestEnvironment -import no.ndla.searchapi.controller.parameters.GrepSearchInput -import no.ndla.searchapi.model.api.grep.GrepSort.{ByCodeAsc, ByCodeDesc} +import no.ndla.searchapi.controller.parameters.GrepSearchInputDTO +import no.ndla.searchapi.model.api.grep.GrepSortDTO.{ByCodeAsc, ByCodeDesc} import no.ndla.searchapi.model.grep.{GrepBundle, GrepElement, GrepTitle} class GrepSearchServiceTest extends IntegrationSuite(EnableElasticsearchContainer = true) with TestEnvironment { @@ -66,7 +66,7 @@ class GrepSearchServiceTest extends IntegrationSuite(EnableElasticsearchContaine ) ) - val emptyInput: GrepSearchInput = GrepSearchInput( + val emptyInput: GrepSearchInputDTO = GrepSearchInputDTO( codes = None, language = None, page = None, diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceAtomicTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceAtomicTest.scala index 73d72a706..8a926786f 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceAtomicTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceAtomicTest.scala @@ -20,7 +20,7 @@ import no.ndla.network.tapir.NonEmptyString import no.ndla.scalatestsuite.IntegrationSuite import no.ndla.search.model.{LanguageValue, SearchableLanguageList, SearchableLanguageValues} import no.ndla.searchapi.TestData.* -import no.ndla.searchapi.model.api.ApiTaxonomyContext +import no.ndla.searchapi.model.api.ApiTaxonomyContextDTO import no.ndla.searchapi.model.domain.{IndexingBundle, LearningResourceType, Sort} import no.ndla.searchapi.model.search.SearchType import no.ndla.searchapi.model.taxonomy.* @@ -721,8 +721,8 @@ class MultiDraftSearchServiceAtomicTest val result = multiDraftSearchService.matchingQuery(multiDraftSearchSettings).get - def ctxsFor(id: Long): List[ApiTaxonomyContext] = result.results.find(_.id == id).get.contexts - def ctxFor(id: Long): ApiTaxonomyContext = { + def ctxsFor(id: Long): List[ApiTaxonomyContextDTO] = result.results.find(_.id == id).get.contexts + def ctxFor(id: Long): ApiTaxonomyContextDTO = { val ctxs = ctxsFor(id) ctxs.length should be(1) ctxs.head diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceTest.scala index a0ed1c511..568993ef5 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiDraftSearchServiceTest.scala @@ -14,7 +14,7 @@ import no.ndla.language.Language.AllLanguages import no.ndla.network.tapir.NonEmptyString import no.ndla.scalatestsuite.IntegrationSuite import no.ndla.searchapi.TestData.* -import no.ndla.searchapi.model.api.MetaImage +import no.ndla.searchapi.model.api.MetaImageDTO import no.ndla.searchapi.model.domain.{IndexingBundle, LearningResourceType, Sort} import no.ndla.searchapi.model.search.SearchPagination import no.ndla.searchapi.{TestData, TestEnvironment} @@ -620,7 +620,7 @@ class MultiDraftSearchServiceTest extends IntegrationSuite(EnableElasticsearchCo search.totalCount should be(1) search.results.head.id should be(10) search.results.head.metaImage should be( - Some(MetaImage("http://api-gateway.ndla-local/image-api/raw/id/123", "alt", "en")) + Some(MetaImageDTO("http://api-gateway.ndla-local/image-api/raw/id/123", "alt", "en")) ) } diff --git a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiSearchServiceTest.scala b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiSearchServiceTest.scala index 5f2f3da14..29695bff3 100644 --- a/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiSearchServiceTest.scala +++ b/search-api/src/test/scala/no/ndla/searchapi/service/search/MultiSearchServiceTest.scala @@ -15,7 +15,7 @@ import no.ndla.language.Language.AllLanguages import no.ndla.network.tapir.NonEmptyString import no.ndla.scalatestsuite.IntegrationSuite import no.ndla.searchapi.TestData.* -import no.ndla.searchapi.model.api.MetaImage +import no.ndla.searchapi.model.api.MetaImageDTO import no.ndla.searchapi.model.domain.{IndexingBundle, LearningResourceType, Sort} import no.ndla.searchapi.model.search.SearchPagination import no.ndla.searchapi.{TestData, TestEnvironment, UnitSuite} @@ -589,7 +589,7 @@ class MultiSearchServiceTest search.totalCount should be(1) search.results.head.id should be(10) search.results.head.metaImage should be( - Some(MetaImage("http://api-gateway.ndla-local/image-api/raw/id/442", "alt", "en")) + Some(MetaImageDTO("http://api-gateway.ndla-local/image-api/raw/id/442", "alt", "en")) ) }