添加项目文件。
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using FileService.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Configs
|
||||
{
|
||||
public class UploadFileConfig : IEntityTypeConfiguration<UploadFile>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UploadFile> builder)
|
||||
{
|
||||
builder.ToTable("upload_files");
|
||||
builder.Property(x => x.FileName)
|
||||
.HasConversion(
|
||||
a => a.Value,
|
||||
b => new Domain.ValueObjects.FileName(b)
|
||||
);
|
||||
|
||||
builder.Property(x => x.ContentType)
|
||||
.HasConversion(
|
||||
a => a.Value,
|
||||
b => new Domain.ValueObjects.ContentType(b)
|
||||
);
|
||||
|
||||
builder.ComplexProperty(x => x.CheckSum, c =>
|
||||
{
|
||||
c.Property(p => p.Value)
|
||||
.HasColumnName("checksum_value");
|
||||
|
||||
c.Property(p => p.Algorithm)
|
||||
.HasColumnName("checksum_algorithm");
|
||||
});
|
||||
|
||||
builder.ComplexProperty(x => x.StorageLocation, c =>
|
||||
{
|
||||
c.Property(p => p.StorageProvider)
|
||||
.HasColumnName("storage_provider");
|
||||
|
||||
c.Property(p => p.ObjectKey)
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
c.Property(p => p.Region)
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
c.Property(p => p.Bucket)
|
||||
.HasColumnName("storage_bucket");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using FileService.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Configs
|
||||
{
|
||||
public class UploadTaskConfig : IEntityTypeConfiguration<UploadTask>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UploadTask> builder)
|
||||
{
|
||||
builder.ToTable("upload_tasks");
|
||||
builder.Property(x => x.FileName)
|
||||
.HasConversion(
|
||||
a => a.Value,
|
||||
b => new Domain.ValueObjects.FileName(b)
|
||||
);
|
||||
|
||||
builder.Property(x => x.ContentType)
|
||||
.HasConversion(
|
||||
a => a.Value,
|
||||
b => new Domain.ValueObjects.ContentType(b)
|
||||
);
|
||||
|
||||
builder.ComplexProperty(x => x.CheckSum, c =>
|
||||
{
|
||||
c.Property(p => p.Value)
|
||||
.HasColumnName("checksum_value");
|
||||
|
||||
c.Property(p => p.Algorithm)
|
||||
.HasColumnName("checksum_algorithm");
|
||||
});
|
||||
|
||||
builder.ComplexProperty(x => x.StorageLocation, c =>
|
||||
{
|
||||
c.Property(p => p.StorageProvider)
|
||||
.HasColumnName("storage_provider");
|
||||
|
||||
c.Property(p => p.ObjectKey)
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
c.Property(p => p.Region)
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
c.Property(p => p.Bucket)
|
||||
.HasColumnName("storage_bucket");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FileService.Domain.Entities;
|
||||
using IM.Infrastructure.Efcore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FileService.Infrastructure
|
||||
{
|
||||
public class FileDbContext : BaseDbContext
|
||||
{
|
||||
public DbSet<UploadFile> Files { get; set; }
|
||||
public DbSet<UploadTask> Tasks { get; set; }
|
||||
public FileDbContext(Microsoft.EntityFrameworkCore.DbContextOptions options, global::MediatR.IMediator mediator) : base(options, mediator)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
|
||||
|
||||
modelBuilder.EnableSoftDeletionGlobalFilter();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FileService.Application\FileService.Application.csproj" />
|
||||
<ProjectReference Include="..\FileService.Domain\FileService.Domain.csproj" />
|
||||
<ProjectReference Include="..\IM.Commons\IM.Commons.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\IM.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FileService.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FileService.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(FileDbContext))]
|
||||
[Migration("20260509073447_InitFileDb")]
|
||||
partial class InitFileDb
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FileService.Domain.Entities.UploadFile", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Deletion")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FileName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<long>("FileSize")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTimeOffset?>("ModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<int>("State")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("CheckSum", "FileService.Domain.Entities.UploadFile.CheckSum#CheckSum", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Algorithm")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_algorithm");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_value");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("StorageLocation", "FileService.Domain.Entities.UploadFile.StorageLocation#StorageLocation", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Bucket")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_bucket");
|
||||
|
||||
b1.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
b1.Property<string>("Region")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
b1.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_provider");
|
||||
});
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("upload_files", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FileService.Domain.Entities.UploadTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<Guid>("ConversationId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Deletion")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FileName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<long>("FileSize")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTimeOffset?>("ModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("State")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("UploaderId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("CheckSum", "FileService.Domain.Entities.UploadTask.CheckSum#CheckSum", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Algorithm")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_algorithm");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_value");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("StorageLocation", "FileService.Domain.Entities.UploadTask.StorageLocation#StorageLocation", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Bucket")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_bucket");
|
||||
|
||||
b1.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
b1.Property<string>("Region")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
b1.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_provider");
|
||||
});
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("upload_tasks", (string)null);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FileService.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitFileDb : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "upload_files",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
OwnerId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
FileName = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
FileSize = table.Column<long>(type: "bigint", nullable: false),
|
||||
ContentType = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
State = table.Column<int>(type: "int", nullable: false),
|
||||
checksum_algorithm = table.Column<string>(type: "longtext", nullable: false),
|
||||
checksum_value = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_bucket = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_key = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_region = table.Column<string>(type: "longtext", nullable: true),
|
||||
storage_provider = table.Column<string>(type: "longtext", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
CreationTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false),
|
||||
Deletion = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true),
|
||||
ModificationTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_upload_files", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "upload_tasks",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
UploaderId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
ConversationId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
FileName = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
FileSize = table.Column<long>(type: "bigint", nullable: false),
|
||||
ContentType = table.Column<string>(type: "longtext", nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||
State = table.Column<int>(type: "int", nullable: false),
|
||||
checksum_algorithm = table.Column<string>(type: "longtext", nullable: false),
|
||||
checksum_value = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_bucket = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_key = table.Column<string>(type: "longtext", nullable: false),
|
||||
storage_region = table.Column<string>(type: "longtext", nullable: true),
|
||||
storage_provider = table.Column<string>(type: "longtext", nullable: false),
|
||||
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
CreationTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false),
|
||||
Deletion = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true),
|
||||
ModificationTime = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_upload_tasks", x => x.Id);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "upload_files");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "upload_tasks");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FileService.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FileService.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(FileDbContext))]
|
||||
partial class FileDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FileService.Domain.Entities.UploadFile", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Deletion")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FileName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<long>("FileSize")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTimeOffset?>("ModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<int>("State")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("CheckSum", "FileService.Domain.Entities.UploadFile.CheckSum#CheckSum", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Algorithm")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_algorithm");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_value");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("StorageLocation", "FileService.Domain.Entities.UploadFile.StorageLocation#StorageLocation", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Bucket")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_bucket");
|
||||
|
||||
b1.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
b1.Property<string>("Region")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
b1.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_provider");
|
||||
});
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("upload_files", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FileService.Domain.Entities.UploadTask", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<Guid>("ConversationId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Deletion")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("FileName")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<long>("FileSize")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTimeOffset?>("ModificationTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("State")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("UploaderId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("CheckSum", "FileService.Domain.Entities.UploadTask.CheckSum#CheckSum", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Algorithm")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_algorithm");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("checksum_value");
|
||||
});
|
||||
|
||||
b.ComplexProperty<Dictionary<string, object>>("StorageLocation", "FileService.Domain.Entities.UploadTask.StorageLocation#StorageLocation", b1 =>
|
||||
{
|
||||
b1.IsRequired();
|
||||
|
||||
b1.Property<string>("Bucket")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_bucket");
|
||||
|
||||
b1.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_key");
|
||||
|
||||
b1.Property<string>("Region")
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_region");
|
||||
|
||||
b1.Property<string>("StorageProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasColumnName("storage_provider");
|
||||
});
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("upload_tasks", (string)null);
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using FileService.Application.Ports;
|
||||
using FileService.Domain.IReposities;
|
||||
using FileService.Infrastructure.Reposites;
|
||||
using FileService.Infrastructure.Storage;
|
||||
using IM.Commons;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FileService.Infrastructure
|
||||
{
|
||||
public class ModuleInit : IModuleInitializer
|
||||
{
|
||||
public void Initialize(IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IUploadFileReposity, UploadFileReposity>();
|
||||
services.AddScoped<IUploadTaskReposity, UploadTaskReposity>();
|
||||
services.AddScoped<IObjectStoragePort, LocalStorageAdapter>();
|
||||
services.AddScoped<IObjectStorageRouter, ObjectStorageRouter>();
|
||||
services.AddScoped<IStorageRedisCache,StorageCacheService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using FileService.Domain.Entities;
|
||||
using FileService.Domain.IReposities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Reposites
|
||||
{
|
||||
public class UploadFileReposity : IUploadFileReposity
|
||||
{
|
||||
private readonly FileDbContext db;
|
||||
|
||||
public UploadFileReposity(FileDbContext db)
|
||||
{
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public void Create(UploadFile file)
|
||||
{
|
||||
db.Files.Add(file);
|
||||
}
|
||||
|
||||
public async Task<UploadFile?> FindByCheckSumAsync(Guid uploaderId, string value)
|
||||
{
|
||||
return await db.Files.FirstOrDefaultAsync(
|
||||
x => x.OwnerId == uploaderId &&
|
||||
x.CheckSum.Value == value
|
||||
);
|
||||
}
|
||||
|
||||
public async Task<UploadFile?> FindByIdAsync(Guid id)
|
||||
{
|
||||
return await db.Files.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FileService.Domain.Entities;
|
||||
using FileService.Domain.IReposities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Reposites
|
||||
{
|
||||
public class UploadTaskReposity : IUploadTaskReposity
|
||||
{
|
||||
private readonly FileDbContext db;
|
||||
|
||||
public UploadTaskReposity(FileDbContext db)
|
||||
{
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public void Create(UploadTask task)
|
||||
{
|
||||
db.Tasks.Add(task);
|
||||
}
|
||||
|
||||
public async Task<UploadTask?> FindByCheckSumAsync(string value)
|
||||
{
|
||||
return await db.Tasks.FirstOrDefaultAsync(x => x.CheckSum.Value == value);
|
||||
}
|
||||
|
||||
public async Task<UploadTask?> FindByIdAsync(Guid id)
|
||||
{
|
||||
return await db.Tasks.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using FileService.Application.Ports;
|
||||
using FileService.Application.StorageContracts;
|
||||
using FileService.Domain.ValueObjects;
|
||||
using IM.Commons;
|
||||
using MassTransit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Storage
|
||||
{
|
||||
public class LocalStorageAdapter : IObjectStoragePort
|
||||
{
|
||||
private readonly IRedisService redis;
|
||||
|
||||
public LocalStorageAdapter(IRedisService redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
public string ProviderCode => "Local";
|
||||
|
||||
public Task<CompleteUploadResult> CompleteUploadAsync(CompleteUploadCommand command, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<PresignedUrl> GenerateUploadUrlAsync(GenerateUploadUrlCommand command, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<InitiateUploadResult> InitUploadAsync(InitiateUploadCommand command, CancellationToken token)
|
||||
{
|
||||
var sessionId = Guid.NewGuid();
|
||||
var location = new StorageLocation();
|
||||
return new InitiateUploadResult(sessionId.ToString(),location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FileService.Application.Ports;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Storage
|
||||
{
|
||||
public class ObjectStorageRouter : IObjectStorageRouter
|
||||
{
|
||||
private IReadOnlyDictionary<string, IObjectStoragePort> adpters;
|
||||
|
||||
public ObjectStorageRouter(IEnumerable<IObjectStoragePort> storages)
|
||||
{
|
||||
this.adpters = storages.ToDictionary(x => x.ProviderCode, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public IObjectStoragePort Route(string providerCode)
|
||||
{
|
||||
return this.adpters[providerCode];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using FileService.Application.Ports;
|
||||
using FileService.Application.StorageContracts;
|
||||
using IM.Commons;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Infrastructure.Storage
|
||||
{
|
||||
public class StorageCacheService:IStorageRedisCache
|
||||
{
|
||||
private readonly IRedisService redis;
|
||||
|
||||
public StorageCacheService(IRedisService redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
public async Task SetAsync(UploadRuntimeCache upload)
|
||||
{
|
||||
string key = RedisHelper.GetUploadInfoKey(upload.UploadSessionId);
|
||||
await redis.SetAsync<UploadRuntimeCache>(key, upload);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string sessionId)
|
||||
{
|
||||
string key = RedisHelper.GetUploadInfoKey(sessionId);
|
||||
await redis.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public Task DeleteByTaskIdAsync(string taskId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<UploadRuntimeCache?> GetAsync(string sessionId)
|
||||
{
|
||||
var key = RedisHelper.GetUploadInfoKey(sessionId);
|
||||
return await redis.GetAsync<UploadRuntimeCache>(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user