Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3lxxx r3ally 1s c00l #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions GradDemo.Api/Controllers/CryptoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,28 @@ public async Task<Response<CryptoCoinResponse>> GetCoin(string coinId, string cu

return Response<CryptoCoinResponse>.Error("Something went wrong");
}

[HttpGet("GetAllCurrencies")]
public async Task<Response<string[]>> GetAllCurrencies()
{
string[]? res;

res = await _coinGeckoProvider.GetAllCurrency();

if (res != null)
{
return Response<string[]>.Successful(res);

}

return Response<string[]>.Error("Something went wrong");
}

[HttpPost("{CurrencySymbol}")]
public void SetCurrencyPreference(string CurrencySymbol)
{
// what should I do???
}

}
}
12 changes: 12 additions & 0 deletions GradDemo.Api/Controllers/Currency.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
7 changes: 7 additions & 0 deletions GradDemo.Api/Controllers/CurrencyBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GradDemo.Api.Controllers
{
public abstract class CurrencyBase
{
public abstract string Symbol { get; set; }
}
}
20 changes: 19 additions & 1 deletion GradDemo.Api/Providers/CoinGeckoProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,5 +44,22 @@ public CoinGeckoProvider(string baseUrl)

return null;
}

public async Task<string[]?> 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<string[]?>(res);
resultValue = coinGeckoResult;
return resultValue;
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion GradDemo.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Applicat
{
db.Database.Migrate();
}

}
}
}
2 changes: 1 addition & 1 deletion GradDemo.Tests/CallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(result.Content);
return (resultContent, result);
throw new Exception("test fail");
}

private static async Task<T?> ParseContent<T>(HttpContent content) where T : class
Expand Down
16 changes: 16 additions & 0 deletions GradDemo.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response<string>>(_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);
}
}
}