Skip to content

Commit b193ddb

Browse files
committed
Add item and collection creation endpoints
1 parent 7630412 commit b193ddb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ lazy val client = crossProject(JSPlatform, JVMPlatform)
217217
"org.locationtech.geotrellis" %% "geotrellis-vector" % Versions.GeoTrellisVersion,
218218
"org.locationtech.jts" % "jts-core" % Versions.Jts,
219219
"org.typelevel" %% "cats-core" % Versions.CatsVersion,
220+
"com.softwaremill.sttp.client3" %% "core" % "3.0.0-RC13",
220221
"co.fs2" %% "fs2-core" % "2.4.2",
221222
"org.http4s" %% "http4s-blaze-client" % "0.21.7",
222223
"org.http4s" %% "http4s-circe" % "0.21.7",

modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/Http4sStacClient.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.azavea.stac4s.{StacCollection, StacItem}
55
import cats.effect.{ConcurrentEffect, Resource, Sync}
66
import cats.syntax.apply._
77
import cats.syntax.either._
8+
import cats.syntax.flatMap._
89
import cats.syntax.functor._
910
import eu.timepit.refined.types.string.NonEmptyString
1011
import io.chrisdavenport.log4cats.Logger
@@ -54,6 +55,26 @@ case class Http4sStacClient[F[_]: Sync: Logger](
5455
client
5556
.expect(getRequest.withUri(baseUri.withPath(s"/collections/$collectionId/items/$itemId")))
5657
.map(_.as[Option[StacItem]].bimap(_ => None, identity).merge)
58+
59+
def itemCreate(collectionId: NonEmptyString, item: StacItem): F[StacItem] =
60+
logger.trace(s"createItem: $collectionId, $item") *>
61+
client
62+
.expect(
63+
postRequest
64+
.withUri(baseUri.withPath(s"/collections/$collectionId/items"))
65+
.withEntity(item.asJson.noSpaces)
66+
)
67+
.flatMap { json => Sync[F].fromEither(json.as[StacItem].leftMap(_.getCause)) }
68+
69+
def collectionCreate(collection: StacCollection): F[StacCollection] =
70+
logger.trace(s"createCollection: $collection") *>
71+
client
72+
.expect(
73+
postRequest
74+
.withUri(baseUri.withPath(s"/collections/"))
75+
.withEntity(collection.asJson.noSpaces)
76+
)
77+
.flatMap { json => Sync[F].fromEither(json.as[StacCollection].leftMap(_.getCause)) }
5778
}
5879

5980
object Http4sStacClient {

modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/StacClient.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ trait StacClient[F[_]] {
2626
def collection(collectionId: NonEmptyString): F[Option[StacCollection]]
2727
def items(collectionId: NonEmptyString): F[List[StacItem]]
2828
def item(collectionId: NonEmptyString, itemId: NonEmptyString): F[Option[StacItem]]
29+
def itemCreate(collectionId: NonEmptyString, item: StacItem): F[StacItem]
30+
def collectionCreate(collection: StacCollection): F[StacCollection]
2931
}

0 commit comments

Comments
 (0)