Skip to content

Commit

Permalink
Add currency support and update project configurations
Browse files Browse the repository at this point in the history
Re-added `CountryData.Sample.Web.API` project with a new GUID and updated solution configurations accordingly. Enhanced `README.md` with a logo and details on new methods `GetCurrencyCodesByCountryCode` and `GetCountryByCurrencyCode`. Updated `Program.cs` in `CountryData.Sample.CountryConsoleProject` to call new methods. Added new endpoints in `CountryController.cs` for the new methods. Removed `InvariantGlobalization` from `CountryData.Sample.Web.API.csproj`. Updated `Program.cs` in `CountryData.Sample.Web.API` to add controllers and remove comments. Added `Currency` property to `Country.cs` in `CountryData.Standard`. Enhanced `CountryHelper.cs` with new methods, fixed formatting, and added exception handling. Introduced new unit tests in `CountryHelperTests` to verify currency-related methods. Added `Currency` class in new `CountryData.Standard` namespace.
  • Loading branch information
Clifftech123 committed Jul 26, 2024
1 parent c3cf9d6 commit e8b183a
Show file tree
Hide file tree
Showing 14 changed files with 1,754 additions and 54 deletions.
Binary file added Assets/CountryData.Net.Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions CountryData.Standard.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{131F8946-782
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{3803AB02-5C70-4523-AA4E-8BEE9AD6D592}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CountryData.Sample.Web.API", "sample\CountryData.Sample.Web.API\CountryData.Sample.Web.API.csproj", "{787E809D-2E54-47F0-A5CB-8C0D383D327E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CountryData.Sample.MAUI", "sample\CountryData.Sample.MAUI\CountryData.Sample.MAUI\CountryData.Sample.MAUI.csproj", "{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CountryData.Sample.Web.API", "sample\CountryData.Sample.Web.API\CountryData.Sample.Web.API.csproj", "{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -53,16 +53,16 @@ Global
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Release|Any CPU.Build.0 = Release|Any CPU
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Release|Any CPU.Build.0 = Release|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.Build.0 = Release|Any CPU
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.Deploy.0 = Release|Any CPU
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -71,8 +71,8 @@ Global
{BFFCBBCD-4DD4-4EBE-8282-A4694E6A0ECA} = {EBEF4582-3E32-4FBA-92CA-335DD47C2B4B}
{A450767F-7970-4A30-834E-3E086B87D925} = {420B8450-0A31-431D-90B0-A5C9C7B314C9}
{397666FE-700B-446E-B4EC-13ACF0DDDEBE} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
{787E809D-2E54-47F0-A5CB-8C0D383D327E} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD61C5EF-9299-42A8-81E2-D96FAF1BC81D}
Expand Down
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# :earth_africa: CountryData.Net
[![Gitter](https://badges.gitter.im/CountryDataDotnet/community.svg)](https://gitter.im/CountryDataDotnet/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
A simple cross-platform offline .NET library for getting Global Country Data without making any HTTP calls.
<!-- logo -->

![Logo](./Assets/CountryData.Net.Logo.png)


| | |
Expand Down Expand Up @@ -42,6 +42,24 @@ For more detailed instructions and comprehensive information about the library,




### Methods and Descriptions

The CountryData.Standard library provides a set of methods that allow you to retrieve country data, flags, regions, and phone codes. The following table lists the available methods and their descriptions.

| Method | Description |
|--------|-------------|
| [`GetCountryData()`](./docs/README.md) | Returns all country data including region, short code, and country name. |
| [`GetCountryByCode(string shortCode)`](./docs/README.md) | Returns a single country's data by its short code. |
| [`GetCountryEmojiFlag(string shortCode)`](./docs/README.md) | Gets the flag of the country, represented as an emoji, by the country's short code. |
| [`GetRegionByCountryCode(string shortCode)`](./docs/README.md) | Selects and returns a list of regions for a particular country identified by its short code. |
| [`GetCountries()`](./docs/README.md) | Gets the list of all country names. |
| [`GetPhoneCodeByCountryShortCode(string shortCode)`](./docs/README.md) | Returns a single country's phone code by its short code. |
| [`GetCountryByPhoneCode(string phoneCode)`](./docs/README.md) | Returns country data for the country associated with the specified phone code. |
| [`GetCurrencyCodesByCountryCode(string shortCode)`](./docs/README.md) | Returns a list of currency codes for a specific country identified by its short code. |
| [`GetCountryByCurrencyCode(string currencyCode)`](./docs/README.md) | Returns a list of countries that use the specified currency code. |


### Initialize the Country data object

```cSharp
Expand Down Expand Up @@ -90,24 +108,6 @@ Console.WriteLine(CountryName);
```




### Methods and Descriptions

The CountryData.Standard library provides a set of methods that allow you to retrieve country data, flags, regions, and phone codes. The following table lists the available methods and their descriptions.

| Method | Description |
|--------|-------------|
| [`GetCountryData()`](./docs/README.md) | Returns all country data including region, short code, and country name. |
| [`GetCountryByCode(string shortCode)`](./docs/README.md) | Returns a single country's data by its short code. |
| [`GetCountryEmojiFlag(string shortCode)`](./docs/README.md) | Gets the flag of the country, represented as an emoji, by the country's short code. |
| [`GetRegionByCountryCode(string ShortCode)`](./docs/README.md) | Selects and returns a list of regions for a particular country identified by its short code. |
| [`GetCountries()`](./docs/README.md) | Gets the list of all country names. |
| [`GetPhoneCodeByCountryShortCode(string shortCode)`](./docs/README.md) | Returns a single country's phone code by its short code. |
| [`GetCountryByPhoneCode(string phoneCode)`](./docs/README.md) | Returns country data for the country associated with the specified phone code. |



### ISO-3166-1 country codes

For a list of supported ISO-3166-1 country codes, PhoneCode, Flags, ISO and , Unicode please refer to the [Country Details](./CountryData/CountryDetails.md) file.
Expand All @@ -129,7 +129,6 @@ We are committed to fostering a welcoming and respectful community for everyone.
* Country ShortCode Enums



### License

This project is licensed under the terms of the [LICENSE](LICENSE).
26 changes: 26 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,30 @@ Country GetCountryByPhoneCode(string phoneCode);
This method is particularly useful when you have a phone code and need to retrieve the corresponding country's information. Simply pass the phone code as a string argument, and the method will return a `Country` object filled with relevant data.


### GetCurrencyCodesByCountryCode(string shortCode)

The `GetCurrencyCodesByCountryCode()` method is designed to fetch the currency codes used in a specific country using its ISO 3166-1 alpha-2 code. This method returns a `List<string>`, with each string representing a distinct currency code used in the specified country.

Here's the method signature in C#:

```csharp

List<string> GetCurrencyCodesByCountryCode(string shortCode);
```

This method is particularly useful for applications that need to display or analyze currency data within a specific country. Simply pass the country

### GetCountryByCurrencyCode(string currencyCode)

The `GetCountryByCurrencyCode()` method is designed to fetch detailed data for a specific country using its currency code. This method returns a `Country` object, providing a wealth of information about the country, including its name, region, flag, and ISO code.

Here's the method signature in C#:

```csharp

Country GetCountryByCurrencyCode(string currencyCode);
```

This method is particularly useful when you have a currency code and need to retrieve the corresponding country's information. Simply pass the currency code as a string argument, and the method will return a `Country` object filled with relevant data.


47 changes: 40 additions & 7 deletions sample/CountryData.Sample.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public static void Main()
GetCountryFlag("US");
GetPhoneCodeByCountryShortCode("AF");
GetCountryByPhoneCode("+233");
GetCurrencyCodesByCountryCode("US");
GetCountryByCurrencyCode("GHS");
}

/// <summary>
/// Retrieves a list of all countries and prints them to the console.
/// </summary>
static void GetCountries()
private static void GetCountries()
{
var countries = _helper.GetCountries();
Console.WriteLine("Countries:");
Expand All @@ -43,7 +45,7 @@ static void GetCountries()
/// Retrieves the data for a given country code and prints it to the console.
/// </summary>
/// <param name="countryCode">The ISO country code.</param>
static void GetCountryByCode(string countryCode)
private static void GetCountryByCode(string countryCode)
{
var country = _helper.GetCountryByCode(countryCode);
Console.WriteLine($"Country data for {countryCode}:");
Expand All @@ -53,7 +55,7 @@ static void GetCountryByCode(string countryCode)
/// <summary>
/// Retrieves comprehensive data for all countries and prints it to the console.
/// </summary>
static void GetCountryData()
private static void GetCountryData()
{
var countryData = _helper.GetCountryData();
Console.WriteLine("Country data:");
Expand All @@ -67,7 +69,7 @@ static void GetCountryData()
/// Retrieves the regions for a given country code and prints them to the console.
/// </summary>
/// <param name="countryCode">The ISO country code.</param>
static void GetRegionsByCountryCode(string countryCode)
private static void GetRegionsByCountryCode(string countryCode)
{
var regions = _helper.GetRegionByCountryCode(countryCode);
Console.WriteLine($"Regions for {countryCode}:");
Expand All @@ -81,7 +83,7 @@ static void GetRegionsByCountryCode(string countryCode)
/// Retrieves the emoji flag for a given country short code and prints it to the console.
/// </summary>
/// <param name="shortCode">The country short code.</param>
static void GetCountryFlag(string shortCode)
private static void GetCountryFlag(string shortCode)
{
var flag = _helper.GetCountryEmojiFlag(shortCode);
Console.WriteLine($"Flag for {shortCode}:");
Expand All @@ -92,7 +94,7 @@ static void GetCountryFlag(string shortCode)
/// Retrieves the phone code for a given country short code and prints it to the console.
/// </summary>
/// <param name="shortCode">The country short code.</param>
static void GetPhoneCodeByCountryShortCode(string shortCode)
private static void GetPhoneCodeByCountryShortCode(string shortCode)
{
var phoneCode = _helper.GetPhoneCodeByCountryShortCode(shortCode);
Console.WriteLine($"Phone code for {shortCode}:");
Expand All @@ -103,7 +105,7 @@ static void GetPhoneCodeByCountryShortCode(string shortCode)
/// Retrieves the country name for a given phone code and prints it to the console.
/// </summary>
/// <param name="phoneCode">The phone code.</param>
static void GetCountryByPhoneCode(string phoneCode)
private static void GetCountryByPhoneCode(string phoneCode)
{
var countries = _helper.GetCountryByPhoneCode(phoneCode);
Console.WriteLine($"Country for phone code {phoneCode}:");
Expand All @@ -112,5 +114,36 @@ static void GetCountryByPhoneCode(string phoneCode)
Console.WriteLine(country.CountryName);
}
}


/// <summary>
/// Retrieves and prints the currency codes for a given country code.
/// </summary>
/// <param name="shortCode">The short country code to look up currency codes for.</param>
private static void GetCurrencyCodesByCountryCode(string shortCode)
{
var currencyCodes = _helper.GetCurrencyCodesByCountryCode(shortCode);
Console.WriteLine($"Currency codes for {shortCode}:");
foreach (var currencyCode in currencyCodes)
{
Console.WriteLine(currencyCode.Code);
}
}



/// <summary>
/// Retrieves and prints the countries that use a given currency code.
/// </summary>
/// <param name="currencyCode">The currency code to look up countries for.</param>
private static void GetCountryByCurrencyCode(string currencyCode)
{
var countries = _helper.GetCountryByCurrencyCode(currencyCode);
Console.WriteLine($"Countries for currency code {currencyCode}:");
foreach (var country in countries)
{
Console.WriteLine(country.CountryName);
}
}
}
}
41 changes: 36 additions & 5 deletions sample/CountryData.Sample.Web.API/Controllers/CountryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public CountryController(CountryHelper helper)
_helper = helper;
}




/// <summary>
/// Retrieves a list of all countries.
/// </summary>
Expand All @@ -36,7 +33,6 @@ public IActionResult GetCountries()
}



/// <summary>
/// Retrieves the country data for a given country code.
/// </summary>
Expand Down Expand Up @@ -105,7 +101,7 @@ public IActionResult GetRegionsByCountryCode([FromQuery] string countryCode)
[HttpGet("flag")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(404)]
public IActionResult GetCountryEmojiFlag([FromQuery] string countryCode)
public IActionResult GetCountryEmojiFlag([FromQuery] string countryCode)
{
var flag = _helper.GetCountryEmojiFlag(countryCode);
if (flag == null)
Expand Down Expand Up @@ -153,7 +149,42 @@ public IActionResult GetCountryByPhoneCode([FromQuery] string phoneCode)
}


/// <summary>
/// Retrieves the currency codes for a given country code.
/// </summary>
/// <param name="countryCode">The ISO country code.</param>
/// <returns>A list of currency codes for the specified country. If no currency codes are found, a NotFound result is returned.</returns>
[HttpGet("currencyCodesByCountryCode")]
[ProducesResponseType(typeof(IEnumerable<Currency>), 200)]
[ProducesResponseType(404)]
public IActionResult GetCurrencyCodesByCountryCode([FromQuery] string countryCode)
{
var currencyCodes = _helper.GetCurrencyCodesByCountryCode(countryCode);
if (currencyCodes == null)
{
return NotFound();
}
return Ok(currencyCodes);
}


/// <summary>
/// Retrieves the countries that use a specific currency code.
/// </summary>
/// <param name="currencyCode">The currency code to search for.</param>
/// <returns>A list of countries that use the specified currency code. If no countries are found, a NotFound result is returned.</returns>
[HttpGet("countryByCurrencyCode")]
[ProducesResponseType(typeof(IEnumerable<Country>), 200)]
[ProducesResponseType(404)]
public IActionResult GetCountryByCurrencyCode([FromQuery] string currencyCode)
{
var countryByCurrencyCode = _helper.GetCountryByCurrencyCode(currencyCode);
if (countryByCurrencyCode == null)
{
return NotFound();
}
return Ok(countryByCurrencyCode);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
Expand Down
Empty file.
6 changes: 2 additions & 4 deletions sample/CountryData.Sample.Web.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Register CountryHelper service
builder.Services.AddScoped<CountryData.Standard.CountryHelper>();

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand All @@ -24,5 +23,4 @@

app.MapControllers();

// Start the application
app.Run();
app.Run();
4 changes: 3 additions & 1 deletion src/CountryData.Standard/Country.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class Country
public string PhoneCode { get; set; }
public string CountryShortCode { get; set; }
public string CountryFlag { get; set; }

public List<Currency> Currency { get; set; }
public List<Regions> Regions { get; set; }

}
}
Loading

0 comments on commit e8b183a

Please sign in to comment.