Exemplo n.º 1
0
        public async ValueTask <Result <decimal, ProblemDetails> > Get(Currencies sourceCurrency,
                                                                       Currencies targetCurrency)
        {
            if (sourceCurrency == Currencies.NotSpecified)
            {
                return(ProblemDetailsBuilder.FailAndLogArgumentNullOrEmpty <decimal>(_logger, nameof(sourceCurrency)));
            }

            if (targetCurrency == Currencies.NotSpecified)
            {
                return(ProblemDetailsBuilder.FailAndLogArgumentNullOrEmpty <decimal>(_logger, nameof(targetCurrency)));
            }

            if (sourceCurrency == targetCurrency)
            {
                return(Result.Success <decimal, ProblemDetails>(1));
            }

            return(await GetDefaultRate(sourceCurrency.ToString(), targetCurrency.ToString())
                   ?? await GetRateFromApi(sourceCurrency, targetCurrency));
        }