This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Update the README #3
Open
caarmen
wants to merge
1
commit into
LedgerHQ:master
Choose a base branch
from
caarmen:update-readme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
caarmen
commented
Dec 15, 2021
- Update some of the referenced class names
- Remove the /users path from the local server url
- Update the reference to the sql file for the table creation
- Add an example curl command to create a user (otherwise the example to fetch a user won't return any user). Update the example which fetches a user, to fetch the one just created
- Fix a spelling error
* Update some of the referenced class names * Remove the /users path from the local server url * Update the reference to the sql file for the table creation * Add an example curl command to create a user (otherwise the example to fetch a user won't return any user). Update the example which fetches a user, to fetch the one just created * Fix a spelling error
caarmen
commented
Dec 15, 2021
6. `sbt test` (optional) | ||
7. `sbt run` | ||
8. `curl http://localhost:8080/users/USERNAME` | ||
8. Create a user: `curl -X POST http://localhost:8080/ -H 'Content-Type: application/json' -d '{"username":"jdoe","email":"jdoe@gmail.com"}'` | ||
9. Read a user `curl http://localhost:8080/jdoe` |
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.
With the current code, the endpoints are at the root /
, not /users
.
If it's desired to have them at /users
, I think something like the following would be needed:
diff --git a/src/main/scala/co/ledger/template/http/UserHttpRoutes.scala b/src/main/scala/co/ledger/template/http/UserHttpRoutes.scala
index 4118217..e0a77d6 100644
--- a/src/main/scala/co/ledger/template/http/UserHttpRoutes.scala
+++ b/src/main/scala/co/ledger/template/http/UserHttpRoutes.scala
@@ -20,21 +20,21 @@ class UserHttpRoutes[F[_]: Sync](userService: UserService[F])(
val routes: HttpRoutes[F] = HttpRoutes.of[F] {
// Find all users
- case GET -> Root =>
+ case GET -> Root / "users" =>
for {
users <- userService.findAll
response <- users.fold(H.handle, x => Ok(x.asJson))
} yield response
// Find user by username
- case GET -> Root / username =>
+ case GET -> Root / "users" / username =>
for {
user <- userService.findUser(UserName(username))
response <- user.fold(H.handle, x => Ok(x.asJson))
} yield response
// Create a user
- case req @ POST -> Root =>
+ case req @ POST -> Root / "users" =>
req.decode[CreateUser] { createUser =>
UserValidation
.validateCreateUser(createUser)
@@ -48,7 +48,7 @@ class UserHttpRoutes[F[_]: Sync](userService: UserService[F])(
}
// Update a user
- case req @ PUT -> Root / username =>
+ case req @ PUT -> Root / "users" / username =>
req.decode[UpdateUser] { updateUser =>
UserValidation
.validateUpdateUser(updateUser)
@@ -63,7 +63,7 @@ class UserHttpRoutes[F[_]: Sync](userService: UserService[F])(
}
// Delete a user
- case DELETE -> Root / username =>
+ case DELETE -> Root / "users" / username =>
for {
result <- userService.deleteUser(UserName(username))
response <- result.fold(H.handle, _ => NoContent())
diff --git a/src/test/scala/co/ledger/template/http/UserHttpRoutesSpec.scala b/src/test/scala/co/ledger/template/http/UserHttpRoutesSpec.scala
index 99059e5..a64f348 100644
--- a/src/test/scala/co/ledger/template/http/UserHttpRoutesSpec.scala
+++ b/src/test/scala/co/ledger/template/http/UserHttpRoutesSpec.scala
@@ -23,7 +23,7 @@ class UserHttpEndpointSpec extends UserHttpRoutesFixture with AnyFlatSpecLike wi
forAll(examples) { (username, expectedStatus, expectedBody) =>
it should s"find the user with username: ${username.value}" in IOAssertion {
- val request = Request[IO](uri = Uri(path = s"/${username.value}"))
+ val request = Request[IO](uri = Uri(path = s"/users/${username.value}"))
httpRoutes.flatMap(_.run(request).value).flatMap { task =>
task.fold(IO(fail("Empty response")) *> IO.unit) { response =>
IO(response.status should be (expectedStatus)) *>
@@ -34,7 +34,7 @@ class UserHttpEndpointSpec extends UserHttpRoutesFixture with AnyFlatSpecLike wi
}
it should "Create a user" in IOAssertion {
- val req = Request[IO](method = Method.POST).withEntity(CreateUser("root", "root@unix.org"))
+ val req = Request[IO](method = Method.POST, uri = Uri(path="/users")).withEntity(CreateUser("root", "root@unix.org"))
for {
routes <- httpRoutes
task <- routes(req).value
(though probably with a constant somewhere, instead of the string literal repeated).
Maybe there's a way to configure this in one place though 🤔
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.