Skip to content

Commit

Permalink
Merge pull request #6 from sgobotta/feature/add-cedears-calculator
Browse files Browse the repository at this point in the history
feature/add cedears calculator
  • Loading branch information
sgobotta authored Dec 1, 2023
2 parents 4bc0755 + b4aa2f8 commit cbffc76
Show file tree
Hide file tree
Showing 32 changed files with 1,938 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export DB_HOSTNAME=localhost
# Producers configuration
export CURRENCY_SUPPLIER=supplier-name
export CURRENCY_SUPPLIER_PRODUCER_NAME=SupplierNameProducer
export CEDEAR_SUPPLIER=supplier-name
export CEDEAR_SUPPLIER_PRODUCER_NAME=SupplierNameProducer

# Cache service
export REDIS_HOST=localhost
Expand Down
8 changes: 8 additions & 0 deletions .github/actions/dev/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ inputs:
CURRENCY_SUPPLIER_PRODUCER_NAME:
description: A currency name for the currency producer
required: true
CEDEAR_SUPPLIER:
description: A cedear supplier
required: true
CEDEAR_SUPPLIER_PRODUCER_NAME:
description: A cedear name for the cedear producer
required: true
ELIXIR_VERSION:
description: Elixir version
required: true
Expand Down Expand Up @@ -109,6 +115,8 @@ runs:
# Application env
CURRENCY_SUPPLIER: currency-supplier
CURRENCY_SUPPLIER_PRODUCER_NAME: CurrencySupplierProducer
CEDEAR_SUPPLIER: cedear-supplier
CEDEAR_SUPPLIER_PRODUCER_NAME: CedearSupplierProducer

# Setup the Phoenix Client -------------------------------------------------
- name: Setup web client
Expand Down
10 changes: 10 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ inputs:
CURRENCY_SUPPLIER_PRODUCER_NAME:
description: A currency name for the currency producer
required: true
CEDEAR_SUPPLIER:
description: A cedear supplier
required: true
CEDEAR_SUPPLIER_PRODUCER_NAME:
description: A cedear name for the cedear producer
required: true
ELIXIR_VERSION:
description: Elixir version
required: true
Expand Down Expand Up @@ -109,6 +115,8 @@ runs:
# Application env
CURRENCY_SUPPLIER: currency-supplier
CURRENCY_SUPPLIER_PRODUCER_NAME: CurrencySupplierProducer
CEDEAR_SUPPLIER: cedear-supplier
CEDEAR_SUPPLIER_PRODUCER_NAME: CedearSupplierProducer

# Setup the Phoenix Client -------------------------------------------------
- name: Setup web client
Expand All @@ -134,5 +142,7 @@ runs:
run: >
CURRENCY_SUPPLIER=currency-supplier
CURRENCY_SUPPLIER_PRODUCER_NAME=CurrencySupplierProducer
CEDEAR_SUPPLIER=cedear-supplier
CEDEAR_SUPPLIER_PRODUCER_NAME=CedearSupplierProducer
GITHUB_TOKEN=${GITHUB_TOKEN}
mix coveralls.github -u
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
with:
CURRENCY_SUPPLIER: currency-supplier
CURRENCY_SUPPLIER_PRODUCER_NAME: CurrencySupplierProducer
CEDEAR_SUPPLIER: cedear-supplier
CEDEAR_SUPPLIER_PRODUCER_NAME: CedearSupplierProducer
ELIXIR_VERSION: ${{ env.ELIXIR_VERSION }}
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
MIX_ENV: dev
Expand Down Expand Up @@ -115,6 +117,8 @@ jobs:
with:
CURRENCY_SUPPLIER: currency-supplier
CURRENCY_SUPPLIER_PRODUCER_NAME: CurrencySupplierProducer
CEDEAR_SUPPLIER: cedear-supplier
CEDEAR_SUPPLIER_PRODUCER_NAME: CedearSupplierProducer
ELIXIR_VERSION: ${{ env.ELIXIR_VERSION }}
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
MIX_ENV: test
Expand Down
4 changes: 3 additions & 1 deletion assets/js/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import LineChart from './line_chart_hook'
import SearchBar from './search_bar'

