Conversation
RichDom2185
left a comment
There was a problem hiding this comment.
Hi, thanks for working on this! Did a quick look, just some comments below for now.
Also, a minor nit: the name data is very generic and a name that reflects more closely to what it does (e.g. state) might be preferred.
There was a problem hiding this comment.
Don't commit this as this is a local development setup, thanks!
| schema "shared_programs" do | ||
| field(:data, :map) | ||
| field(:uuid, Ecto.UUID) | ||
|
|
||
| timestamps() | ||
| end | ||
|
|
||
| @doc false | ||
| def changeset(shared_program, attrs) do | ||
| shared_program |
There was a problem hiding this comment.
Missing definitions for required and optional fields (take a look at the other models in the codebase to see how they're implemented).
| add(:uuid, :uuid) | ||
| add(:data, :map) |
There was a problem hiding this comment.
Can we add constraints and/or indices to this table (e.g. non-null, unique, primary key, etc.)?
| # pipe_through :api | ||
| # end | ||
|
|
||
| scope "/v2", CadetWeb do |
There was a problem hiding this comment.
Don't create a separate scope is possible, since this endpoint is grouped as part of the other routes.
| # end | ||
|
|
||
| scope "/v2", CadetWeb do | ||
| pipe_through(:api) |
There was a problem hiding this comment.
We should pipe through the proper authentication middleware like the other endpoints.
| scope "/v2", CadetWeb do | ||
| pipe_through(:api) | ||
|
|
||
| resources("/shared_programs", SharedProgramController, only: [:index, :show, :create, :delete]) |
There was a problem hiding this comment.
Are we supporting :index and :delete? Only create and read operations are meant to be supported right?
| defp ping_url_shortener(uuid) do | ||
| url = "https://localhost:8000/yourls-api.php" | ||
|
|
||
| params = %{ | ||
| signature: "5eef899abd", | ||
| action: "shorturl", | ||
| format: "json", | ||
| keyword: uuid, | ||
| url: "http://localhost:8000/playground#uuid=#{uuid}" | ||
| } | ||
|
|
||
| case HTTPoison.post(url, {:form, params}) do | ||
| {:ok, %{status_code: 200, body: body}} -> | ||
| {:ok, body} | ||
|
|
||
| {:error, %HTTPoison.Error{reason: reason}} -> | ||
| {:error, reason} | ||
|
|
||
| other -> | ||
| {:error, "Unexpected response: #{inspect(other)}"} | ||
| end | ||
| end |
| # case ping_url_shortener(uuid) do | ||
| # {:ok, shortened_url} -> | ||
| # conn | ||
| # |> put_status(:created) | ||
| # |> put_resp_header("location", ~s"/api/shared_programs/#{shared_program}") | ||
| # # |> render(:show, shared_program: shared_program) | ||
| # |> render("show.json", %{uuid: uuid, shortened_url: shortened_url}) | ||
| # {:error, reason} -> | ||
| # conn | ||
| # |> put_status(:internal_server_error) | ||
| # |> json(%{error: "Failed to shorten URL: #{reason}"}) | ||
| # end |
There was a problem hiding this comment.
Commented code should either be explained with a comment or removed if unused.
| # change to current server of source academy | ||
| # server = "http://localhost:8000" | ||
| # url = |
| action_fallback(CadetWeb.FallbackController) | ||
|
|
||
| def index(conn, _params) do | ||
| shared_programs = SharedPrograms.list_shared_programs() |
There was a problem hiding this comment.
We should not expose this. Very dangerous and breaks privacy.
This is just a draft, currently there are several problems yet to fix: