-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add delete function to db context * fix: API keys seeds module name * feat: Campus Controller - Criaçao da rota - Criaçao do controller - Criaçao da documentaçao
- Loading branch information
Showing
6 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
defmodule FuschiaWeb.CampusController do | ||
@moduledoc false | ||
|
||
use FuschiaWeb, :controller | ||
use OpenApiSpex.ControllerSpecs | ||
|
||
alias Fuschia.Db | ||
alias Fuschia.Entities.Campus | ||
alias Fuschia.Queries.Campi | ||
alias FuschiaWeb.Swagger.{CampusSchemas, Response, Security} | ||
alias OpenApiSpex.Schema | ||
|
||
action_fallback FuschiaWeb.FallbackController | ||
|
||
tags(["campi"]) | ||
security(Security.private()) | ||
|
||
operation(:create, | ||
request_body: | ||
{"Atributos de criação", "application/json", CampusSchemas.CreateRequest, required: true}, | ||
responses: | ||
[created: {"Resposta de sucesso", "application/json", CampusSchemas.Campus}] ++ | ||
Response.errors(:unauthorized) | ||
) | ||
|
||
@spec create(Plug.Conn.t(), map) :: Plug.Conn.t() | ||
def create(conn, %{"campus" => campus_attr}) do | ||
with {:ok, campus} <- Db.create(Campus, campus_attr) do | ||
render_response(campus, conn, :created) | ||
end | ||
end | ||
|
||
operation(:index, | ||
responses: | ||
[ok: {"Resposta de sucesso", "application/json", CampusSchemas.AllCampiResponse}] ++ | ||
Response.errors(:unauthorized) | ||
) | ||
|
||
@spec index(Plug.Conn.t(), map) :: Plug.Conn.t() | ||
def index(conn, _params) do | ||
Campi.query() | ||
|> Db.list() | ||
|> render_response(conn) | ||
end | ||
|
||
operation(:delete, | ||
parameters: [ | ||
id: [ | ||
in: :path, | ||
type: %Schema{type: :string, minimum: 1}, | ||
description: "ID do Campus", | ||
example: "1111111", | ||
required: true | ||
] | ||
], | ||
responses: | ||
[ok: {"Resposta de sucesso", "application/json", CampusSchemas.Campus}] ++ | ||
Response.errors(:unauthorized) | ||
) | ||
|
||
@spec delete(Plug.Conn.t(), map) :: Plug.Conn.t() | ||
def delete(conn, %{"campus_id" => campus_id}) do | ||
with %Campus{} = campus <- Db.get(Campi.query(), campus_id), | ||
{:ok, _campus} <- Db.delete(campus) do | ||
render_response(campus, conn) | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
defmodule FuschiaWeb.Swagger.CampusSchemas do | ||
@moduledoc false | ||
|
||
require OpenApiSpex | ||
|
||
alias OpenApiSpex.Schema | ||
|
||
defmodule CreateRequest do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "Criação do Campus", | ||
type: :object, | ||
properties: %{ | ||
nome: %Schema{type: :string, description: "Campus name", required: true} | ||
}, | ||
example: %{ | ||
"nome" => "Campos dos Goytacazes" | ||
} | ||
}) | ||
end | ||
|
||
defmodule AllCampiResponse do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "Listagem de Campi", | ||
type: :object, | ||
properties: %{ | ||
data: %Schema{description: "Campi", type: :array, items: Campus} | ||
}, | ||
example: %{ | ||
"data" => [ | ||
%{ | ||
"nome" => "Campos dos Goytacazes", | ||
"id_externo" => "1111111" | ||
} | ||
] | ||
} | ||
}) | ||
end | ||
|
||
defmodule Campus do | ||
@moduledoc false | ||
|
||
OpenApiSpex.schema(%{ | ||
description: "Campus info", | ||
type: :object, | ||
properties: %{ | ||
nome: %Schema{type: :string, description: "Campus name"}, | ||
id_externo: %Schema{type: :string, description: "Campus id"} | ||
}, | ||
example: %{ | ||
"nome" => "Campos dos Goytacazes", | ||
"id_externo" => "1111111" | ||
} | ||
}) | ||
end | ||
end |
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