Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a correct content type to POST requests and SearchFilters adjustments #359

Merged
merged 5 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
### Changed
- Add a correct content type to POST requests and SearchFilters adjustments [#359](https://github.com/azavea/stac4s/pull/359)

## [0.6.0] - 2021-07-01
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.azavea.stac4s.api.client.util.ClientCodecs
import com.azavea.stac4s.geometry.Geometry
import com.azavea.stac4s.{Bbox, TemporalExtent}

import cats.syntax.option._
import eu.timepit.refined.types.numeric.NonNegInt
import io.circe._
import io.circe.refined._
Expand Down Expand Up @@ -39,8 +40,8 @@ object SearchFilters extends ClientCodecs {
bbox,
datetime,
intersects,
collectionsOption.getOrElse(Nil),
itemsOption.getOrElse(Nil),
collectionsOption getOrElse Nil,
jisantuc marked this conversation as resolved.
Show resolved Hide resolved
itemsOption getOrElse Nil,
limit,
query getOrElse Map.empty,
paginationToken
Expand All @@ -62,10 +63,10 @@ object SearchFilters extends ClientCodecs {
filters.bbox,
filters.datetime,
filters.intersects,
filters.collections,
filters.items,
filters.collections.some.filter(_.nonEmpty),
filters.items.some.filter(_.nonEmpty),
filters.limit,
filters.query,
filters.query.some.filter(_.nonEmpty),
filters.next
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.azavea.stac4s.api.client
import com.azavea.stac4s.api.client.util.ClientCodecs
import com.azavea.stac4s.{Bbox, TemporalExtent}

import cats.syntax.option._
import eu.timepit.refined.types.numeric.NonNegInt
import geotrellis.vector.{io => _, _}
import io.circe._
Expand Down Expand Up @@ -39,8 +40,8 @@ object SearchFilters extends ClientCodecs {
bbox,
datetime,
intersects,
collectionsOption.getOrElse(Nil),
itemsOption.getOrElse(Nil),
collectionsOption getOrElse Nil,
itemsOption getOrElse Nil,
limit,
query getOrElse Map.empty,
paginationToken
Expand All @@ -62,10 +63,10 @@ object SearchFilters extends ClientCodecs {
filters.bbox,
filters.datetime,
filters.intersects,
filters.collections,
filters.items,
filters.collections.some.filter(_.nonEmpty),
filters.items.some.filter(_.nonEmpty),
filters.limit,
filters.query,
filters.query.some.filter(_.nonEmpty),
jisantuc marked this conversation as resolved.
Show resolved Hide resolved
filters.next
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.circe.{Encoder, Json, JsonObject}
import monocle.Lens
import sttp.client3.circe.asJson
import sttp.client3.{Response, SttpBackend, UriContext, basicRequest}
import sttp.model.Uri
import sttp.model.{MediaType, Uri}

case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]]: Encoder](
client: SttpBackend[F, Any],
Expand All @@ -40,7 +40,13 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]]
Stream
.unfoldLoopEval((baseUri.addPath("search"), initialBody)) { case (link, request) =>
client
.send(basicRequest.body(request.noSpaces).post(link).response(asJson[Json]))
.send(
basicRequest
.post(link)
.contentType(MediaType.ApplicationJson)
jisantuc marked this conversation as resolved.
Show resolved Hide resolved
.body(request.deepDropNullValues.noSpaces)
.response(asJson[Json])
)
.flatMap { response =>
val items = response.stacItems
val next = response.nextLink.nested.map(_ -> noPaginationBody).value
Expand Down Expand Up @@ -77,6 +83,7 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]]
.send(
basicRequest
.post(baseUri.addPath("collections"))
.contentType(MediaType.ApplicationJson)
.body(collection.asJson.noSpaces)
.response(asJson[StacCollection])
)
Expand Down Expand Up @@ -109,6 +116,7 @@ case class SttpStacClientF[F[_]: MonadThrow, S: Lens[*, Option[PaginationToken]]
.send(
basicRequest
.post(baseUri.addPath("collections", collectionId.value, "items"))
.contentType(MediaType.ApplicationJson)
.body(item.asJson.noSpaces)
.response(asJson[StacItem])
)
Expand Down