Skip to content

Commit

Permalink
Move Document to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
dbulaja98 committed Nov 25, 2022
1 parent cc2d8e0 commit 027b50a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
15 changes: 15 additions & 0 deletions modules/library/src/main/scala/zio/elasticsearch/Document.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package zio.elasticsearch

import zio.schema.Schema
import zio.schema.codec.JsonCodec.JsonDecoder
import zio.schema.codec.{DecodeError, JsonCodec}

private[elasticsearch] final case class Document(json: String) {
def decode[A](implicit schema: Schema[A]): Either[DecodeError, A] = JsonDecoder.decode(schema, json)
}

private[elasticsearch] object Document {
def apply[A](doc: A)(implicit schema: Schema[A]): Document = Document(
JsonCodec.jsonEncoder(schema).encodeJson(a = doc, indent = None).toString
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ object ElasticRequest {
case None => Left(DocumentNotFound)
}

def put[A](
def put[A: Schema](
index: IndexName,
id: DocumentId,
doc: A,
routing: Option[Routing] = None
)(implicit schema: Schema[A]): ElasticRequest[Unit] =
Put(index, id, Document.apply(doc), routing)
): ElasticRequest[Unit] =
Put(index, id, Document(doc), routing)

private[elasticsearch] final case class GetById(
index: IndexName,
Expand Down
17 changes: 0 additions & 17 deletions modules/library/src/main/scala/zio/elasticsearch/package.scala

This file was deleted.

0 comments on commit 027b50a

Please sign in to comment.