Skip to content

Commit 5898be2

Browse files
authored
feat(api): add user contact retrieval API with stub implementation (#35)
1 parent d84f0ea commit 5898be2

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

lib/webtrit_adapter_client.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ defmodule WebtritAdapterClient do
157157
request(client, options)
158158
end
159159

160+
@spec get_user_contact(Tesla.Client.t(), String.t()) :: result()
161+
def get_user_contact(client, user_id) do
162+
options = [
163+
method: :get,
164+
url: "/user/contacts/#{user_id}"
165+
]
166+
167+
request(client, options)
168+
end
169+
160170
@spec get_user_history_list(Tesla.Client.t(), Tesla.Env.query() | nil) :: result()
161171
def get_user_history_list(client, query \\ []) do
162172
options = [

lib/webtrit_adapter_web/controllers/api/v1/user/contact_controller.ex

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule WebtritAdapterWeb.Api.V1.User.ContactController do
66
alias Portabilling.Api
77
alias WebtritAdapterWeb.Api.V1.CastAndValidateRenderError
88
alias WebtritAdapterWeb.Api.V1.FallbackController
9-
alias WebtritAdapterWeb.Api.V1.CommonResponse
9+
alias WebtritAdapterWeb.Api.V1.{CommonResponse, CommonSchema}
1010
alias WebtritAdapterWeb.Api.V1.User.ContactSchema
1111
alias WebtritAdapterWeb.Api.V1.User.ControllerMapping
1212

@@ -104,4 +104,40 @@ defmodule WebtritAdapterWeb.Api.V1.User.ContactController do
104104
{:error, :internal_server_error, :external_api_issue}
105105
end
106106
end
107+
108+
OpenApiSpexExt.operation(:show,
109+
summary: "Retrieve a contact by UserId",
110+
description: """
111+
Retrieve extension number and name of a specific user
112+
within the same **Adaptee** by their UserId.
113+
""",
114+
parameters: [
115+
user_id: [
116+
in: :path,
117+
description: "The unique identifier of the user",
118+
schema: CommonSchema.UserId
119+
]
120+
],
121+
responses: [
122+
CommonResponse.unauthorized(),
123+
CommonResponse.forbidden(),
124+
CommonResponse.not_found([
125+
:session_not_found,
126+
:user_not_found,
127+
:contact_not_found
128+
]),
129+
CommonResponse.unprocessable(),
130+
CommonResponse.external_api_issue(),
131+
CommonResponse.functionality_not_implemented(),
132+
ok: {
133+
"Ok",
134+
"application/json",
135+
CommonSchema.Contact
136+
}
137+
]
138+
)
139+
140+
def show(_conn, _params, _user_id) do
141+
{:error, :not_implemented, :functionality_not_implemented}
142+
end
107143
end

lib/webtrit_adapter_web/router.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule WebtritAdapterWeb.Router do
6969

7070
scope "/user", User do
7171
resources "/", InfoController, only: [:show, :delete], singleton: true
72-
resources "/contacts", ContactController, only: [:index]
72+
resources "/contacts", ContactController, only: [:index, :show], params: "user_id"
7373
resources "/history", HistoryController, only: [:index]
7474
resources "/recordings", RecordingController, only: [:show], param: "recording_id"
7575

0 commit comments

Comments
 (0)