This commit is contained in:
gcn
2026-11-25 16:05:26 +03:00
parent 0b29942a2e
commit 6eb9e3089b
2 changed files with 12 additions and 4 deletions
Binary file not shown.
+12 -4
View File
@@ -73,12 +73,20 @@ app.MapDelete("/pokemons/{id}", (int id) =>
app.Run();
List<string> Validate(PokemonInput input)
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)) errors.Add("Имя не может быть пустым.");
if (string.IsNullOrWhiteSpace(input.Type)) errors.Add("Тип не может быть пустым.");
if (input.Level <= 0) errors.Add("Уровень должен быть больше 0.");
if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Trim().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;
}