Skip to content

Commit

Permalink
removed otp version from debug environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav1924 committed Aug 1, 2024
1 parent f653725 commit 9bec5bc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 37 deletions.
12 changes: 12 additions & 0 deletions .elixir-tools/next-ls.log
Original file line number Diff line number Diff line change
Expand Up @@ -41199,3 +41199,15 @@ This will trigger a full recompilation in order to re-index your codebase.
17:17:32.719 [debug] handled notification client -> server textDocument/didOpen in 4ms

17:20:32.701 [debug] handled notification client -> server textDocument/didClose in 205µs

17:44:37.769 [debug] handled notification client -> server textDocument/didOpen in 1ms

17:47:37.756 [debug] handled notification client -> server textDocument/didClose in 2ms

18:55:12.240 [debug] handled notification client -> server textDocument/didChange in 27ms

18:55:12.250 [debug] handled notification client -> server textDocument/didChange in 3ms

18:55:12.260 [debug] handled notification client -> server textDocument/didChange in 10ms

18:55:12.260 [debug] handled notification client -> server workspace/didChangeWatchedFiles in 9ms
2 changes: 1 addition & 1 deletion .github/workflows/check-format-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
mix --version
elixir --version
otp --version
# Remove the otp command, as it does not exist
env
- name: Install dependencies
Expand Down
50 changes: 25 additions & 25 deletions lib/polly/polls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@ defmodule Polly.Polls do
end
end

defp do_create_poll({:ok, %Poll{} = poll}) do
:ok = Polly.PollsManager.add_poll(poll)
{:ok, poll}
end
defp do_create_poll({:ok, %Poll{} = poll}) do
:ok = Polly.PollsManager.add_poll(poll)
{:ok, poll}
end

defp do_create_poll({:error, changeset}) do
{:error, changeset}
end
defp do_create_poll({:error, changeset}) do
{:error, changeset}
end

@spec update_poll(Poll.t(), map()) :: {:ok, Poll.t()} | {:error, Ecto.Changeset.t()}
def update_poll(%Poll{} = poll, attrs) do
poll
|> Poll.changeset(attrs)
|> Ecto.Changeset.apply_action(:update)
|> do_update_poll(poll)
end
@spec update_poll(Poll.t(), map()) :: {:ok, Poll.t()} | {:error, Ecto.Changeset.t()}
def update_poll(%Poll{} = poll, attrs) do
poll
|> Poll.changeset(attrs)
|> Ecto.Changeset.apply_action(:update)
|> do_update_poll(poll)
end

defp do_update_poll({:ok, %Poll{} = updated_poll}, _poll) do
:ok = Polly.PollsManager.update_poll(updated_poll.id,updated_poll)
{:ok, updated_poll}
end
defp do_update_poll({:ok, %Poll{} = updated_poll}, _poll) do
:ok = Polly.PollsManager.update_poll(updated_poll.id, updated_poll)
{:ok, updated_poll}
end

defp do_update_poll({:error, changeset}, _poll) do
{:error, changeset}
end
defp do_update_poll({:error, changeset}, _poll) do
{:error, changeset}
end

@spec change_poll(Poll.t(), map()) :: Ecto.Changeset.t()
def change_poll(%Poll{} = poll, attrs \\ %{}) do
Poll.changeset(poll, attrs)
end
@spec change_poll(Poll.t(), map()) :: Ecto.Changeset.t()
def change_poll(%Poll{} = poll, attrs \\ %{}) do
Poll.changeset(poll, attrs)
end
21 changes: 12 additions & 9 deletions lib/polly/polls_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ defmodule Polly.PollsManager do
@spec get_poll!(binary(), boolean()) :: Poll.t()
def get_poll!(poll_id, with_option_votes \\ false) do
case @storage_module.get_poll!(poll_id, with_option_votes) do
nil -> raise ArgumentError, message: "Poll with ID #{poll_id} not found"
poll -> Map.replace(poll, :total_votes, get_poll_votes!(poll_id))
|> replace_option_votes(with_option_votes)
nil ->
raise ArgumentError, message: "Poll with ID #{poll_id} not found"

poll ->
Map.replace(poll, :total_votes, get_poll_votes!(poll_id))
|> replace_option_votes(with_option_votes)
end
end

Expand Down Expand Up @@ -75,13 +78,13 @@ defmodule Polly.PollsManager do
end

@spec update_poll(binary(), Poll.t()) :: :ok | {:error, atom()}
def update_poll(poll_id, %Poll{} = updated_poll) do
if @storage_module.get_poll!(poll_id) do
@storage_module.update_poll(poll_id, updated_poll)
else
{:error, :poll_not_found}
def update_poll(poll_id, %Poll{} = updated_poll) do
if @storage_module.get_poll!(poll_id) do
@storage_module.update_poll(poll_id, updated_poll)
else
{:error, :poll_not_found}
end
end
end

@spec change_poll(Poll.t(), map()) :: Ecto.Changeset.t()
def change_poll(%Poll{} = poll, attrs \\ %{}) do
Expand Down
3 changes: 2 additions & 1 deletion lib/polly/storage/ets_storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule Polly.ETSStorage do
|> Map.replace(:total_votes, get_poll_votes!(poll_id))
|> replace_option_votes(with_option_votes)

[] -> nil
[] ->
nil
end
end

Expand Down
1 change: 0 additions & 1 deletion test/polly/schema/poll_creation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ defmodule Polly.TestPollCreation do
IO.inspect({id, poll}, label: "Poll")
end)
end

end

0 comments on commit 9bec5bc

Please sign in to comment.