Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Add configuration/settings endpoints (#515)
Browse files Browse the repository at this point in the history
* Create Setting table/Schema

* Add Setting overlay module

* Add Setting.all()

* Add initial seeder for settings

* Add position

* Finalize setting seeds

* Skip input requirements when assume_yes is true

* Add descriptions

* Refactor Standalone and max_per_page settings

* Refactor code to handle base_url and standalone settings properly

* Create EWalletConfig sub app

* Reorganize EWalletConfig and EWalletDB

* Use EWalletConfig in all other sub apps

* Refactor EWalletConfig to use a GenServer for setting registration

* Update EWalletDB to use EWalletConfig GenServer

* Fix most of the tests in wallet

* Extract Settings loading out of Config

* Update EWalletAPI To use EWalletConfig

* Fix failing eWallet tests

* Finally figured out how to fix all the tests with the Config GenServer…

* Reorganize utils tests

* Add tests for Setting module

* Add config_test

* Add type specs in Config

* Add multi node test

* Add SettingLoader tests

* Remove unused alias

* Cleanup

* Remove multi node test for now

* Fix seeds

* Add setting validation and remove select type

* Fix setting ordering

* Fix minor issues

* Fix Credo issue in insert_all_defaults

* Fix dependencies out of place for emails

* Move back validator functions not needed in EWalletConfig

* Remove unique index on positions

* Update LocalLedger to use EWalletConfig

* Fix race condition

* Move back Validator in ewallet_db

* Update components.md

* Add ConfigurationController

* Add /configuration.update endpoint

* Add result count in responses

* Fix Credo offenses

* Remove custom error

* Handle keyword list properly for config_pid param

* Update Swagger with Configuration endpoints

* Fix and update open api spec (also convert to json)
  • Loading branch information
Thibault authored Nov 20, 2018
1 parent e079c9d commit 2629d80
Show file tree
Hide file tree
Showing 25 changed files with 1,067 additions and 429 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule AdminAPI.V1.ConfigurationController do
use AdminAPI, :controller
import AdminAPI.V1.ErrorHandler

alias EWallet.Web.{Orchestrator, V1.SettingOverlay}
alias EWalletConfig.{Config, Repo}

def get(conn, attrs) do
settings =
Config.query_settings()
|> Orchestrator.query(SettingOverlay, attrs, Repo)

render(conn, :settings, %{settings: settings})
end

def update(conn, attrs) do
with {:ok, settings} <- Config.update(attrs) do
render(conn, :settings_with_errors, %{settings: settings})
else
{:error, code} ->
handle_error(conn, code)
end
end
end
3 changes: 3 additions & 0 deletions apps/admin_api/lib/admin_api/v1/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ defmodule AdminAPI.V1.Router do

post("/settings.all", SettingsController, :get_settings)

post("/configuration.get", ConfigurationController, :get)
post("/configuration.update", ConfigurationController, :update)

# Self endpoints (operations on the currently authenticated user)
post("/me.get", SelfController, :get)
post("/me.get_accounts", SelfController, :get_accounts)
Expand Down
16 changes: 16 additions & 0 deletions apps/admin_api/lib/admin_api/v1/views/configuration_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule AdminAPI.V1.ConfigurationView do
use AdminAPI, :view
alias EWallet.Web.V1.{ConfigSettingSerializer, ResponseSerializer}

def render("settings.json", %{settings: settings}) do
settings
|> ConfigSettingSerializer.serialize()
|> ResponseSerializer.serialize(success: true)
end

def render("settings_with_errors.json", %{settings: settings}) do
settings
|> ConfigSettingSerializer.serialize_with_errors()
|> ResponseSerializer.serialize(success: true)
end
end
Loading

0 comments on commit 2629d80

Please sign in to comment.