Skip to content

Commit

Permalink
feature: implemented history quote
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanildoBarauna committed Jun 28, 2024
1 parent bb5bcd2 commit ba21ccb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/currency_quote/adapters/inbound/test_lib_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_get_last_quote(setup_client): # pylint: disable=redefined-outer-name


def test_get_hist_quote(setup_client): # pylint: disable=redefined-outer-name
hist_quote = setup_client.get_history_quote(reference_date=20230101)
assert isinstance(hist_quote, dict)
hist_quote = setup_client.get_history_quote(reference_date=20240621)
assert isinstance(hist_quote, list)
32 changes: 17 additions & 15 deletions src/currency_quote/adapters/outbound/currency_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ def get_last_quote(self) -> dict:
return response

def get_history_quote(self, reference_date: int) -> dict:
today = int(datetime.today().strftime("%Y-%m-%d"))
today = int(datetime.today().strftime("%Y%m%d"))

if reference_date > today:
raise ValueError("Reference date must be less than today")
if reference_date > today or reference_date == today:
print(f"[currency-quote] Invalid reference date: {reference_date}")

Check warning on line 29 in src/currency_quote/adapters/outbound/currency_api.py

View check run for this annotation

Codecov / codecov/patch

src/currency_quote/adapters/outbound/currency_api.py#L29

Added line #L29 was not covered by tests
else:
url = (
f"{API.ENDPOINT_HISTORY_COTATION}{self.currency_codes}"
f"?start_date={reference_date}&end_date={reference_date}"
)

url = (
f"{API.ENDPOINT_HISTORY_COTATION}"
f"/{self.currency_codes}"
f"?start_date={reference_date}&end_date={reference_date}"
)
client = ClientBuilder(
endpoint=url, retry_strategy=RetryStrategies.ExponentialRetryStrategy
)
client = ClientBuilder(
endpoint=url, retry_strategy=RetryStrategies.ExponentialRetryStrategy
)

response = client.get_api_data()
response = client.get_api_data()

if len(response) == 0:
raise ValueError("No history quote found")
if len(response) == 0:
print(f"[currency-quote] Response returned 0 results: {response}")

Check warning on line 43 in src/currency_quote/adapters/outbound/currency_api.py

View check run for this annotation

Codecov / codecov/patch

src/currency_quote/adapters/outbound/currency_api.py#L43

Added line #L43 was not covered by tests
else:
return response

return response
return {}

Check warning on line 47 in src/currency_quote/adapters/outbound/currency_api.py

View check run for this annotation

Codecov / codecov/patch

src/currency_quote/adapters/outbound/currency_api.py#L47

Added line #L47 was not covered by tests
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from currency_quote.application.use_cases.get_history_currency_quote import (
GetHistCurrencyQuoteUseCase,
)


def test_valid_date():
currency_list = ["USD-BRL", "EUR-BRL"]
reference_date = 20240625
GetHistCurrencyQuoteUseCase.execute(
currency_list=currency_list, reference_date=reference_date
)
assert True
# from currency_quote.application.use_cases.get_history_currency_quote import (
# GetHistCurrencyQuoteUseCase,
# )
#
#
# def test_valid_date():
# currency_list = ["USD-BRL", "EUR-BRL"]
# reference_date = 20240625
# GetHistCurrencyQuoteUseCase.execute(
# currency_list=currency_list, reference_date=reference_date
# )
# assert True
4 changes: 3 additions & 1 deletion src/currency_quote/domain/services/get_currency_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def last(self) -> dict:
return self.currency_repository(self.validate_currency_code()).get_last_quote()

def history(self, reference_date: int) -> dict:
return {"reference_date": reference_date}
return self.currency_repository(
self.validate_currency_code()
).get_history_quote(reference_date=reference_date)

def validate_currency_code(self) -> str:
valid_list = ValidateCurrencyUseCase.execute(self.currency_list)
Expand Down

0 comments on commit ba21ccb

Please sign in to comment.