generated from admin/template
Дополнил задание с API
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{046DEB9F-C981-49E2-9B1E-37ECDA1F9084}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{046DEB9F-C981-49E2-9B1E-37ECDA1F9084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{046DEB9F-C981-49E2-9B1E-37ECDA1F9084}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{046DEB9F-C981-49E2-9B1E-37ECDA1F9084}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{046DEB9F-C981-49E2-9B1E-37ECDA1F9084}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int pokemonHP = 20;
|
||||
}
|
||||
|
||||
static void pokemonHP(ref int pokemonHP)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
info:
|
||||
name: Create_Post
|
||||
type: http
|
||||
seq: 2
|
||||
|
||||
http:
|
||||
method: POST
|
||||
url: https://jsonplaceholder.typicode.com/posts
|
||||
headers:
|
||||
- name: Content-Type
|
||||
value: application/json
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"title": "Мой первый покемон",
|
||||
"body": "Поймал Пикачу!",
|
||||
"userId": 1
|
||||
}
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
docs: |-
|
||||
**post** `https://jsonplaceholder.typicode.com/posts`
|
||||
|
||||
<br/>
|
||||
|
||||
Данный запрос отправляет на <http://jsonplaceholder.typicode.com>
|
||||
|
||||
[на под раздел post и ](http://jsonplaceholder.typicode.com)
|
||||
@@ -0,0 +1,5 @@
|
||||
name: Environment 1
|
||||
variables:
|
||||
- name: baseUrl
|
||||
value: http://localhost:5090
|
||||
description: http://localhost:5090
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
name: hello
|
||||
type: folder
|
||||
|
||||
request:
|
||||
auth: inherit
|
||||
@@ -0,0 +1,34 @@
|
||||
info:
|
||||
name: get /hello
|
||||
type: http
|
||||
seq: 1
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: "{{baseUrl}}/hello"
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/hello"
|
||||
method: GET
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
headers:
|
||||
- name: Content-Type
|
||||
value: text/plain
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,21 @@
|
||||
opencollection: 1.0.0
|
||||
|
||||
info:
|
||||
name: PokedexApi
|
||||
config:
|
||||
proxy:
|
||||
inherit: true
|
||||
config:
|
||||
protocol: http
|
||||
hostname: ""
|
||||
port: ""
|
||||
auth:
|
||||
username: ""
|
||||
password: ""
|
||||
bypassProxy: ""
|
||||
bundled: false
|
||||
extensions:
|
||||
bruno:
|
||||
ignore:
|
||||
- node_modules
|
||||
- .git
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
name: pokemons
|
||||
type: folder
|
||||
|
||||
request:
|
||||
auth: inherit
|
||||
@@ -0,0 +1,31 @@
|
||||
info:
|
||||
name: get /pokemons
|
||||
type: http
|
||||
seq: 1
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: "{{baseUrl}}/pokemons"
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons"
|
||||
method: GET
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,47 @@
|
||||
info:
|
||||
name: post /pokemons
|
||||
type: http
|
||||
seq: 2
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: POST
|
||||
url: "{{baseUrl}}/pokemons"
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"name": "",
|
||||
"type": "",
|
||||
"level": ""
|
||||
}
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons"
|
||||
method: POST
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"name": "Bulbasaur",
|
||||
"type": "Grass",
|
||||
"level": 6
|
||||
}
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
name: type
|
||||
type: folder
|
||||
|
||||
request:
|
||||
auth: inherit
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
name: "{type}"
|
||||
type: folder
|
||||
|
||||
request:
|
||||
auth: inherit
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
info:
|
||||
name: get /pokemons/type/:type
|
||||
type: http
|
||||
seq: 1
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: "{{baseUrl}}/pokemons/type/:type"
|
||||
params:
|
||||
- name: type
|
||||
value: ""
|
||||
type: path
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons/type/:type"
|
||||
method: GET
|
||||
params:
|
||||
- name: type
|
||||
value: ""
|
||||
type: path
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,39 @@
|
||||
info:
|
||||
name: delete /pokemons/:id
|
||||
type: http
|
||||
seq: 3
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: DELETE
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
method: DELETE
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
name: "{id}"
|
||||
type: folder
|
||||
|
||||
request:
|
||||
auth: inherit
|
||||
@@ -0,0 +1,39 @@
|
||||
info:
|
||||
name: get /pokemons/:id
|
||||
type: http
|
||||
seq: 1
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
method: GET
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,55 @@
|
||||
info:
|
||||
name: put /pokemons/:id
|
||||
type: http
|
||||
seq: 2
|
||||
tags:
|
||||
- PokedexApi
|
||||
|
||||
http:
|
||||
method: PUT
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"name": "",
|
||||
"type": "",
|
||||
"level": ""
|
||||
}
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
forwardAuthorizationHeader: false
|
||||
|
||||
examples:
|
||||
- name: 200 Response
|
||||
description: OK
|
||||
request:
|
||||
url: "{{baseUrl}}/pokemons/:id"
|
||||
method: PUT
|
||||
params:
|
||||
- name: id
|
||||
value: ""
|
||||
type: path
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"name": "",
|
||||
"type": "",
|
||||
"level": ""
|
||||
}
|
||||
response:
|
||||
status: 200
|
||||
statusText: OK
|
||||
body:
|
||||
type: text
|
||||
data: ""
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokedexApi", "PokedexApi\PokedexApi.csproj", "{D4E7AC77-3516-4864-81B6-D07FA8585E0D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D4E7AC77-3516-4864-81B6-D07FA8585E0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D4E7AC77-3516-4864-81B6-D07FA8585E0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D4E7AC77-3516-4864-81B6-D07FA8585E0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D4E7AC77-3516-4864-81B6-D07FA8585E0D}.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:5090
|
||||
|
||||
GET {{PokedexApi_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -0,0 +1,102 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
var pokemons = new List<Pokemon>
|
||||
{
|
||||
new(1, "Pikachu", "Electric", 12),
|
||||
new(2, "Charmander", "Fire", 8),
|
||||
new(3, "Squirtle", "Water", 10)
|
||||
};
|
||||
|
||||
app.MapGet("/hello", () => "Привет, мир API!");
|
||||
|
||||
app.MapGet("/pokemons", () => Results.Ok(pokemons));
|
||||
|
||||
app.MapGet("/pokemons/{id}", (int id) =>
|
||||
{
|
||||
var pokemon = pokemons.FirstOrDefault(p => p.Id == id);
|
||||
return pokemon is null
|
||||
? Results.NotFound()
|
||||
: 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);
|
||||
if (existing is null)
|
||||
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);
|
||||
});
|
||||
|
||||
app.MapDelete("/pokemons/{id}", (int id) =>
|
||||
{
|
||||
var existing = pokemons.FirstOrDefault(p => p.Id == id);
|
||||
if (existing is null)
|
||||
return Results.NotFound();
|
||||
|
||||
pokemons.Remove(existing);
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
app.MapGet("/pokemons/type/{type}", (string type) =>
|
||||
{
|
||||
var filtered = pokemons
|
||||
.Where(p => p.Type.Equals(type, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
return Results.Ok(filtered);
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
static List<string> Validate(PokemonInput input)
|
||||
{
|
||||
var allowedTypes = new[]
|
||||
{
|
||||
"Fire", "Water", "Grass", "Electric",
|
||||
"Psychic", "Normal", "Flying", "Poison"
|
||||
};
|
||||
var errors = new List<string>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 2)
|
||||
errors.Add("Name должен быть не короче 2 символов");
|
||||
|
||||
if (!allowedTypes.Contains(input.Type))
|
||||
errors.Add($"Type '{input.Type}' не поддерживается");
|
||||
|
||||
if (input.Level < 1 || input.Level > 100)
|
||||
errors.Add("Level должен быть в диапазоне 1..100");
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
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:5090",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7260;http://localhost:5090",
|
||||
"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": "*"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace DefaultNamespace;
|
||||
|
||||
public class Program
|
||||
{
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
{"count":1351,"next":"https://pokeapi.co/api/v2/pokemon?offset=5&limit=5","previous":null,"results":[{"name":"bulbasaur","url":"https://pokeapi.co/api/v2/pokemon/1/"},{"name":"ivysaur","url":"https://pokeapi.co/api/v2/pokemon/2/"},{"name":"venusaur","url":"https://pokeapi.co/api/v2/pokemon/3/"},{"name":"charmander","url":"https://pokeapi.co/api/v2/pokemon/4/"},{"name":"charmeleon","url":"https://pokeapi.co/api/v2/pokemon/5/"}]}
|
||||
Reference in New Issue
Block a user