From a987494d29d67a60ab075c8f91f761557df2ba61 Mon Sep 17 00:00:00 2001 From: Hukuta47 Date: Fri, 17 Apr 2026 11:23:02 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=20=D0=BF=D0=BE=20=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9,=20=D0=BD=D0=B5=20=D1=81=D0=BF=D0=B5=D1=88=D0=B0,?= =?UTF-8?q?=20=D0=B0=D0=BA=D0=BA=D1=83=D1=80=D0=B0=D1=82=D0=BD=D0=BE,=20?= =?UTF-8?q?=D0=BA=D1=80=D1=87=20=D0=B6=D0=BE=D0=BF=D0=B0=20>:(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CartriX.Api/AppDbContext.cs | 15 ++++ CartriX.Api/CartriX.Api.csproj | 22 +++++ .../20260417022106_Init1.Designer.cs | 87 +++++++++++++++++++ .../Migrations/20260417022106_Init1.cs | 83 ++++++++++++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 84 ++++++++++++++++++ CartriX.Api/Models/Cartridge.cs | 9 ++ CartriX.Api/Models/Printer.cs | 10 +++ CartriX.Api/Program.cs | 14 +++ CartriX.Api/Properties/launchSettings.json | 23 +++++ CartriX.Api/appsettings.Development.json | 11 +++ CartriX.Api/appsettings.json | 9 ++ 11 files changed, 367 insertions(+) create mode 100644 CartriX.Api/AppDbContext.cs create mode 100644 CartriX.Api/CartriX.Api.csproj create mode 100644 CartriX.Api/Migrations/20260417022106_Init1.Designer.cs create mode 100644 CartriX.Api/Migrations/20260417022106_Init1.cs create mode 100644 CartriX.Api/Migrations/AppDbContextModelSnapshot.cs create mode 100644 CartriX.Api/Models/Cartridge.cs create mode 100644 CartriX.Api/Models/Printer.cs create mode 100644 CartriX.Api/Program.cs create mode 100644 CartriX.Api/Properties/launchSettings.json create mode 100644 CartriX.Api/appsettings.Development.json create mode 100644 CartriX.Api/appsettings.json diff --git a/CartriX.Api/AppDbContext.cs b/CartriX.Api/AppDbContext.cs new file mode 100644 index 0000000..cf42476 --- /dev/null +++ b/CartriX.Api/AppDbContext.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using CartriX.Api.Models; + +namespace CartriX.Api +{ + public class AppDbContext : DbContext + { + public AppDbContext(DbContextOptions options) : base(options) + { + + } + public DbSet Printers { get; set; } + public DbSet Cartridges { get; set; } + } +} \ No newline at end of file diff --git a/CartriX.Api/CartriX.Api.csproj b/CartriX.Api/CartriX.Api.csproj new file mode 100644 index 0000000..9fd2701 --- /dev/null +++ b/CartriX.Api/CartriX.Api.csproj @@ -0,0 +1,22 @@ + + + + true + net10.0 + enable + enable + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/CartriX.Api/Migrations/20260417022106_Init1.Designer.cs b/CartriX.Api/Migrations/20260417022106_Init1.Designer.cs new file mode 100644 index 0000000..4f41dfa --- /dev/null +++ b/CartriX.Api/Migrations/20260417022106_Init1.Designer.cs @@ -0,0 +1,87 @@ +// +using CartriX.Api; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CartriX.Api.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260417022106_Init1")] + partial class Init1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.6"); + + modelBuilder.Entity("CartriX.Api.Models.Cartridge", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Capacity") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Cartridges"); + }); + + modelBuilder.Entity("CartriX.Api.Models.Printer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrinterName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Printers"); + }); + + modelBuilder.Entity("CartridgePrinter", b => + { + b.Property("CartridgesHaveId") + .HasColumnType("INTEGER"); + + b.Property("CartridgesInPrinterId") + .HasColumnType("INTEGER"); + + b.HasKey("CartridgesHaveId", "CartridgesInPrinterId"); + + b.HasIndex("CartridgesInPrinterId"); + + b.ToTable("CartridgePrinter"); + }); + + modelBuilder.Entity("CartridgePrinter", b => + { + b.HasOne("CartriX.Api.Models.Cartridge", null) + .WithMany() + .HasForeignKey("CartridgesHaveId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CartriX.Api.Models.Printer", null) + .WithMany() + .HasForeignKey("CartridgesInPrinterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CartriX.Api/Migrations/20260417022106_Init1.cs b/CartriX.Api/Migrations/20260417022106_Init1.cs new file mode 100644 index 0000000..8f16403 --- /dev/null +++ b/CartriX.Api/Migrations/20260417022106_Init1.cs @@ -0,0 +1,83 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CartriX.Api.Migrations +{ + /// + public partial class Init1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Cartridges", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Capacity = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cartridges", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Printers", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PrinterName = table.Column(type: "TEXT", nullable: false), + IpAddress = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Printers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CartridgePrinter", + columns: table => new + { + CartridgesHaveId = table.Column(type: "INTEGER", nullable: false), + CartridgesInPrinterId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CartridgePrinter", x => new { x.CartridgesHaveId, x.CartridgesInPrinterId }); + table.ForeignKey( + name: "FK_CartridgePrinter_Cartridges_CartridgesHaveId", + column: x => x.CartridgesHaveId, + principalTable: "Cartridges", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CartridgePrinter_Printers_CartridgesInPrinterId", + column: x => x.CartridgesInPrinterId, + principalTable: "Printers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CartridgePrinter_CartridgesInPrinterId", + table: "CartridgePrinter", + column: "CartridgesInPrinterId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CartridgePrinter"); + + migrationBuilder.DropTable( + name: "Cartridges"); + + migrationBuilder.DropTable( + name: "Printers"); + } + } +} diff --git a/CartriX.Api/Migrations/AppDbContextModelSnapshot.cs b/CartriX.Api/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..2d88578 --- /dev/null +++ b/CartriX.Api/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,84 @@ +// +using CartriX.Api; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CartriX.Api.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.6"); + + modelBuilder.Entity("CartriX.Api.Models.Cartridge", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Capacity") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Cartridges"); + }); + + modelBuilder.Entity("CartriX.Api.Models.Printer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IpAddress") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrinterName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Printers"); + }); + + modelBuilder.Entity("CartridgePrinter", b => + { + b.Property("CartridgesHaveId") + .HasColumnType("INTEGER"); + + b.Property("CartridgesInPrinterId") + .HasColumnType("INTEGER"); + + b.HasKey("CartridgesHaveId", "CartridgesInPrinterId"); + + b.HasIndex("CartridgesInPrinterId"); + + b.ToTable("CartridgePrinter"); + }); + + modelBuilder.Entity("CartridgePrinter", b => + { + b.HasOne("CartriX.Api.Models.Cartridge", null) + .WithMany() + .HasForeignKey("CartridgesHaveId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CartriX.Api.Models.Printer", null) + .WithMany() + .HasForeignKey("CartridgesInPrinterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CartriX.Api/Models/Cartridge.cs b/CartriX.Api/Models/Cartridge.cs new file mode 100644 index 0000000..5972b60 --- /dev/null +++ b/CartriX.Api/Models/Cartridge.cs @@ -0,0 +1,9 @@ +namespace CartriX.Api.Models +{ + public class Cartridge + { + public int Id { get; set; } + public int Capacity { get; set; } + public List CartridgesInPrinter { get; set; } = default!; + } +} \ No newline at end of file diff --git a/CartriX.Api/Models/Printer.cs b/CartriX.Api/Models/Printer.cs new file mode 100644 index 0000000..9abb1ad --- /dev/null +++ b/CartriX.Api/Models/Printer.cs @@ -0,0 +1,10 @@ +namespace CartriX.Api.Models +{ + public class Printer + { + public int Id { get; set; } + public string PrinterName { get; set; } = default!; + public string IpAddress { get; set; } = default!; + public List CartridgesHave { get; set; } = default!; + } +} \ No newline at end of file diff --git a/CartriX.Api/Program.cs b/CartriX.Api/Program.cs new file mode 100644 index 0000000..ea494a4 --- /dev/null +++ b/CartriX.Api/Program.cs @@ -0,0 +1,14 @@ +using CartriX.Api; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddDbContext(options => +{ + options.UseSqlite(builder.Configuration.GetConnectionString("DevSQL")); +}); + + +var app = builder.Build(); + + +app.Run(); diff --git a/CartriX.Api/Properties/launchSettings.json b/CartriX.Api/Properties/launchSettings.json new file mode 100644 index 0000000..14f5e25 --- /dev/null +++ b/CartriX.Api/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5197", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7209;http://localhost:5197", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/CartriX.Api/appsettings.Development.json b/CartriX.Api/appsettings.Development.json new file mode 100644 index 0000000..e63a021 --- /dev/null +++ b/CartriX.Api/appsettings.Development.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings" : { + "DevSQL" : "Data Source = /home/hukuta/db.db" + } +} diff --git a/CartriX.Api/appsettings.json b/CartriX.Api/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/CartriX.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}