export default {
LineChart
LineChart,
SearchBar
}
38 changes: 38 additions & 0 deletions assets/js/hooks/search_bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This is optional phoenix client hook. It allows to use key down and up to select results.

export default {
mounted() {
const searchBarContainer = (this as any).el as HTMLDivElement
document.addEventListener('keydown', (event) => {
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
return
}

const focusElemnt = document.querySelector(':focus') as HTMLElement

if (!focusElemnt) {
return
}

if (!searchBarContainer.contains(focusElemnt)) {
return
}

event.preventDefault()

const tabElements = document.querySelectorAll(
'#search-input, #searchbox__results_list a',
) as NodeListOf<HTMLElement>
const focusIndex = Array.from(tabElements).indexOf(focusElemnt)
const tabElementsCount = tabElements.length - 1

if (event.key === 'ArrowUp') {
tabElements[focusIndex > 0 ? focusIndex - 1 : tabElementsCount].focus()
}

if (event.key === 'ArrowDown') {
tabElements[focusIndex < tabElementsCount ? focusIndex + 1 : 0].focus()
}
})
},
}
10 changes: 10 additions & 0 deletions lib/ex_finance/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ExFinance.Application do
use Application

alias ExFinance.Currencies.CurrencyProducer
alias ExFinance.Instruments.CedearProducer

@impl true
def start(_type, _args) do
Expand All @@ -28,6 +29,10 @@ defmodule ExFinance.Application do
supplier: fetch_currency_supplier(),
module_name: fetch_currency_supplier_producer_name()
),
CedearProducer.child_spec(
supplier: fetch_cedear_supplier(),
module_name: fetch_cedear_supplier_producer_name()
),
# Start to serve requests, typically the last entry
ExFinanceWeb.Endpoint
]
Expand Down Expand Up @@ -58,6 +63,11 @@ defmodule ExFinance.Application do

defp fetch_currency_supplier, do: System.fetch_env!("CURRENCY_SUPPLIER")

defp fetch_cedear_supplier, do: System.fetch_env!("CEDEAR_SUPPLIER")

defp fetch_currency_supplier_producer_name,
do: System.fetch_env!("CURRENCY_SUPPLIER_PRODUCER_NAME")

defp fetch_cedear_supplier_producer_name,
do: System.fetch_env!("CEDEAR_SUPPLIER_PRODUCER_NAME")
end
19 changes: 11 additions & 8 deletions lib/ex_finance/currencies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ defmodule ExFinance.Currencies do
## Examples
iex> get_by_internal_id("some internal id")
iex> get_by_type("some internal id")
%Currency{}
iex> get_by_internal_id("some internal id")
iex> get_by_type("some internal id")
nil
"""
@spec get_by_internal_id(String.t()) :: Currency.t()
def get_by_internal_id(internal_id) do
Repo.get_by(Currency, internal_id: internal_id)
@spec get_by_type(String.t()) :: Currency.t()
def get_by_type(type) do
Repo.get_by(Currency, type: type)
end

@doc """
Expand Down Expand Up @@ -182,19 +182,22 @@ defmodule ExFinance.Currencies do
end

@doc """
Assigns a supplier id to the given currency.
Assigns a supplier id to the given entity.
## Examples
iex> update_currency(currency, Ecto.UUID.generate())
{:ok, %Currency{}}
iex> update_currency(cedear, Ecto.UUID.generate())
{:ok, %ExFinance.Instruments.Cedear{}}
iex> update_currency(currency, "some invalid id")
{:error, %Ecto.Changeset{}}
"""
def assign_supplier(%Currency{} = currency, supplier_id) do
currency
def assign_supplier(entity, supplier_id) do
entity
|> Currency.change_supplier(supplier_id)
|> Repo.update()
end
Expand Down
Loading

0 comments on commit cbffc76

Please sign in to comment.