Skip to content

Commit

Permalink
feat: currencies exchange rates cache (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioltonon authored May 6, 2023
1 parent 4c7d4eb commit b630d4d
Show file tree
Hide file tree
Showing 46 changed files with 1,084 additions and 1,042 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ stop:
@echo "Stopping application and its dependencies..."
@docker-compose down --remove-orphans

mocks:
@echo "Creating mocks..."
@go generate ./...

tests:
@echo "# Running tests..."
@go test -cover ./application/services/... ./domain/services/...
@go test -cover ./application/services/...

tidy:
@echo "# Formatting code..."
Expand Down
14 changes: 14 additions & 0 deletions application/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/spf13/viper"
)
Expand All @@ -14,6 +15,11 @@ func init() {
viper.SetDefault("database.kind", "mongodb")
viper.SetDefault("database.uri", "mongodb://database:27017")

// Cache Config
viper.SetDefault("cache.address", "cache:6379")
viper.SetDefault("cache.connection_timeout", "5s")
viper.SetDefault("cache.currency_exchange_rates.ttl", "24h")

// Server config
viper.SetDefault("server.address", ":8080")
viper.SetDefault("server.development_environment", true)
Expand All @@ -39,6 +45,14 @@ type Config struct {
URI string
}

Cache struct {
Address string
ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
CurrencyExchangeRates struct {
TTL time.Duration
} `mapstructure:"currency_exchange_rates"`
}

Server struct {
Address string
DevelopmentEnvironment bool `mapstructure:"development_environment"`
Expand Down
12 changes: 7 additions & 5 deletions application/repositories/currencies_repository.go
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package repositories

import "convercy/domain/aggregate"
import "convercy/domain/valueobject"

//go:generate mockery --name RegisteredCurrenciesRepository
type RegisteredCurrenciesRepository interface {
GetRegisteredCurrencies() (*aggregate.RegisteredCurrencies, error)
SaveRegisteredCurrencies(registeredCurrencies *aggregate.RegisteredCurrencies) error
// CurrenciesRepository is a service responsible for providing all known currencies
//
//go:generate mockery --name CurrenciesRepository
type CurrenciesRepository interface {
// ListCurrencyCodes should return a list with all known currency codes
ListCurrencyCodes() (valueobject.CurrencyCodes, error)
}
12 changes: 12 additions & 0 deletions application/repositories/currency_exchange_rates_cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package repositories

import (
"convercy/domain/aggregate"
"convercy/domain/valueobject"
)

//go:generate mockery --name CurrencyExchangeRatesCache
type CurrencyExchangeRatesCache interface {
GetCurrencyExchangeRates(code valueobject.CurrencyCode) (*aggregate.CurrencyExchangeRates, error)
SaveCurrencyExchangeRates(currencyExchangeRates *aggregate.CurrencyExchangeRates) error
}
11 changes: 11 additions & 0 deletions application/repositories/currency_exchange_rates_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package repositories

import (
"convercy/domain/aggregate"
"convercy/domain/valueobject"
)

//go:generate mockery --name CurrencyExchangeRatesRepository
type CurrencyExchangeRatesRepository interface {
GetCurrencyExchangeRates(code valueobject.CurrencyCode) (*aggregate.CurrencyExchangeRates, error)
}
29 changes: 8 additions & 21 deletions application/repositories/mocks/CurrenciesRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions application/repositories/mocks/CurrencyExchangeRatesCache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions application/repositories/mocks/CurrencyExchangeRatesRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions application/repositories/registered_currencies_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package repositories

import "convercy/domain/aggregate"

//go:generate mockery --name RegisteredCurrenciesRepository
type RegisteredCurrenciesRepository interface {
GetRegisteredCurrencies() (*aggregate.RegisteredCurrencies, error)
SaveRegisteredCurrencies(registeredCurrencies *aggregate.RegisteredCurrencies) error
}
Loading

0 comments on commit b630d4d

Please sign in to comment.