-
Notifications
You must be signed in to change notification settings - Fork 18
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
(dsl): Support GetById request #5
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6e78c10
Provide initial getById Elasticsearch request
drmarjanovic 0c2a803
Format code
drmarjanovic 6f369ae
Improve getById request
drmarjanovic 73eb1e8
Code cleanup
drmarjanovic 3836bae
Refactor code
dbulaja98 9e9aaf4
Refactor ElasticRequest
dbulaja98 5b49545
Add error message to JsonDecoderError
markaya 779b994
Use left map instead of fold
markaya 335bdb9
Rename 'Index' to 'IndexName'
drmarjanovic 91a344c
Format code
drmarjanovic ab67c7c
Extract elastic errors to a separated file
dbulaja98 6c75875
Refactor ElasticError
dbulaja98 615c987
Refactor elastic error
dbulaja98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
modules/library/src/main/scala/zio/elasticsearch/DocumentId.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package zio.elasticsearch | ||
|
||
final case class DocumentId(value: String) extends AnyVal |
14 changes: 14 additions & 0 deletions
14
modules/library/src/main/scala/zio/elasticsearch/ElasticError.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package zio.elasticsearch | ||
|
||
object ElasticError { | ||
|
||
sealed abstract class DocumentGettingError | ||
|
||
object DocumentGettingError { | ||
|
||
case object DocumentNotFound extends DocumentGettingError | ||
|
||
case class JsonDecoderError(errorMsg: String) extends DocumentGettingError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
modules/library/src/main/scala/zio/elasticsearch/ElasticRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package zio.elasticsearch | ||
|
||
import zio.elasticsearch.ElasticError._ | ||
import zio.elasticsearch.ElasticError.DocumentGettingError._ | ||
import zio.schema.Schema | ||
|
||
sealed trait ElasticRequest[+A] { self => | ||
final def map[B](f: A => B): ElasticRequest[B] = ElasticRequest.Map(self, f) | ||
|
||
} | ||
|
||
object ElasticRequest { | ||
|
||
private[elasticsearch] final case class Map[A, B](request: ElasticRequest[A], mapper: A => B) | ||
arnoldlacko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extends ElasticRequest[B] | ||
|
||
def getById[A: Schema]( | ||
index: IndexName, | ||
id: DocumentId, | ||
routing: Option[Routing] = None | ||
): ElasticRequest[Either[DocumentGettingError, A]] = | ||
GetById(index, id, routing).map { | ||
case Some(document) => document.decode.left.map(err => JsonDecoderError(err.message)) | ||
case None => Left(DocumentNotFound) | ||
} | ||
|
||
private[elasticsearch] final case class GetById( | ||
index: IndexName, | ||
id: DocumentId, | ||
routing: Option[Routing] = None | ||
) extends ElasticRequest[Option[Document]] | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
modules/library/src/main/scala/zio/elasticsearch/IndexName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package zio.elasticsearch | ||
|
||
final case class IndexName(name: String) extends AnyVal |
3 changes: 3 additions & 0 deletions
3
modules/library/src/main/scala/zio/elasticsearch/Routing.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package zio.elasticsearch | ||
|
||
final case class Routing(value: String) extends AnyVal |
11 changes: 11 additions & 0 deletions
11
modules/library/src/main/scala/zio/elasticsearch/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package zio | ||
|
||
import zio.schema.Schema | ||
import zio.schema.codec.DecodeError | ||
import zio.schema.codec.JsonCodec.JsonDecoder | ||
|
||
package object elasticsearch { | ||
private[elasticsearch] final case class Document(json: String) { | ||
def decode[A](implicit schema: Schema[A]): Either[DecodeError, A] = JsonDecoder.decode(schema, json) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about having only
sealed trait ElasticError
at the moment?We should consider this because we don't have a lot of errors, and maybe it's too early to introduce several layers of error types.