Skip to content

Commit e8b183a

Browse files
committed
Add currency support and update project configurations
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.
1 parent c3cf9d6 commit e8b183a

14 files changed

Lines changed: 1754 additions & 54 deletions

File tree

Assets/CountryData.Net.Logo.png

82.9 KB
Loading

CountryData.Standard.sln

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{131F8946-782
3131
EndProject
3232
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{3803AB02-5C70-4523-AA4E-8BEE9AD6D592}"
3333
EndProject
34-
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}"
35-
EndProject
3634
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}"
3735
EndProject
36+
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}"
37+
EndProject
3838
Global
3939
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4040
Debug|Any CPU = Debug|Any CPU
@@ -53,16 +53,16 @@ Global
5353
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
5454
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
5555
{397666FE-700B-446E-B4EC-13ACF0DDDEBE}.Release|Any CPU.Build.0 = Release|Any CPU
56-
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57-
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Debug|Any CPU.Build.0 = Debug|Any CPU
58-
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Release|Any CPU.ActiveCfg = Release|Any CPU
59-
{787E809D-2E54-47F0-A5CB-8C0D383D327E}.Release|Any CPU.Build.0 = Release|Any CPU
6056
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6157
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
6258
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
6359
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
6460
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.Build.0 = Release|Any CPU
6561
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB}.Release|Any CPU.Deploy.0 = Release|Any CPU
62+
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5}.Release|Any CPU.Build.0 = Release|Any CPU
6666
EndGlobalSection
6767
GlobalSection(SolutionProperties) = preSolution
6868
HideSolutionNode = FALSE
@@ -71,8 +71,8 @@ Global
7171
{BFFCBBCD-4DD4-4EBE-8282-A4694E6A0ECA} = {EBEF4582-3E32-4FBA-92CA-335DD47C2B4B}
7272
{A450767F-7970-4A30-834E-3E086B87D925} = {420B8450-0A31-431D-90B0-A5C9C7B314C9}
7373
{397666FE-700B-446E-B4EC-13ACF0DDDEBE} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
74-
{787E809D-2E54-47F0-A5CB-8C0D383D327E} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
7574
{2EBA3AC1-C3FE-47B0-8606-917BA212E6AB} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
75+
{A77E8CA8-11B9-41B4-A00C-46BD55756CF5} = {BBA69DE8-BE26-498E-9A62-131EB2494972}
7676
EndGlobalSection
7777
GlobalSection(ExtensibilityGlobals) = postSolution
7878
SolutionGuid = {CD61C5EF-9299-42A8-81E2-D96FAF1BC81D}

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

66

77
| | |
@@ -42,6 +42,24 @@ For more detailed instructions and comprehensive information about the library,
4242

4343

4444

45+
46+
### Methods and Descriptions
47+
48+
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.
49+
50+
| Method | Description |
51+
|--------|-------------|
52+
| [`GetCountryData()`](./docs/README.md) | Returns all country data including region, short code, and country name. |
53+
| [`GetCountryByCode(string shortCode)`](./docs/README.md) | Returns a single country's data by its short code. |
54+
| [`GetCountryEmojiFlag(string shortCode)`](./docs/README.md) | Gets the flag of the country, represented as an emoji, by the country's short code. |
55+
| [`GetRegionByCountryCode(string shortCode)`](./docs/README.md) | Selects and returns a list of regions for a particular country identified by its short code. |
56+
| [`GetCountries()`](./docs/README.md) | Gets the list of all country names. |
57+
| [`GetPhoneCodeByCountryShortCode(string shortCode)`](./docs/README.md) | Returns a single country's phone code by its short code. |
58+
| [`GetCountryByPhoneCode(string phoneCode)`](./docs/README.md) | Returns country data for the country associated with the specified phone code. |
59+
| [`GetCurrencyCodesByCountryCode(string shortCode)`](./docs/README.md) | Returns a list of currency codes for a specific country identified by its short code. |
60+
| [`GetCountryByCurrencyCode(string currencyCode)`](./docs/README.md) | Returns a list of countries that use the specified currency code. |
61+
62+
4563
### Initialize the Country data object
4664

