diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI.sln b/works/Api/lab-01/PokemonAPI/PokemonAPI.sln new file mode 100644 index 0000000..fdfb217 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokemonAPI", "PokemonAPI\PokemonAPI.csproj", "{AB656F88-0D39-4163-8984-28C83362611C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AB656F88-0D39-4163-8984-28C83362611C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj new file mode 100644 index 0000000..3939e20 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj @@ -0,0 +1,13 @@ + + + + net10.0 + enable + enable + + + + + + + diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http new file mode 100644 index 0000000..b2717a7 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http @@ -0,0 +1,6 @@ +@PokemonAPI_HostAddress = http://localhost:5076 + +GET {{PokemonAPI_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs b/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs new file mode 100644 index 0000000..356dfce --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs @@ -0,0 +1,50 @@ +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddOpenApi(); + +var app = builder.Build(); + +var pokemons = new List +{ + new(1, "Pikachu", "Electric", 12), + new(2, "Charmander", "Fire", 8), + new(3, "Squirtle", "Water", 10) +}; + +app.MapGet("/pokemons/{id}", (int id) => +{ + var pokemon = pokemons.FirstOrDefault(p => p.Id == id); + + if (pokemon != null) + { + return Results.Ok(pokemon); + } + else + { + return Results.NotFound(); + } +}); + +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); +} +app.MapGet("/hello", () => "Привет, мир API!"); +app.MapGet("/pokemons", () => Results.Ok(pokemons)); + + +app.Run(); + +public record Pokemon( + int Id, + string Name, + string Type, + int Level +); + +public record PokemonInput( + string Name, + string Type, + int Level +); + diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json new file mode 100644 index 0000000..80e65fa --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5076", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7190;http://localhost:5076", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/works/Api/lab-01/lab-01 - PokeAPI.zip b/works/Api/lab-01/lab-01 - PokeAPI.zip new file mode 100644 index 0000000..02c6123 Binary files /dev/null and b/works/Api/lab-01/lab-01 - PokeAPI.zip differ