@al2o3cr
Here is the user controller
def create(conn, params) do
IO.inspect(conn)
IO.inspect(params)
with {:ok, %User{} = user} <- Users.create_user(params) do
IO.inspect(Users.create_user(params))
conn
|> put_status(:created)
|> put_resp_header("location", Routes.user_path(conn, :show, user))
|> render("show.json", user: user)
end
end
IO.inspect(conn)
PS D:\db-service-backend> mix test test\dbservice_web\controllers\user_controller_test.exs
dbservice: generated priv/static/swagger.json
.%Plug.Conn{
adapter: {Plug.Adapters.Test.Conn, :...},
assigns: %{},
body_params: %{
"user" => %{
"address" => nil,
"city" => nil,
"country" => nil,
"date_of_birth" => nil,
"district" => nil,
"email" => nil,
"full_name" => nil,
"gender" => nil,
"phone" => "nope",
"pincode" => nil,
"role" => nil,
"state" => nil,
"whatsapp_phone" => nil
}
},
cookies: %{},
halted: false,
host: "www.example.com",
method: "POST",
owner: #PID<0.458.0>,
params: %{
"user" => %{
"address" => nil,
"city" => nil,
"country" => nil,
"date_of_birth" => nil,
"district" => nil,
"email" => nil,
"full_name" => nil,
"gender" => nil,
"phone" => "nope",
"pincode" => nil,
"role" => nil,
"state" => nil,
"whatsapp_phone" => nil
}
},
path_info: ["api", "user"],
path_params: %{},
port: 80,
private: %{
DbserviceWeb.Router => {[], %{PhoenixSwagger.Plug.SwaggerUI => []}},
:before_send => [#Function<0.11807388/1 in Plug.Telemetry.call/2>],
:phoenix_action => :create,
:phoenix_controller => DbserviceWeb.UserController,
:phoenix_endpoint => DbserviceWeb.Endpoint,
:phoenix_format => "json",
:phoenix_layout => {DbserviceWeb.LayoutView, :app},
:phoenix_recycled => true,
:phoenix_request_logger => {"request_logger", "request_logger"},
:phoenix_router => DbserviceWeb.Router,
:phoenix_view => DbserviceWeb.UserView,
:plug_session_fetch => #Function<1.84243074/1 in Plug.Session.fetch_session/1>,
:plug_skip_csrf_protection => true
},
query_params: %{},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %{},
req_headers: [
{"accept", "application/json"},
{"content-type", "multipart/mixed; boundary=plug_conn_test"}
],
request_path: "/api/user",
resp_body: nil,
resp_cookies: %{},
resp_headers: [
{"cache-control", "max-age=0, private, must-revalidate"},
{"x-request-id", "F1WHfW2oA8A7DPUAAAPB"}
],
scheme: :http,
script_name: [],
secret_key_base: :...,
state: :unset,
status: nil
}
%Plug.Conn{
adapter: {Plug.Adapters.Test.Conn, :...},
assigns: %{},
body_params: %{
"address" => "some address",
"city" => "some city",
"country" => "some country",
"date_of_birth" => ~U[2022-04-28 13:58:00Z],
"district" => "some district",
"email" => "some email",
"full_name" => "some full name",
"gender" => "some gender",
"phone" => "9456591269",
"pincode" => "some pincode",
"role" => "some role",
"state" => "some state",
"whatsapp_phone" => "some whatsapp phone"
},
cookies: %{},
halted: false,
host: "www.example.com",
method: "POST",
owner: #PID<0.462.0>,
params: %{
"address" => "some address",
"city" => "some city",
"country" => "some country",
"date_of_birth" => ~U[2022-04-28 13:58:00Z],
"district" => "some district",
"email" => "some email",
"full_name" => "some full name",
"gender" => "some gender",
"phone" => "9456591269",
"pincode" => "some pincode",
"role" => "some role",
"state" => "some state",
"whatsapp_phone" => "some whatsapp phone"
},
path_info: ["api", "user"],
path_params: %{},
port: 80,
private: %{
DbserviceWeb.Router => {[], %{PhoenixSwagger.Plug.SwaggerUI => []}},
:before_send => [#Function<0.11807388/1 in Plug.Telemetry.call/2>],
:phoenix_action => :create,
:phoenix_controller => DbserviceWeb.UserController,
:phoenix_endpoint => DbserviceWeb.Endpoint,
:phoenix_format => "json",
:phoenix_layout => {DbserviceWeb.LayoutView, :app},
:phoenix_recycled => true,
:phoenix_request_logger => {"request_logger", "request_logger"},
:phoenix_router => DbserviceWeb.Router,
:phoenix_view => DbserviceWeb.UserView,
:plug_session_fetch => #Function<1.84243074/1 in Plug.Session.fetch_session/1>,
:plug_skip_csrf_protection => true
},
query_params: %{},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %{},
req_headers: [
{"accept", "application/json"},
{"content-type", "multipart/mixed; boundary=plug_conn_test"}
],
request_path: "/api/user",
resp_body: nil,
resp_cookies: %{},
resp_headers: [
{"cache-control", "max-age=0, private, must-revalidate"},
{"x-request-id", "F1WHfXVHk8Bb4iUAAABj"}
],
scheme: :http,
script_name: [],
secret_key_base: :...,
state: :unset,
status: nil
}
IO.inspect(params)
PS D:\db-service-backend> mix test test\dbservice_web\controllers\user_controller_test.exs
Compiling 1 file (.ex)
dbservice: generated priv/static/swagger.json
...%{
"user" => %{
"address" => nil,
"city" => nil,
"country" => nil,
"date_of_birth" => nil,
"district" => nil,
"email" => nil,
"full_name" => nil,
"gender" => nil,
"phone" => "nope",
"pincode" => nil,
"role" => nil,
"state" => nil,
"whatsapp_phone" => nil
}
}
%{
"address" => "some address",
"city" => "some city",
"country" => "some country",
"date_of_birth" => ~U[2022-04-28 13:58:00Z],
"district" => "some district",
"email" => "some email",
"full_name" => "some full name",
"gender" => "some gender",
"phone" => "9456591269",
"pincode" => "some pincode",
"role" => "some role",
"state" => "some state",
"whatsapp_phone" => "some whatsapp phone"
}
IO.inspect(Users.create_user)
{:ok,
%Dbservice.Users.User{
__meta__: #Ecto.Schema.Metadata<:loaded, "user">,
id: 471,
address: nil,
city: nil,
district: nil,
email: nil,
full_name: nil,
gender: nil,
phone: nil,
pincode: nil,
role: nil,
state: nil,
whatsapp_phone: nil,
date_of_birth: nil,
country: nil,
inserted_at: ~N[2023-04-13 15:10:19],
updated_at: ~N[2023-04-13 15:10:19],
sessions: #Ecto.Association.NotLoaded<association :sessions is not loaded>,
teacher: #Ecto.Association.NotLoaded<association :teacher is not loaded>,
student: #Ecto.Association.NotLoaded<association :student is not loaded>,
group: #Ecto.Association.NotLoaded<association :group is not loaded>
}}
.{:ok,
%Dbservice.Users.User{
__meta__: #Ecto.Schema.Metadata<:loaded, "user">,
id: 473,
address: nil,
city: nil,
district: nil,
email: nil,
full_name: nil,
gender: nil,
phone: nil,
pincode: nil,
role: nil,
state: nil,
whatsapp_phone: nil,
date_of_birth: nil,
country: nil,
inserted_at: ~N[2023-04-13 15:10:19],
updated_at: ~N[2023-04-13 15:10:19],
sessions: #Ecto.Association.NotLoaded<association :sessions is not loaded>,
teacher: #Ecto.Association.NotLoaded<association :teacher is not loaded>,
student: #Ecto.Association.NotLoaded<association :student is not loaded>,
group: #Ecto.Association.NotLoaded<association :group is not loaded>
}}