-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new API service and Blazor app components
- Added `CountryDataController` to handle API requests for country data. - Updated `Program.cs` to configure services, middleware, and distributed application builder. - Added `launchSettings.json` for HTTP/HTTPS profiles and environment variables. - Implemented `CountryDataServices` and `ICountryDataServices` for country data methods. - Configured logging settings in `appsettings.Development.json` and `appsettings.json`. - Updated project references and package references in `dotnetBlazorFullStuck.ApiService.csproj`. - Added `dotnetBlazorFullStuck.AppHost.csproj` and `dotnetBlazorFullStuck.ServiceDefaults.csproj`. - Added Blazor components: `App.razor`, `MainLayout.razor`, `NavMenu.razor`, `Counter.razor`, `CurrencyByCountryCode.razor`, `RegionsByCountryCode.razor`, `Error.razor`, `Home.razor`, and `Routes.razor`. - Updated `_Imports.razor` for common components and services. - Added `CountryClient` for HTTP requests to API endpoints. - Added `Country` class for data models. - Enhanced navigation menu styles in `NavMenu.razor.css`. - Added `app.css` for application styles and `favicon.png`.
- Loading branch information
1 parent
2bd305c
commit 8db0de1
Showing
81 changed files
with
62,890 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/Controllers/CountryDataController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using dotnetBlazorFullStuck.ApiService.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace dotnetBlazorFullStuck.ApiService.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/")] | ||
public class CountryDataController : ControllerBase | ||
{ | ||
private readonly ICountryDataServices _countryDataServices; | ||
|
||
public CountryDataController(ICountryDataServices countryDataServices) | ||
{ | ||
_countryDataServices = countryDataServices; | ||
} | ||
|
||
|
||
|
||
[HttpGet("countrydata")] | ||
public async Task<IActionResult> GetCountryDataAsync([FromQuery] int offset = 1, [FromQuery] int limit = 20, [FromQuery] string? serchQuery = null) | ||
{ | ||
var data = await _countryDataServices.GetCountryDataAsync(offset, limit, serchQuery); | ||
return Ok(data); | ||
} | ||
|
||
|
||
[HttpGet("country/{code}")] | ||
public async Task<IActionResult> GetCountryByCodeAsync(string code) | ||
{ | ||
var data = await _countryDataServices.GetCountryByCodeAsync(code); | ||
return Ok(data); | ||
} | ||
|
||
|
||
|
||
[HttpGet("countryflag/{countrycode}")] | ||
public async Task<IActionResult> GetCountryFlagAsync(string countrycode) | ||
{ | ||
var data = await _countryDataServices.GetCountryFlagAsync(countrycode); | ||
return Ok(data); | ||
} | ||
|
||
|
||
[HttpGet("regions/{code}")] | ||
|
||
public async Task<IActionResult> GetRegionsByCountryCodeAsync(string code) | ||
{ | ||
var data = await _countryDataServices.GetRegionsByCountryCodeAsync(code); | ||
return Ok(data); | ||
} | ||
|
||
|
||
|
||
[HttpGet("currency/{code}")] | ||
public async Task<IActionResult> GetCurrencyAsync(string code) | ||
{ | ||
var data = await _countryDataServices.GetCurrencyAsync(code); | ||
return Ok(data); | ||
} | ||
|
||
|
||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using CountryData.Standard; | ||
using dotnetBlazorFullStuck.ApiService.Services; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add service defaults & Aspire client integrations. | ||
builder.AddServiceDefaults(); | ||
|
||
// Add services to the container. | ||
builder.Services.AddProblemDetails(); | ||
|
||
|
||
|
||
builder.Services.AddScoped<CountryHelper>(); | ||
builder.Services.AddScoped<ICountryDataServices, CountryDataServices>(); | ||
|
||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi | ||
builder.Services.AddOpenApi(); | ||
builder.Services.AddControllers(); | ||
builder.Services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new() { Title = "My API", Version = "v1" }); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
app.UseExceptionHandler(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.MapOpenApi(); | ||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1")); | ||
app.UseSwagger(); | ||
} | ||
|
||
|
||
|
||
app.MapDefaultEndpoints(); | ||
app.MapControllers(); | ||
|
||
app.Run(); | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "http://localhost:5418", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "https://localhost:7569;http://localhost:5418", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/Services/CountryDataServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using CountryData.Standard; | ||
using Newtonsoft.Json; | ||
|
||
namespace dotnetBlazorFullStuck.ApiService.Services | ||
{ | ||
public class CountryDataServices : ICountryDataServices | ||
{ | ||
private readonly CountryHelper _countryHelper; | ||
|
||
public CountryDataServices(CountryHelper countryHelper) | ||
{ | ||
_countryHelper = countryHelper; | ||
} | ||
|
||
/// <summary> | ||
/// Get country data with pagination and search | ||
/// </summary> | ||
/// <param name="offset"></param> | ||
/// <param name="limit"></param> | ||
/// <param name="serchQuery"></param> | ||
/// <returns></returns> | ||
|
||
public Task<string> GetCountryDataAsync(int offset = 1, int limit = 20, string? serchQuery = null) | ||
{ | ||
var countries = _countryHelper.GetCountryData(); | ||
if (!string.IsNullOrEmpty(serchQuery)) | ||
{ | ||
|
||
serchQuery = serchQuery.ToLower(); | ||
countries = countries.Where(x => x.CountryName.ToLower().Contains(serchQuery)).ToList(); | ||
} | ||
var pagination = countries.Skip((offset - 1) * limit).Take(limit).ToList(); | ||
|
||
if (!pagination.Any()) | ||
{ | ||
return Task.FromResult("No data found"); | ||
} | ||
|
||
return Task.FromResult(JsonConvert.SerializeObject(pagination, Formatting.Indented)); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
/// <summary> | ||
/// Get country by code | ||
/// </summary> | ||
/// <param name="code"></param> | ||
/// <returns></returns> | ||
public Task<string> GetCountryByCodeAsync(string code) | ||
{ | ||
var country = _countryHelper.GetCountryByCode(code); | ||
if (country == null) | ||
{ | ||
return Task.FromResult("No data found"); | ||
} | ||
return Task.FromResult(JsonConvert.SerializeObject(country, Formatting.Indented)); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Get country by phone code | ||
/// </summary> | ||
/// <param name="phoneCode"></param> | ||
/// <returns></returns> | ||
|
||
public Task<string> GetCountryByPhoneCodeAsync(string phoneCode) | ||
{ | ||
var country = _countryHelper.GetCountryByPhoneCode(phoneCode); | ||
if (country == null) | ||
{ | ||
return Task.FromResult("No data found"); | ||
} | ||
return Task.FromResult(JsonConvert.SerializeObject(country, Formatting.Indented)); | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// .Get country flag by country code | ||
/// </summary> | ||
/// <param name="countrycode"></param> | ||
/// <returns></returns> | ||
|
||
public Task<string> GetCountryFlagAsync(string countrycode) | ||
{ | ||
var flag = _countryHelper.GetCountryEmojiFlag(countrycode); | ||
if (string.IsNullOrEmpty(flag)) | ||
{ | ||
return Task.FromResult("No data found"); | ||
} | ||
return Task.FromResult(flag); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Get currency by country code | ||
/// </summary> | ||
/// <param name="code"></param> | ||
/// <returns></returns> | ||
public Task<IEnumerable<Currency>> GetCurrencyAsync(string code) | ||
{ | ||
var currency = _countryHelper.GetCurrencyCodesByCountryCode(code); | ||
return Task.FromResult(currency); | ||
} | ||
|
||
public Task<List<Regions>> GetRegionsByCountryCodeAsync(string code) | ||
{ | ||
var regions = _countryHelper.GetRegionByCountryCode(code); | ||
return Task.FromResult(regions); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/Services/ICountryDataServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using CountryData.Standard; | ||
|
||
namespace dotnetBlazorFullStuck.ApiService.Services | ||
{ | ||
public interface ICountryDataServices | ||
{ | ||
Task<string> GetCountryByCodeAsync(string code); | ||
Task<string> GetCountryByPhoneCodeAsync(string phoneCode); | ||
Task<string> GetCountryDataAsync(int offset = 1, int limit = 20, string? serchQuery = null); | ||
Task<string> GetCountryFlagAsync(string countrycode); | ||
Task<List<Regions>> GetRegionsByCountryCodeAsync(string code); | ||
|
||
Task<IEnumerable<Currency>> GetCurrencyAsync(string code); | ||
|
||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
dotnetBlazorFullStuck/dotnetBlazorFullStuck.ApiService/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
19 changes: 19 additions & 0 deletions
19
...tBlazorFullStuck/dotnetBlazorFullStuck.ApiService/dotnetBlazorFullStuck.ApiService.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\dotnetBlazorFullStuck.ServiceDefaults\dotnetBlazorFullStuck.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CountryData.Standard" Version="1.5.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
dotnetBlazorFullStuck/dotnetBlazorFullStuck.AppHost/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var apiService = builder.AddProject<Projects.dotnetBlazorFullStuck_ApiService>("apiservice"); | ||
|
||
builder.AddProject<Projects.dotnetBlazorFullStuck_Web>("webfrontend") | ||
.WithExternalHttpEndpoints() | ||
.WithReference(apiService) | ||
.WaitFor(apiService); | ||
|
||
builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
dotnetBlazorFullStuck/dotnetBlazorFullStuck.AppHost/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:17109;http://localhost:15207", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21232", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22073" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15207", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19042", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20098" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dotnetBlazorFullStuck/dotnetBlazorFullStuck.AppHost/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
dotnetBlazorFullStuck/dotnetBlazorFullStuck.AppHost/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Aspire.Hosting.Dcp": "Warning" | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
dotnetBlazorFullStuck/dotnetBlazorFullStuck.AppHost/dotnetBlazorFullStuck.AppHost.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>6be278e0-6fab-47d8-857a-ab5c1d9ab9f8</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\dotnetBlazorFullStuck.ApiService\dotnetBlazorFullStuck.ApiService.csproj" /> | ||
<ProjectReference Include="..\dotnetBlazorFullStuck.Web\dotnetBlazorFullStuck.Web.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.