4765
```cSharp
@@ -90,24 +108,6 @@ Console.WriteLine(CountryName);
90108
```
91109

92110

93-
94-
95-
### Methods and Descriptions
96-
97-
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.
98-
99-
| Method | Description |
100-
|--------|-------------|
101-
| [`GetCountryData()`](./docs/README.md) | Returns all country data including region, short code, and country name. |
102-
| [`GetCountryByCode(string shortCode)`](./docs/README.md) | Returns a single country's data by its short code. |
103-
| [`GetCountryEmojiFlag(string shortCode)`](./docs/README.md) | Gets the flag of the country, represented as an emoji, by the country's short code. |
104-
| [`GetRegionByCountryCode(string ShortCode)`](./docs/README.md) | Selects and returns a list of regions for a particular country identified by its short code. |
105-
| [`GetCountries()`](./docs/README.md) | Gets the list of all country names. |
106-
| [`GetPhoneCodeByCountryShortCode(string shortCode)`](./docs/README.md) | Returns a single country's phone code by its short code. |
107-
| [`GetCountryByPhoneCode(string phoneCode)`](./docs/README.md) | Returns country data for the country associated with the specified phone code. |
108-
109-
110-
111111
### ISO-3166-1 country codes
112112

113113
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.
@@ -129,7 +129,6 @@ We are committed to fostering a welcoming and respectful community for everyone.
129129
* Country ShortCode Enums
130130

131131

132-
133132
### License
134133

135134
This project is licensed under the terms of the [LICENSE](LICENSE).

docs/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,30 @@ Country GetCountryByPhoneCode(string phoneCode);
159159
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.
160160

161161

162+
### GetCurrencyCodesByCountryCode(string shortCode)
163+
164+
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.
165+
166+
Here's the method signature in C#:
167+
168+
```csharp
169+
170+
List<string> GetCurrencyCodesByCountryCode(string shortCode);
171+
```
172+
173+
This method is particularly useful for applications that need to display or analyze currency data within a specific country. Simply pass the country
174+
175+
### GetCountryByCurrencyCode(string currencyCode)
176+
177+
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.
178+
179+
Here's the method signature in C#:
180+
181+
```csharp
182+
183+
Country GetCountryByCurrencyCode(string currencyCode);
184+
```
185+
186+
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.
187+
162188

sample/CountryData.Sample.Console/Program.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public static void Main()
2424
GetCountryFlag("US");
2525
GetPhoneCodeByCountryShortCode("AF");
2626
GetCountryByPhoneCode("+233");
27+
GetCurrencyCodesByCountryCode("US");
28+
GetCountryByCurrencyCode("GHS");
2729
}
2830

