From e6a2231e89fc44de02d18bc9dcf28a2621108a43 Mon Sep 17 00:00:00 2001 From: 328p <328p@BTK.MAIN> Date: Thu, 17 Sep 2026 15:54:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- works/lab-01/pokedex_api | 1 - works/lab-01/pokedex_api/PokedexApi.sln | 16 ++++ .../PokedexApi/Data/Models/Ability.cs | 22 ++++++ .../PokedexApi/Data/Models/Pokemon.cs | 24 ++++++ .../PokedexApi/Data/Models/PokemonAbility.cs | 21 +++++ .../PokedexApi/Data/Models/PokemonType.cs | 16 ++++ .../PokedexApi/Data/PokemonContext.cs | 17 ++++ .../20260911140633_Init.Designer.cs | 51 ++++++++++++ .../Migrations/20260911140633_Init.cs | 41 ++++++++++ .../20260911142245_PokemonTable.Designer.cs | 79 +++++++++++++++++++ .../Migrations/20260911142245_PokemonTable.cs | 41 ++++++++++ .../Migrations/PokemonContextModelSnapshot.cs | 76 ++++++++++++++++++ .../pokedex_api/PokedexApi/PokedexApi.csproj | 19 +++++ .../lab-01/pokedex_api/PokedexApi/Program.cs | 7 ++ works/lab-01/pokedex_api/gitignore | 55 +++++++++++++ 15 files changed, 485 insertions(+), 1 deletion(-) delete mode 160000 works/lab-01/pokedex_api create mode 100644 works/lab-01/pokedex_api/PokedexApi.sln create mode 100644 works/lab-01/pokedex_api/PokedexApi/Data/Models/Ability.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Data/Models/Pokemon.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonAbility.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonType.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Data/PokemonContext.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.Designer.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.Designer.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/Migrations/PokemonContextModelSnapshot.cs create mode 100644 works/lab-01/pokedex_api/PokedexApi/PokedexApi.csproj create mode 100644 works/lab-01/pokedex_api/PokedexApi/Program.cs create mode 100644 works/lab-01/pokedex_api/gitignore diff --git a/works/lab-01/pokedex_api b/works/lab-01/pokedex_api deleted file mode 160000 index 4750d69..0000000 --- a/works/lab-01/pokedex_api +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4750d69416fc5358039419f84dd4c5af5b3adddc diff --git a/works/lab-01/pokedex_api/PokedexApi.sln b/works/lab-01/pokedex_api/PokedexApi.sln new file mode 100644 index 0000000..01ad780 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokedexApi", "PokedexApi\PokedexApi.csproj", "{A1E50924-2398-46E6-9A31-D88C139614E6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A1E50924-2398-46E6-9A31-D88C139614E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1E50924-2398-46E6-9A31-D88C139614E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1E50924-2398-46E6-9A31-D88C139614E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1E50924-2398-46E6-9A31-D88C139614E6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/works/lab-01/pokedex_api/PokedexApi/Data/Models/Ability.cs b/works/lab-01/pokedex_api/PokedexApi/Data/Models/Ability.cs new file mode 100644 index 0000000..a209097 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Data/Models/Ability.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace PokedexApi.Data.Models; +[Table("ability")] +[Index(nameof(Name), IsUnique = true)] +public class Ability +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ability_id")] + public int AbilityId { get; set; } + [Column("ability_name")] + [Required] + [MaxLength(100)] + public string Name { get; set; } + [Column("ability_description")] + [Required] + public string Description { get; set; } + +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Data/Models/Pokemon.cs b/works/lab-01/pokedex_api/PokedexApi/Data/Models/Pokemon.cs new file mode 100644 index 0000000..19b0b61 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Data/Models/Pokemon.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace PokedexApi.Data.Models; +[Table("pokemon")] +[Index(nameof(Name), IsUnique = true)] +public class Pokemon +{ + [Key] + [Column("pokemon_id")] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int Id { get; set; } + [Column("pokemon_name")] + [Required] + [MaxLength(30)] + public string Name { get; set; } + [Column("pokemon_height_m")] + [Required] + public double Height { get; set; } + [Column("pokemon_weight_kg")] + [Required] + public double Weight { get; set; } +} \ No newline at end of file diff --git a/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonAbility.cs b/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonAbility.cs new file mode 100644 index 0000000..bb0b972 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonAbility.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace PokedexApi.Data.Models; +[Table("pokemonAbility")] +[Index(nameof(Name), IsUnique = true)] +public class PokemonAbility +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("pokemon_ability_id")] + public int AbilityId { get; set; } + [Column("pokemon_ability_name")] + [Required] + public string Name { get; set; } + [Column("IsHidden")] + [Required] + public bool IsHidden { get; set; } + +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonType.cs b/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonType.cs new file mode 100644 index 0000000..4ad228d --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Data/Models/PokemonType.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace PokedexApi.Data.Models; +[Table("type")] +[Index(nameof(Name), IsUnique = true)] +public class Type +{ + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("type_id")] + public int TypeId { get; set; } + [Column("type_name")] + public string Name { get; set; } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Data/PokemonContext.cs b/works/lab-01/pokedex_api/PokedexApi/Data/PokemonContext.cs new file mode 100644 index 0000000..2fc2f23 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Data/PokemonContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using PokedexApi.Data.Models; +using Type = PokedexApi.Data.Models.Type; + +namespace PokedexApi.Data; + +public class PokemonContext: DbContext +{ + public DbSet Types { get; set; } + public DbSet Pokemons { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.UseNpgsql("Username=postgres;Password=123;Host=localhost:5432;Database=postgres"); + } +} \ No newline at end of file diff --git a/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.Designer.cs b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.Designer.cs new file mode 100644 index 0000000..330fa9a --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.Designer.cs @@ -0,0 +1,51 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PokedexApi.Data; + +#nullable disable + +namespace PokedexApi.Migrations +{ + [DbContext(typeof(PokemonContext))] + [Migration("20260911140633_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PokedexApi.Data.Models.Type", b => + { + b.Property("TypeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("type_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TypeId")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("type_name"); + + b.HasKey("TypeId"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.cs b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.cs new file mode 100644 index 0000000..2938852 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911140633_Init.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace PokedexApi.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "type", + columns: table => new + { + type_id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + type_name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_type", x => x.type_id); + }); + + migrationBuilder.CreateIndex( + name: "IX_type_type_name", + table: "type", + column: "type_name", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "type"); + } + } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.Designer.cs b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.Designer.cs new file mode 100644 index 0000000..cdaa1c3 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.Designer.cs @@ -0,0 +1,79 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PokedexApi.Data; + +#nullable disable + +namespace PokedexApi.Migrations +{ + [DbContext(typeof(PokemonContext))] + [Migration("20260911142245_PokemonTable")] + partial class PokemonTable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PokedexApi.Data.Models.Pokemon", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("pokemon_id"); + + b.Property("Height") + .HasColumnType("double precision") + .HasColumnName("pokemon_height_m"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)") + .HasColumnName("pokemon_name"); + + b.Property("Weight") + .HasColumnType("double precision") + .HasColumnName("pokemon_weight_kg"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("pokemon"); + }); + + modelBuilder.Entity("PokedexApi.Data.Models.Type", b => + { + b.Property("TypeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("type_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TypeId")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("type_name"); + + b.HasKey("TypeId"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.cs b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.cs new file mode 100644 index 0000000..f9c122b --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Migrations/20260911142245_PokemonTable.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PokedexApi.Migrations +{ + /// + public partial class PokemonTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "pokemon", + columns: table => new + { + pokemon_id = table.Column(type: "integer", nullable: false), + pokemon_name = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), + pokemon_height_m = table.Column(type: "double precision", nullable: false), + pokemon_weight_kg = table.Column(type: "double precision", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_pokemon", x => x.pokemon_id); + }); + + migrationBuilder.CreateIndex( + name: "IX_pokemon_pokemon_name", + table: "pokemon", + column: "pokemon_name", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "pokemon"); + } + } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/Migrations/PokemonContextModelSnapshot.cs b/works/lab-01/pokedex_api/PokedexApi/Migrations/PokemonContextModelSnapshot.cs new file mode 100644 index 0000000..d0fcbae --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Migrations/PokemonContextModelSnapshot.cs @@ -0,0 +1,76 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PokedexApi.Data; + +#nullable disable + +namespace PokedexApi.Migrations +{ + [DbContext(typeof(PokemonContext))] + partial class PokemonContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PokedexApi.Data.Models.Pokemon", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("pokemon_id"); + + b.Property("Height") + .HasColumnType("double precision") + .HasColumnName("pokemon_height_m"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)") + .HasColumnName("pokemon_name"); + + b.Property("Weight") + .HasColumnType("double precision") + .HasColumnName("pokemon_weight_kg"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("pokemon"); + }); + + modelBuilder.Entity("PokedexApi.Data.Models.Type", b => + { + b.Property("TypeId") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("type_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TypeId")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("type_name"); + + b.HasKey("TypeId"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/works/lab-01/pokedex_api/PokedexApi/PokedexApi.csproj b/works/lab-01/pokedex_api/PokedexApi/PokedexApi.csproj new file mode 100644 index 0000000..c2186ce --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/PokedexApi.csproj @@ -0,0 +1,19 @@ + + + + Exe + net10.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/works/lab-01/pokedex_api/PokedexApi/Program.cs b/works/lab-01/pokedex_api/PokedexApi/Program.cs new file mode 100644 index 0000000..5e28648 --- /dev/null +++ b/works/lab-01/pokedex_api/PokedexApi/Program.cs @@ -0,0 +1,7 @@ +using PokedexApi.Data; + +PokemonContext pk = new PokemonContext(); +Console.WriteLine( + string.Join(", ", + pk.Pokemons.Select(pk => pk.Name) + )); \ No newline at end of file diff --git a/works/lab-01/pokedex_api/gitignore b/works/lab-01/pokedex_api/gitignore new file mode 100644 index 0000000..12cba71 --- /dev/null +++ b/works/lab-01/pokedex_api/gitignore @@ -0,0 +1,55 @@ +# ========================================== +# IDE & Editors (JetBrains: Rider, IDEA, Android Studio) +# ========================================== +.idea/ +*.iml +*.iws +*.ipr +.vscode/ +*.suo +*.user +*.userosscache +*.sln.docstates + +# ========================================== +# Database Tools (DBeaver) +# ========================================== +.dbeaver/ +.eclipse/ +*.dbeaver-data/ + +# ========================================== +# C# / .NET / Visual Studio / Rider builds +# ========================================== +bin/ +obj/ +out/ +[D-d]ebug/ +[R-r]elease/ +*.userprefs +*.pidb +*.versioncontrol +*.csproj.user + +# ========================================== +# Android Studio / Gradle / Kotlin +# ========================================== +.gradle/ +build/ +local.properties +.navigation/ +captures/ +.externalNativeBuild +.cxx/ +*.apk +*.aab +*.keystore +*.jks + +# ========================================== +# OS Generated Files & Logs +# ========================================== +.DS_Store +Thumbs.db +*.log +*.tmp