diff --git a/GradDemo.Api/Controllers/CryptoController.cs b/GradDemo.Api/Controllers/CryptoController.cs index cdbca2f..7ecb227 100644 --- a/GradDemo.Api/Controllers/CryptoController.cs +++ b/GradDemo.Api/Controllers/CryptoController.cs @@ -44,5 +44,28 @@ public async Task> GetCoin(string coinId, string cu return Response.Error("Something went wrong"); } + + [HttpGet("GetAllCurrencies")] + public async Task> GetAllCurrencies() + { + string[]? res; + + res = await _coinGeckoProvider.GetAllCurrency(); + + if (res != null) + { + return Response.Successful(res); + + } + + return Response.Error("Something went wrong"); + } + + [HttpPost("{CurrencySymbol}")] + public void SetCurrencyPreference(string CurrencySymbol) + { + // what should I do??? + } + } } diff --git a/GradDemo.Api/Controllers/Currency.cs b/GradDemo.Api/Controllers/Currency.cs new file mode 100644 index 0000000..0c4bd22 --- /dev/null +++ b/GradDemo.Api/Controllers/Currency.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GradDemo.Api.Controllers +{ + public class Currency + { + public string? Symbol { get; set; } + } +} diff --git a/GradDemo.Api/Controllers/CurrencyBase.cs b/GradDemo.Api/Controllers/CurrencyBase.cs new file mode 100644 index 0000000..9d34e81 --- /dev/null +++ b/GradDemo.Api/Controllers/CurrencyBase.cs @@ -0,0 +1,7 @@ +namespace GradDemo.Api.Controllers +{ + public abstract class CurrencyBase + { + public abstract string Symbol { get; set; } + } +} \ No newline at end of file diff --git a/GradDemo.Api/Providers/CoinGeckoProvider.cs b/GradDemo.Api/Providers/CoinGeckoProvider.cs index 7885a9b..260a1d7 100644 --- a/GradDemo.Api/Providers/CoinGeckoProvider.cs +++ b/GradDemo.Api/Providers/CoinGeckoProvider.cs @@ -1,4 +1,5 @@ -using GradDemo.Api.Models.CoinGecko; +using GradDemo.Api.Controllers; +using GradDemo.Api.Models.CoinGecko; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -43,5 +44,22 @@ public CoinGeckoProvider(string baseUrl) return null; } + + public async Task GetAllCurrency() + { + string[]? resultValue = null; + + string url = $"/api/v3/simple/supported_vs_currencies"; + HttpResponseMessage response = await client.GetAsync(url); + if (response.IsSuccessStatusCode) + { + var res = await response.Content.ReadAsStringAsync(); + var coinGeckoResult = JsonConvert.DeserializeObject(res); + resultValue = coinGeckoResult; + return resultValue; + } + + return null; + } } } diff --git a/GradDemo.Api/Startup.cs b/GradDemo.Api/Startup.cs index 7f7b37b..aec0d3f 100644 --- a/GradDemo.Api/Startup.cs +++ b/GradDemo.Api/Startup.cs @@ -82,7 +82,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Applicat { db.Database.Migrate(); } - + } } } diff --git a/GradDemo.Tests/CallHelper.cs b/GradDemo.Tests/CallHelper.cs index 32198f4..74df71e 100644 --- a/GradDemo.Tests/CallHelper.cs +++ b/GradDemo.Tests/CallHelper.cs @@ -20,7 +20,7 @@ public static class CallHelper var content = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json"); var result = await client.PostAsync(path, content); var resultContent = await ParseContent(result.Content); - return (resultContent, result); + throw new Exception("test fail"); } private static async Task ParseContent(HttpContent content) where T : class diff --git a/GradDemo.Tests/UnitTest1.cs b/GradDemo.Tests/UnitTest1.cs index a728f53..5b00013 100644 --- a/GradDemo.Tests/UnitTest1.cs +++ b/GradDemo.Tests/UnitTest1.cs @@ -135,5 +135,21 @@ public async Task TestGetCurrency() Assert.IsTrue(usdResult.content.Payload.Value < zarresult.content.Payload.Value); } + + [Test] + public async Task TestSetCurrencyPref() + { + + string currencyPref = "usd"; + var usdResult = await CallHelper.GetAndDeserialize>(_httpClient, $"/api/v3/simple/price?ids=bitcoin&vs_currencies={currencyPref}"); + + Assert.IsTrue(usdResult.httpResponse.IsSuccessStatusCode); + + + + Assert.IsTrue(usdResult.httpResponse.IsSuccessStatusCode); + + Assert.IsTrue(usdResult.content.Payload == currencyPref); + } } } \ No newline at end of file