2931
/// <summary>
3032
/// Retrieves a list of all countries and prints them to the console.
3133
/// </summary>
32-
static void GetCountries()
34+
private static void GetCountries()
3335
{
3436
var countries = _helper.GetCountries();
3537
Console.WriteLine("Countries:");
@@ -43,7 +45,7 @@ static void GetCountries()
4345
/// Retrieves the data for a given country code and prints it to the console.
4446
/// </summary>
4547
/// <param name="countryCode">The ISO country code.</param>
46-
static void GetCountryByCode(string countryCode)
48+
private static void GetCountryByCode(string countryCode)
4749
{
4850
var country = _helper.GetCountryByCode(countryCode);
4951
Console.WriteLine($"Country data for {countryCode}:");
@@ -53,7 +55,7 @@ static void GetCountryByCode(string countryCode)
5355
/// <summary>
5456
/// Retrieves comprehensive data for all countries and prints it to the console.
5557
/// </summary>
56-
static void GetCountryData()
58+
private static void GetCountryData()
5759
{
5860
var countryData = _helper.GetCountryData();
5961
Console.WriteLine("Country data:");
@@ -67,7 +69,7 @@ static void GetCountryData()
6769
/// Retrieves the regions for a given country code and prints them to the console.
6870
/// </summary>
6971
/// <param name="countryCode">The ISO country code.</param>
70-
static void GetRegionsByCountryCode(string countryCode)
72+
private static void GetRegionsByCountryCode(string countryCode)
7173
{
7274
var regions = _helper.GetRegionByCountryCode(countryCode);
7375
Console.WriteLine($"Regions for {countryCode}:");
@@ -81,7 +83,7 @@ static void GetRegionsByCountryCode(string countryCode)
8183
/// Retrieves the emoji flag for a given country short code and prints it to the console.
8284
/// </summary>
8385
/// <param name="shortCode">The country short code.</param>
84-
static void GetCountryFlag(string shortCode)
86+
private static void GetCountryFlag(string shortCode)
8587
{
8688
var flag = _helper.GetCountryEmojiFlag(shortCode);
8789
Console.WriteLine($"Flag for {shortCode}:");
@@ -92,7 +94,7 @@ static void GetCountryFlag(string shortCode)
9294
/// Retrieves the phone code for a given country short code and prints it to the console.
9395
/// </summary>
9496
/// <param name="shortCode">The country short code.</param>
95-
static void GetPhoneCodeByCountryShortCode(string shortCode)
97+
private static void GetPhoneCodeByCountryShortCode(string shortCode)
9698
{
9799
var phoneCode = _helper.GetPhoneCodeByCountryShortCode(shortCode);
98100
Console.WriteLine($"Phone code for {shortCode}:");
@@ -103,7 +105,7 @@ static void GetPhoneCodeByCountryShortCode(string shortCode)
103105
/// Retrieves the country name for a given phone code and prints it to the console.
104106
/// </summary>
105107
/// <param name="phoneCode">The phone code.</param>
106-
static void GetCountryByPhoneCode(string phoneCode)
108+
private static void GetCountryByPhoneCode(string phoneCode)
107109
{
108110
var countries = _helper.GetCountryByPhoneCode(phoneCode);
109111
Console.WriteLine($"Country for phone code {phoneCode}:");
@@ -112,5 +114,36 @@ static void GetCountryByPhoneCode(string phoneCode)
112114
Console.WriteLine(country.CountryName);
113115
}
114116
}
117+
118+
119+
/// <summary>
120+
/// Retrieves and prints the currency codes for a given country code.
121+
/// </summary>
122+
/// <param name="shortCode">The short country code to look up currency codes for.</param>
123+
private static void GetCurrencyCodesByCountryCode(string shortCode)
124+
{
125+
var currencyCodes = _helper.GetCurrencyCodesByCountryCode(shortCode);
126+
Console.WriteLine($"Currency codes for {shortCode}:");
127+
foreach (var currencyCode in currencyCodes)
128+
{
129+
Console.WriteLine(currencyCode.Code);
130+
}
131+
}
132+
133+
134+
135+
/// <summary>
136+
/// Retrieves and prints the countries that use a given currency code.
137+
/// </summary>
138+
/// <param name="currencyCode">The currency code to look up countries for.</param>
139+
private static void GetCountryByCurrencyCode(string currencyCode)
140+
{
141+
var countries = _helper.GetCountryByCurrencyCode(currencyCode);
142+
Console.WriteLine($"Countries for currency code {currencyCode}:");
143+
foreach (var country in countries)
144+
{
145+
Console.WriteLine(country.CountryName);
146+
}
147+
}
115148
}
116149
}

sample/CountryData.Sample.Web.API/Controllers/CountryController.cs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public CountryController(CountryHelper helper)
1515
_helper = helper;
1616
}
1717

18-
19-
20-
2118
/// <summary>
2219
/// Retrieves a list of all countries.
2320
/// </summary>
@@ -36,7 +33,6 @@ public IActionResult GetCountries()
3633
}
3734

3835

39-
4036
/// <summary>
4137
/// Retrieves the country data for a given country code.
4238
/// </summary>
@@ -105,7 +101,7 @@ public IActionResult GetRegionsByCountryCode([FromQuery] string countryCode)
105101
[HttpGet("flag")]
106102
[ProducesResponseType(typeof(string), 200)]
107103
[ProducesResponseType(404)]
108-
public IActionResult GetCountryEmojiFlag([FromQuery] string countryCode)
104+
public IActionResult GetCountryEmojiFlag([FromQuery] string countryCode)
109105
{
110106
var flag = _helper.GetCountryEmojiFlag(countryCode);
111107
if (flag == null)
@@ -153,7 +149,42 @@ public IActionResult GetCountryByPhoneCode([FromQuery] string phoneCode)
153149
}
154150

155151

152+
/// <summary>
153+
/// Retrieves the currency codes for a given country code.
154+
/// </summary>
155+
/// <param name="countryCode">The ISO country code.</param>
156+
/// <returns>A list of currency codes for the specified country. If no currency codes are found, a NotFound result is returned.</returns>
157+
[HttpGet("currencyCodesByCountryCode")]
158+
[ProducesResponseType(typeof(IEnumerable<Currency>), 200)]
159+
[ProducesResponseType(404)]
160+
public IActionResult GetCurrencyCodesByCountryCode([FromQuery] string countryCode)
161+
{
162+
var currencyCodes = _helper.GetCurrencyCodesByCountryCode(countryCode);
163+
if (currencyCodes == null)
164+
{
165+
return NotFound();
166+
}
167+
return Ok(currencyCodes);
168+
}
169+
156170

171+
/// <summary>
172+
/// Retrieves the countries that use a specific currency code.
173+
/// </summary>
174+
/// <param name="currencyCode">The currency code to search for.</param>
175+
/// <returns>A list of countries that use the specified currency code. If no countries are found, a NotFound result is returned.</returns>
176+
[HttpGet("countryByCurrencyCode")]
177+
[ProducesResponseType(typeof(IEnumerable<Country>), 200)]
178+
[ProducesResponseType(404)]
179+
public IActionResult GetCountryByCurrencyCode([FromQuery] string currencyCode)
180+
{
181+
var countryByCurrencyCode = _helper.GetCountryByCurrencyCode(currencyCode);
182+
if (countryByCurrencyCode == null)
183+
{
184+
return NotFound();
185+
}
186+
return Ok(countryByCurrencyCode);
187+
}
157188

158189
}
159190
}

