create gists
This commit is contained in:
parent
79a17290d5
commit
43a8412f06
90 changed files with 1777 additions and 2107 deletions
43
lib/zoeyscomputer_web/controllers/gist_controller.ex
Normal file
43
lib/zoeyscomputer_web/controllers/gist_controller.ex
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
defmodule ZoeyscomputerWeb.GistController do
|
||||
use ZoeyscomputerWeb, :controller
|
||||
|
||||
alias Zoeyscomputer.Gists
|
||||
alias Zoeyscomputer.Gists.Gist
|
||||
|
||||
action_fallback ZoeyscomputerWeb.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
gists = Gists.list_gists()
|
||||
render(conn, :index, gists: gists)
|
||||
end
|
||||
|
||||
def create(conn, %{"gist" => gist_params}) do
|
||||
with {:ok, %Gist{} = gist} <- Gists.create_gist(gist_params) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> put_resp_header("location", ~p"/api/gists/#{gist}")
|
||||
|> render(:show, gist: gist)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
gist = Gists.get_gist!(id)
|
||||
render(conn, :show, gist: gist)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "gist" => gist_params}) do
|
||||
gist = Gists.get_gist!(id)
|
||||
|
||||
with {:ok, %Gist{} = gist} <- Gists.update_gist(gist, gist_params) do
|
||||
render(conn, :show, gist: gist)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
gist = Gists.get_gist!(id)
|
||||
|
||||
with {:ok, %Gist{}} <- Gists.delete_gist(gist) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
25
lib/zoeyscomputer_web/controllers/gist_json.ex
Normal file
25
lib/zoeyscomputer_web/controllers/gist_json.ex
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
defmodule ZoeyscomputerWeb.GistJSON do
|
||||
alias Zoeyscomputer.Gists.Gist
|
||||
|
||||
@doc """
|
||||
Renders a list of gists.
|
||||
"""
|
||||
def index(%{gists: gists}) do
|
||||
%{data: for(gist <- gists, do: data(gist))}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Renders a single gist.
|
||||
"""
|
||||
def show(%{gist: gist}) do
|
||||
%{data: data(gist)}
|
||||
end
|
||||
|
||||
defp data(%Gist{} = gist) do
|
||||
%{
|
||||
id: gist.id,
|
||||
code: gist.code,
|
||||
lang: gist.lang
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<div class="container p-4 flex justify-center align-middle">
|
||||
<div class="border border-ctp-overlay0 rounded-md p-4 flex-col flex items-center">
|
||||
<h1 class="font-bold text-ctp-mauve">zoey</h1>
|
||||
<p class="text-ctp-text"><i>Software Engineer 🏳️⚧️</i></p>
|
||||
<p class="max-w-96 text-center mt-4 text-ctp-overlay2">
|
||||
Currently cooking this up, stay tuned... in the meantime, you can monitor my server's resources.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue