diff --git a/Tasks/Lab10/RankingService/RankingService.sln b/Tasks/Lab10/RankingService/RankingService.sln new file mode 100644 index 0000000..25a4851 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RankingService", "RankingService\RankingService.csproj", "{BC31F4B3-2FAF-4E74-BDFB-B642F8F74D35}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BC31F4B3-2FAF-4E74-BDFB-B642F8F74D35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC31F4B3-2FAF-4E74-BDFB-B642F8F74D35}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC31F4B3-2FAF-4E74-BDFB-B642F8F74D35}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC31F4B3-2FAF-4E74-BDFB-B642F8F74D35}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {93368568-85F1-41B9-983B-B459F5C738D4} + EndGlobalSection +EndGlobal diff --git a/Tasks/Lab10/RankingService/RankingService/Competitor.cs b/Tasks/Lab10/RankingService/RankingService/Competitor.cs new file mode 100644 index 0000000..c6489ad --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/Competitor.cs @@ -0,0 +1,8 @@ +namespace RankingService +{ + public class Competitor + { + public string? Name { get; set; } + public string? Time { get; set; } + } +} diff --git a/Tasks/Lab10/RankingService/RankingService/Program.cs b/Tasks/Lab10/RankingService/RankingService/Program.cs new file mode 100644 index 0000000..2b7ea26 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/Program.cs @@ -0,0 +1,33 @@ +using Microsoft.OpenApi.Models; +using System.Net; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen( + (options) => + { + options.SwaggerDoc( + "v1", + new OpenApiInfo + { + Version = "v1", + Title = "Ranking API", + Description = "List rankings" + }); + }); + +// Add services to the container. + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); +app.MapControllers(); +app.Run(); diff --git a/Tasks/Lab10/RankingService/RankingService/Properties/launchSettings.json b/Tasks/Lab10/RankingService/RankingService/Properties/launchSettings.json new file mode 100644 index 0000000..eeda355 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:31447", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "Rankings", + "applicationUrl": "http://localhost:5072", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "Rankings", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Tasks/Lab10/RankingService/RankingService/RankingService.csproj b/Tasks/Lab10/RankingService/RankingService/RankingService.csproj new file mode 100644 index 0000000..e0838c6 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/RankingService.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/Tasks/Lab10/RankingService/RankingService/RankingService.http b/Tasks/Lab10/RankingService/RankingService/RankingService.http new file mode 100644 index 0000000..6b9d939 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/RankingService.http @@ -0,0 +1,6 @@ +@RankingService_HostAddress = http://localhost:5072 + +GET {{RankingService_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Tasks/Lab10/RankingService/RankingService/RankingsController.cs b/Tasks/Lab10/RankingService/RankingService/RankingsController.cs new file mode 100644 index 0000000..715d536 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/RankingsController.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace RankingService +{ + [Route("[controller]")] + [ApiController] + public class RankingsController : ControllerBase + { + private string[] ranks = { + "Mueller Stefan,02:31:14", + "Marti Adrian,2:30:09", + "Kiptum Daniel,2:11:31", + "Ancay Tarcis,2:20:02", + "Kreibuhl Christian,2:21:47", + "Ott Michael,2:33:48", + "Menzi Christoph,2:27:26", + "Oliver Ruben,2:32:12", + "Elmer Beat,2:33:53", + "Kuehni Martin,2:33:36" + }; + + private Lazy> competitors; + + public RankingsController() + { + competitors = new Lazy>( + () => + { + List result = new(); + + foreach (string rank in ranks) + { + string[] items = rank.Split(','); + + result.Add( + new Competitor + { + Name = items[0], + Time = items[1] + }); + } + + return result; + }); + } + + [HttpGet] + public ActionResult> Get() + { + return competitors.Value; + } + } +} diff --git a/Tasks/Lab10/RankingService/RankingService/appsettings.Development.json b/Tasks/Lab10/RankingService/RankingService/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Tasks/Lab10/RankingService/RankingService/appsettings.json b/Tasks/Lab10/RankingService/RankingService/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Tasks/Lab10/RankingService/RankingService/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}