diff --git a/API/lab-01/API.zip b/API/lab-01/API.zip new file mode 100644 index 0000000..f5f6316 Binary files /dev/null and b/API/lab-01/API.zip differ diff --git a/API/lab-01/PokedexApi/PokedexApi/Program.cs b/API/lab-01/PokedexApi/PokedexApi/Program.cs index 3adf7f0..9d99d02 100644 --- a/API/lab-01/PokedexApi/PokedexApi/Program.cs +++ b/API/lab-01/PokedexApi/PokedexApi/Program.cs @@ -73,12 +73,20 @@ app.MapDelete("/pokemons/{id}", (int id) => app.Run(); -List Validate(PokemonInput input) +static List Validate(PokemonInput input) { + var allowedTypes = new[] { "Fire", "Water", "Grass", "Electric", "Psychic", "Normal", "Flying", "Poison" }; var errors = new List(); - 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; }