Skip to content

Commit

Permalink
feat(accounts): built GET get_account_by_id endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielparizet committed Jul 4, 2024
1 parent 735f317 commit 9e00e00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/book_my_gigs_web/accounts/accounts_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ defmodule BookMyGigsWeb.AccountsController do
|> send_resp(200, accounts)
end

operation(:get_account_by_id,
summary: "Get account by id",
parameters: [
account_id: [
in: :path,
description: "Account id",
schema: %Schema{type: :string, format: :uuid},
example: "61492a85-3946-4b62-8887-2952af807c26"
]
],
responses: [
ok: {"Get accounts response", "application/json", Schemas.GetAccountsResponse}
],
ok: "Account succesfsfully found"
)

def get_account_by_id(conn, _params) do
account_id = conn.path_params["id"]

account =
account_id
|> Accounts.get_account_by_id!()
|> Accounts.to_context_struct()
|> Jason.encode!()

conn
|> put_resp_content_type("application/json")
|> send_resp(200, account)
end

operation(:create,
summary: "Create an account",
request_body: {"Create account input", "application/json", Schemas.CreateAccountInput},
Expand Down
1 change: 1 addition & 0 deletions lib/book_my_gigs_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule BookMyGigsWeb.Router do
scope "/api", BookMyGigsWeb do
pipe_through [:api, :auth]
get "/accounts", AccountsController, :get
get "/account/:id", AccountsController, :get_account_by_id
put "/accounts/:id", AccountsController, :update
delete "/accounts/:id", AccountsController, :delete
end
Expand Down

0 comments on commit 9e00e00

Please sign in to comment.