Skip to content

Commit

Permalink
Return results as an object
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Feb 28, 2024
1 parent 824d284 commit b8d7e9f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package io.renku.search.api.data
import io.bullet.borer.Encoder
import io.bullet.borer.derivation.MapBasedCodecs
import io.bullet.borer.Decoder
import sttp.tapir.Schema

final case class PageDef(
limit: Int,
Expand All @@ -40,3 +41,4 @@ object PageDef:

given Encoder[PageDef] = MapBasedCodecs.deriveEncoder
given Decoder[PageDef] = MapBasedCodecs.deriveDecoder
given Schema[PageDef] = Schema.derived
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package io.renku.search.api.data

import io.bullet.borer.{Decoder, Encoder}
import io.bullet.borer.NullOptions.given
import io.bullet.borer.derivation.MapBasedCodecs
import sttp.tapir.Schema

final case class PageWithTotals(
page: PageDef,
prevPage: Option[Int],
Expand All @@ -27,6 +32,10 @@ final case class PageWithTotals(
)

object PageWithTotals:
given Encoder[PageWithTotals] = MapBasedCodecs.deriveEncoder
given Decoder[PageWithTotals] = MapBasedCodecs.deriveDecoder
given Schema[PageWithTotals] = Schema.derived

def apply(page: PageDef, totalResults: Long, hasMore: Boolean): PageWithTotals =
PageWithTotals(
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@

package io.renku.search.api.data

import io.bullet.borer.derivation.MapBasedCodecs
import io.bullet.borer.Encoder
import io.bullet.borer.Decoder
import sttp.tapir.Schema

final case class SearchResult(
items: Seq[SearchEntity],
pagingInfo: PageWithTotals
)

object SearchResult:
given Encoder[SearchResult] = MapBasedCodecs.deriveEncoder
given Decoder[SearchResult] = MapBasedCodecs.deriveDecoder
given Schema[SearchResult] = Schema.derived
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ object Params extends TapirCodecs with TapirBorerJson {
borerJsonBody[Seq[SearchEntity]]

val searchResult: EndpointOutput[SearchResult] =
searchItems.and(pagingInfo).mapTo[SearchResult]
borerJsonBody[SearchResult].and(pagingInfo).map(_._1)(r => (r, r.pagingInfo))
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ trait TapirCodecs:
Codec.string.mapEither(Query.parse(_))(_.render)

given Schema[Query] = Schema.anyObject[Query]
given Schema[PageDef] = Schema.derived
given Schema[QueryInput] = Schema.derived
2 changes: 1 addition & 1 deletion nix/openapi-doc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: 'http://localhost:8080/search/spec.json',
url: 'http://localhost:8080/apiv2/search/spec.json',
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
Expand Down

0 comments on commit b8d7e9f

Please sign in to comment.