Обновленние-добавление

This commit is contained in:
ArhaNge1
2026-10-21 15:39:13 +03:00
parent efb41a5d8a
commit ebd04219c5
34 changed files with 35543 additions and 36 deletions
+9
View File
@@ -0,0 +1,9 @@
# Secrets
.env*
# Dependencies
node_modules
# OS files
.DS_Store
Thumbs.db
@@ -0,0 +1,16 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokedexApi", "PokedexApi\PokedexApi.csproj", "{342D404B-EE24-4EF6-95DF-A79BD34A11E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{342D404B-EE24-4EF6-95DF-A79BD34A11E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{342D404B-EE24-4EF6-95DF-A79BD34A11E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{342D404B-EE24-4EF6-95DF-A79BD34A11E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{342D404B-EE24-4EF6-95DF-A79BD34A11E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.11"/>
</ItemGroup>
</Project>
@@ -0,0 +1,6 @@
@PokedexApi_HostAddress = http://localhost:5037
GET {{PokedexApi_HostAddress}}/weatherforecast/
Accept: application/json
###
@@ -0,0 +1,93 @@
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
var pokemons = new List<Pokemon>
{
new(1, "Pikachu", "Electric", 12),
new(2, "Charmander", "Fire", 8),
new(3, "Squirtle", "Water", 10)
};
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapGet("/hello", () => "Привет, мир API!");
app.MapGet("/pokemons", () => Results.Ok(pokemons));
app.MapGet("/pokemons/{id:int}", (int id) =>
{
var pokemon = pokemons.FirstOrDefault(p => p.Id == id);
if (pokemon == null)
{
return Results.NotFound();
}
else
{
return Results.Ok(pokemon);
}
});
app.MapPost("/pokemons", (PokemonInput input) =>
{
var errors = Validate(input);
if (errors.Count > 0)
{
return Results.BadRequest(new { errors });
}
var newId = pokemons.Max(p => p.Id) + 1;
var pokemon = new Pokemon(newId, input.Name, input.Type, input.Level);
pokemons.Add(pokemon);
{
return Results.Created($"/pokemons/{newId}", pokemon);
}
});
app.MapPut("/pokemons/{id}", (int id, PokemonInput input) =>
{
var existing = pokemons.FirstOrDefault(p => p.Id == id);
{
return Results.NotFound();
}
var errors = Validate(input);
if (errors.Count > 0)
{
return Results.BadRequest(new { errors });
}
var updated = new Pokemon(id, input.Name, input.Type, input.Level);
pokemons[pokemons.IndexOf(existing)] = updated;
{
return Results.Ok(updated);
}
});
// DELETE /pokemons/{id} — удалить покемона по id
app.MapDelete("/pokemons/{id}", (int id) =>
{
var existing = pokemons.FirstOrDefault(p => p.Id == id);
{
return Results.NotFound();
}
pokemons.Remove(existing);
{
return Results.NoContent();
}
});
app.Run();
public record Pokemon(
int Id,
string Name,
string Type,
int Level);
public record PokemonInput(
string Name,
string Type,
int Level);
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5037",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7299;http://localhost:5037",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
@@ -0,0 +1,21 @@
opencollection: 1.0.0
info:
name: Lab1 - PokeAPI
config:
proxy:
inherit: true
config:
protocol: http
hostname: ""
port: ""
auth:
username: ""
password: ""
bypassProxy: ""
bundled: false
extensions:
bruno:
ignore:
- node_modules
- .git
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff