Import products
This commit is contained in:
Binary file not shown.
@@ -4,6 +4,10 @@
|
|||||||
<ProjectReference Include="..\Bimix.Domain\Bimix.Domain.csproj" />
|
<ProjectReference Include="..\Bimix.Domain\Bimix.Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="DTO\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|||||||
@@ -3,4 +3,7 @@ namespace Bimix.Domain.Entities;
|
|||||||
public class Product : BaseEntity
|
public class Product : BaseEntity
|
||||||
{
|
{
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
|
public string? Code { get; set; }
|
||||||
|
public string? Ean { get; set; }
|
||||||
|
public string? StockAddresses { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,6 @@ namespace Bimix.Domain.Entities;
|
|||||||
|
|
||||||
public class SyncState
|
public class SyncState
|
||||||
{
|
{
|
||||||
public required string Entity { get; set; }
|
public required string Entity { get; init; }
|
||||||
public required long LastSynced { get; set; } // UnixTimestamp
|
public required long LastSynced { get; set; } // UnixTimestamp
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,9 @@ public class BimixDbContext(DbContextOptions<BimixDbContext> options) : DbContex
|
|||||||
|
|
||||||
modelBuilder.Entity<Product>().HasKey(x => x.Id);
|
modelBuilder.Entity<Product>().HasKey(x => x.Id);
|
||||||
modelBuilder.Entity<Product>().Property(x => x.Name).IsRequired().HasMaxLength(512);
|
modelBuilder.Entity<Product>().Property(x => x.Name).IsRequired().HasMaxLength(512);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.Code).IsRequired().HasMaxLength(40);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.Ean).IsRequired().HasMaxLength(50);
|
||||||
|
modelBuilder.Entity<Product>().Property(x => x.StockAddresses).IsRequired().HasMaxLength(512);
|
||||||
|
|
||||||
modelBuilder.Entity<SyncState>().HasKey((x => x.Entity));
|
modelBuilder.Entity<SyncState>().HasKey((x => x.Entity));
|
||||||
}
|
}
|
||||||
|
|||||||
80
Bimix.Infrastructure/Migrations/20250624193445_Products-NewFields.Designer.cs
generated
Normal file
80
Bimix.Infrastructure/Migrations/20250624193445_Products-NewFields.Designer.cs
generated
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Bimix.Infrastructure.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bimix.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(BimixDbContext))]
|
||||||
|
[Migration("20250624193445_Products-NewFields")]
|
||||||
|
partial class ProductsNewFields
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.17")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bimix.Domain.Entities.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(40)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("Ean")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<string>("StockAddresses")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bimix.Domain.Entities.SyncState", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Entity")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<long>("LastSynced")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Entity");
|
||||||
|
|
||||||
|
b.ToTable("SyncStates");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bimix.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ProductsNewFields : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Code",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(40)",
|
||||||
|
maxLength: 40,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Ean",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(50)",
|
||||||
|
maxLength: 50,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "StockAddresses",
|
||||||
|
table: "Products",
|
||||||
|
type: "nvarchar(512)",
|
||||||
|
maxLength: 512,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Code",
|
||||||
|
table: "Products");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Ean",
|
||||||
|
table: "Products");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "StockAddresses",
|
||||||
|
table: "Products");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,14 +28,29 @@ namespace Bimix.Infrastructure.Migrations
|
|||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("uniqueidentifier");
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<string>("Code")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(40)
|
||||||
|
.HasColumnType("nvarchar(40)");
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedAt")
|
b.Property<DateTime>("CreatedAt")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("Ean")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("nvarchar(50)");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(512)
|
.HasMaxLength(512)
|
||||||
.HasColumnType("nvarchar(512)");
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
|
b.Property<string>("StockAddresses")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(512)
|
||||||
|
.HasColumnType("nvarchar(512)");
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedAt")
|
b.Property<DateTime>("UpdatedAt")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Bimix.Domain.Entities;
|
using Bimix.Domain.Entities;
|
||||||
using Bimix.Infrastructure.Data;
|
using Bimix.Infrastructure.Data;
|
||||||
@@ -28,6 +29,9 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
{
|
{
|
||||||
var idStr = p.GetProperty("id").GetString() ?? "";
|
var idStr = p.GetProperty("id").GetString() ?? "";
|
||||||
var name = p.GetProperty("name").GetString() ?? "";
|
var name = p.GetProperty("name").GetString() ?? "";
|
||||||
|
var code = p.GetProperty("code").GetString() ?? "";
|
||||||
|
var stockAddresses = p.GetProperty("stock_addresses").GetString() ?? "";
|
||||||
|
var ean = p.GetProperty("ean").GetString() ?? "";
|
||||||
|
|
||||||
if (!Guid.TryParse(idStr, out Guid id))
|
if (!Guid.TryParse(idStr, out Guid id))
|
||||||
{
|
{
|
||||||
@@ -43,6 +47,9 @@ public class ProductSyncService(HttpClient httpClient, BimixDbContext db, IConfi
|
|||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
|
Ean = ean,
|
||||||
|
Code = code,
|
||||||
|
StockAddresses = stockAddresses,
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
UpdatedAt = DateTime.UtcNow
|
UpdatedAt = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user