Skip to content

Commit

Permalink
image-api: Keep includeCopyrighted as a flag
Browse files Browse the repository at this point in the history
For backwards compatibility. If `license` is provided this is used instead.
  • Loading branch information
jnatten committed Jan 13, 2025
1 parent 4c5d403 commit c455226
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ trait BaseImageController {
val license: EndpointInput.Query[Option[String]] =
query[Option[String]]("license")
.description("Return only images with provided license.")
val includeCopyrighted: EndpointInput.Query[Boolean] =
query[Boolean]("includeCopyrighted")
.description("Return copyrighted images. May be omitted.")
.deprecated()
.default(false)
val sort: EndpointInput.Query[Option[String]] = query[Option[String]]("sort")
.description(
s"""The sorting used on results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ trait ImageControllerV2 {
val language = searchParams.language.getOrElse(Language.AllLanguages)
val fallback = searchParams.fallback.getOrElse(false)
scrollSearchOr(searchParams.scrollId, language, user) {
val minimumSize = searchParams.minimumSize
val query = searchParams.query
val license = searchParams.license
val pageSize = searchParams.pageSize
val page = searchParams.page
val minimumSize = searchParams.minimumSize
val query = searchParams.query
val license = searchParams.license.orElse(Option.when(searchParams.includeCopyrighted.contains(true))("all"))
val pageSize = searchParams.pageSize
val page = searchParams.page
val podcastFriendly = searchParams.podcastFriendly
val sort = searchParams.sort
val shouldScroll = searchParams.scrollId.exists(InitialScrollContextKeywords.contains)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ trait ImageControllerV3 {
.in(language)
.in(fallback)
.in(license)
.in(includeCopyrighted)
.in(sort)
.in(pageNo)
.in(pageSize)
Expand All @@ -149,6 +150,7 @@ trait ImageControllerV3 {
language,
fallback,
license,
includeCopyrighted,
sortStr,
pageNo,
pageSize,
Expand All @@ -160,13 +162,14 @@ trait ImageControllerV3 {
val sort = Sort.valueOf(sortStr)
val shouldScroll = scrollId.exists(InitialScrollContextKeywords.contains)
val modelReleasedStatus = modelReleased.values.flatMap(ModelReleasedStatus.valueOf)
val licenseOpt = license.orElse(Option.when(includeCopyrighted)("all"))

searchV3(
minimumSize,
query,
language,
fallback,
license,
licenseOpt,
sort,
pageSize,
pageNo,
Expand Down Expand Up @@ -195,9 +198,11 @@ trait ImageControllerV3 {
val fallback = searchParams.fallback.getOrElse(false)

scrollSearchOr(searchParams.scrollId, language, user) {
val minimumSize = searchParams.minimumSize
val query = searchParams.query
val license = searchParams.license
val minimumSize = searchParams.minimumSize
val query = searchParams.query
val license = searchParams.license.orElse {
Option.when(searchParams.includeCopyrighted.contains(true))("all")
}
val pageSize = searchParams.pageSize
val page = searchParams.page
val podcastFriendly = searchParams.podcastFriendly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.imageapi.model.api
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.imageapi.model.domain.Sort
import sttp.tapir.Schema.annotations.description
import sttp.tapir.Schema.annotations.{description, deprecated}

// format: off
@description("The search parameters")
Expand All @@ -20,6 +20,7 @@ case class SearchParamsDTO(
@description("The ISO 639-1 language code describing language used in query-params") language: Option[String],
@description("Fallback to existing language if language is specified.") fallback: Option[Boolean],
@description("Return only images with full size larger than submitted value in bytes.") minimumSize: Option[Int],
@deprecated @description("Return copyrighted images. May be omitted.") includeCopyrighted: Option[Boolean],
@description("""The sorting used on results. The following are supported: relevance, -relevance, title, -title, lastUpdated, -lastUpdated, id, -id. Default is by -relevance (desc) when query is set, and title (asc) when query is empty.""") sort: Option[Sort],
@description("The page number of the search hits to display.") page: Option[Int],
@description("The number of search hits to display for each page.") pageSize: Option[Int],
Expand Down

0 comments on commit c455226

Please # to comment.