Skip to content

Commit

Permalink
Integrate changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil committed Apr 19, 2024
1 parent 0d97412 commit 1fedb49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions docs/dsl/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ object Quiz {
}

object EndpointWithMultipleOutputTypes extends ZIOAppDefault {
val endpoint: Endpoint[Unit, Unit, ZNothing, Either[Course, Quiz], None] =
val endpoint: Endpoint[Unit, Unit, ZNothing, Either[Quiz, Course], None] =
Endpoint(RoutePattern.GET / "resources")
.out[Course]
.out[Quiz]
Expand All @@ -264,8 +264,8 @@ object EndpointWithMultipleOutputTypes extends ZIOAppDefault {
endpoint.implement(handler {
ZIO.randomWith(_.nextBoolean)
.map(r =>
if (r) Left(Course("Introduction to Programming", 49.99))
else Right(Quiz("What is the boiling point of water in Celsius?", 2)),
if (r) Right(Course("Introduction to Programming", 49.99))
else Left(Quiz("What is the boiling point of water in Celsius?", 2)),
)
})
.toHttpApp).provide(Server.default, Scope.default)
Expand Down Expand Up @@ -306,7 +306,7 @@ implicit val bookSchema = DeriveSchema.gen[Book]
implicit val notFoundSchema = DeriveSchema.gen[BookNotFound]
implicit val authSchema = DeriveSchema.gen[AuthenticationError]

val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[BookNotFound, AuthenticationError], Book, None] =
val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[AuthenticationError, BookNotFound], Book, None] =
Endpoint(RoutePattern.GET / "books" / PathCodec.int("id"))
.header(HeaderCodec.authorization)
.out[Book]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault {
}
}

val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[BookNotFound, AuthenticationError], Book, None] =
val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[AuthenticationError, BookNotFound], Book, None] =
Endpoint(RoutePattern.GET / "books" / PathCodec.int("id"))
.header(HeaderCodec.authorization)
.out[Book]
Expand All @@ -48,12 +48,12 @@ object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault {
def isUserAuthorized(authHeader: Header.Authorization) = false

val getBookHandler
: Handler[Any, Either[BookNotFound, AuthenticationError], (RuntimeFlags, Header.Authorization), Book] =
: Handler[Any, Either[AuthenticationError, BookNotFound], (RuntimeFlags, Header.Authorization), Book] =
handler { (id: Int, authHeader: Header.Authorization) =>
if (isUserAuthorized(authHeader))
BookRepo.find(id).mapError(Left(_))
BookRepo.find(id).mapError(Right(_))
else
ZIO.fail(Right(AuthenticationError("User is not authenticated", 123)))
ZIO.fail(Left(AuthenticationError("User is not authenticated", 123)))
}

val app = endpoint.implement(getBookHandler).toHttpApp @@ Middleware.debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ object BadRequestSpec extends ZIOSpecDefault {
val expectedBody =
html(
body(
h1("Bad Request"),
p("There was an error decoding the request"),
h1("Codec Error"),
p("There was an error en-/decoding the request/response"),
p("SchemaTransformationFailure", idAttr := "name"),
p("Expected single value for query parameter age, but got 2 instead", idAttr := "message"),
),
Expand Down

0 comments on commit 1fedb49

Please sign in to comment.