sample/CountryData.Sample.Web.API/CountryData.Sample.Web.API.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<InvariantGlobalization>true</InvariantGlobalization>
87
</PropertyGroup>
98

109
<ItemGroup>

sample/CountryData.Sample.Web.API/CountryData.Sample.Web.API.http

Whitespace-only changes.

sample/CountryData.Sample.Web.API/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
var builder = WebApplication.CreateBuilder(args);
22

33
// Add services to the container.
4+
45
builder.Services.AddControllers();
56
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
67
builder.Services.AddEndpointsApiExplorer();
78
builder.Services.AddSwaggerGen();
8-
99
// Register CountryHelper service
1010
builder.Services.AddScoped<CountryData.Standard.CountryHelper>();
11-
1211
var app = builder.Build();
1312

1413
// Configure the HTTP request pipeline.
@@ -24,5 +23,4 @@
2423

2524
app.MapControllers();
2625

27-
// Start the application
28-
app.Run();
26+
app.Run();

src/CountryData.Standard/Country.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public class Country
88
public string PhoneCode { get; set; }
99
public string CountryShortCode { get; set; }
1010
public string CountryFlag { get; set; }
11+
12+
public List<Currency> Currency { get; set; }
1113
public List<Regions> Regions { get; set; }
12-
14+
1315
}
1416
}

0 commit comments

Comments
 (0)