This commit is contained in:
Puzanova
2026-10-19 15:57:59 +03:00
parent 12fc104a6a
commit 3c1448c8a7
13 changed files with 427 additions and 43 deletions
@@ -1,15 +0,0 @@
namespace PokedexApi.Models;
public record Pokemon(int Id, string Name, string Type, int Level);
// TODO 1: объяви record Pokemon
// Поля: Id (int), Name (string), Type (string), Level (int)
public record PokemonInput( string Name, string Type, int Level);
// TODO 2: объяви record PokemonInput
// Поля: Name (string), Type (string), Level (int)
public record LevelUpdate( int Level);
// TODO 3: объяви record LevelUpdate
// Поле: Level (int)
@@ -0,0 +1,5 @@
namespace PokedexApi.Models;
public record Pokemon(int Id, string Name, string Type, int Level);
public record PokemonInput( string Name, string Type, int Level);
public record LevelUpdate( int Level);
@@ -12,7 +12,6 @@
<ItemGroup>
<Folder Include="Endpoints\" />
<Folder Include="Validation\" />
</ItemGroup>
</Project>
@@ -11,19 +11,34 @@ public class PokemonStorage
new Pokemon(3, "Squirtle", "Water", 10)
};
// TODO 1: объяви приватный список _pokemons
// с тремя стартовыми покемонами:
// (1, "Pikachu", "Electric", 12)
// (2, "Charmander", "Fire", 8)
// (3, "Squirtle", "Water", 10)
private readonly object _lock = new object();
// TODO 2: объяви приватное поле _lock типа object
public void DoSomething()
{
lock (_lock)
{
// этот блок выполняет только один поток за раз
// остальные ждут, пока он выйдет
}
}
new Pokemon(1, "Pikachu", ...)
private readonly object _lock = new object();
// TODO 3: реализуй метод GetAll()
// TODO 4: реализуй метод GetById(int id)
// TODO 5: реализуй метод Filter(string? type, int? minLevel)
if (type != null && p.Type != type) continue;
if (minLevel != null && p.Level < minLevel) continue;
result.Add(p);
// TODO 6: реализуй метод SearchByName(string query)
// TODO 7: реализуй метод Add(PokemonInput input)
int newId = 1;
foreach (var p in _pokemons)
{
if (p.Id >= newId) newId = p.Id + 1;
}
new Pokemon(newId, input.Name, input.Type, input.Level)
// TODO 8: реализуй метод Update(int id, PokemonInput input)
// TODO 9: реализуй метод UpdateLevel(int id, int level)
// TODO 10: реализуй метод Delete(int id)
@@ -0,0 +1,6 @@
namespace PokedexApi2.Validation;
public interface PokemonStorage
{
}