From afe3526c126e73b4bdbec391eec492514c38eea0 Mon Sep 17 00:00:00 2001 From: "jaloliddin.mahkamov@mail.ru" Date: Fri, 24 May 2024 20:16:00 +0500 Subject: [PATCH] DATA: Model & Migrate Video metadata --- .../Storages/IStorageBroker.VedioMetadata.cs | 11 ++++ .../Brokers/Storages/IStorageBroker.cs | 10 +++ .../Storages/StorageBroker.VedioMetadata.cs | 14 +++++ .../Brokers/Storages/StorageBroker.cs | 27 ++++++++ ...0024_CreateAllTablesInitialize.Designer.cs | 63 +++++++++++++++++++ ...0240524150024_CreateAllTablesInitialize.cs | 39 ++++++++++++ .../Migrations/StorageBrokerModelSnapshot.cs | 53 ++++++++++++++++ .../Models/VideoMetadatas/VideoMetadata.cs | 17 +++++ UsefulTime.Api/Program.cs | 44 ++++++++----- UsefulTime.Api/UsefulTime.Api.csproj | 12 +++- UsefulTime.Api/appsettings.Development.json | 3 + .../UsefulTime.Unit.Tests.csproj | 14 +++-- 12 files changed, 285 insertions(+), 22 deletions(-) create mode 100644 UsefulTime.Api/Brokers/Storages/IStorageBroker.VedioMetadata.cs create mode 100644 UsefulTime.Api/Brokers/Storages/IStorageBroker.cs create mode 100644 UsefulTime.Api/Brokers/Storages/StorageBroker.VedioMetadata.cs create mode 100644 UsefulTime.Api/Brokers/Storages/StorageBroker.cs create mode 100644 UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.Designer.cs create mode 100644 UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.cs create mode 100644 UsefulTime.Api/Migrations/StorageBrokerModelSnapshot.cs create mode 100644 UsefulTime.Api/Models/VideoMetadatas/VideoMetadata.cs diff --git a/UsefulTime.Api/Brokers/Storages/IStorageBroker.VedioMetadata.cs b/UsefulTime.Api/Brokers/Storages/IStorageBroker.VedioMetadata.cs new file mode 100644 index 0000000..603fdce --- /dev/null +++ b/UsefulTime.Api/Brokers/Storages/IStorageBroker.VedioMetadata.cs @@ -0,0 +1,11 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +namespace UsefulTime.Api.Brokers.Storages +{ + public partial interface IStorageBroker + { + + } +} diff --git a/UsefulTime.Api/Brokers/Storages/IStorageBroker.cs b/UsefulTime.Api/Brokers/Storages/IStorageBroker.cs new file mode 100644 index 0000000..1620bc8 --- /dev/null +++ b/UsefulTime.Api/Brokers/Storages/IStorageBroker.cs @@ -0,0 +1,10 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +namespace UsefulTime.Api.Brokers.Storages +{ + public partial interface IStorageBroker + { } + +} diff --git a/UsefulTime.Api/Brokers/Storages/StorageBroker.VedioMetadata.cs b/UsefulTime.Api/Brokers/Storages/StorageBroker.VedioMetadata.cs new file mode 100644 index 0000000..e947e6c --- /dev/null +++ b/UsefulTime.Api/Brokers/Storages/StorageBroker.VedioMetadata.cs @@ -0,0 +1,14 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +using Microsoft.EntityFrameworkCore; +using UsefulTime.Api.Models.VideoMetadatas; + +namespace UsefulTime.Api.Brokers.Storages +{ + public partial class StorageBroker + { + public DbSet VideoMetadatas { get; set; } + } +} diff --git a/UsefulTime.Api/Brokers/Storages/StorageBroker.cs b/UsefulTime.Api/Brokers/Storages/StorageBroker.cs new file mode 100644 index 0000000..8b5590d --- /dev/null +++ b/UsefulTime.Api/Brokers/Storages/StorageBroker.cs @@ -0,0 +1,27 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +using EFxceptions; +using Microsoft.EntityFrameworkCore; + +namespace UsefulTime.Api.Brokers.Storages +{ + public partial class StorageBroker:EFxceptionsContext,IStorageBroker + { + private readonly IConfiguration configuration; + + public StorageBroker(IConfiguration configuration) + { + this.configuration = configuration; + Database.Migrate(); + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + string connectionString = + this.configuration.GetConnectionString("DefaultConnection"); + + optionsBuilder.UseSqlServer(connectionString); + } + } +} diff --git a/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.Designer.cs b/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.Designer.cs new file mode 100644 index 0000000..7366403 --- /dev/null +++ b/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.Designer.cs @@ -0,0 +1,63 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UsefulTime.Api.Brokers.Storages; + +#nullable disable + +namespace UsefulTime.Api.Migrations +{ + [DbContext(typeof(StorageBroker))] + [Migration("20240524150024_CreateAllTablesInitialize")] + partial class CreateAllTablesInitialize + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UsefulTime.Api.Models.VideoMetadatas.VideoMetadata", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BlobPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Thubnail") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("VideoMetadatas"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.cs b/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.cs new file mode 100644 index 0000000..3f66f19 --- /dev/null +++ b/UsefulTime.Api/Migrations/20240524150024_CreateAllTablesInitialize.cs @@ -0,0 +1,39 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +using System; +using Microsoft.EntityFrameworkCore.Migrations; + + +namespace UsefulTime.Api.Migrations +{ + + public partial class CreateAllTablesInitialize : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "VideoMetadatas", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + BlobPath = table.Column(type: "nvarchar(max)", nullable: false), + Thubnail = table.Column(type: "nvarchar(max)", nullable: false), + CreatedDate = table.Column(type: "datetimeoffset", nullable: false), + UpdatedDate = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VideoMetadatas", x => x.Id); + }); + } + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "VideoMetadatas"); + } + } +} diff --git a/UsefulTime.Api/Migrations/StorageBrokerModelSnapshot.cs b/UsefulTime.Api/Migrations/StorageBrokerModelSnapshot.cs new file mode 100644 index 0000000..276b448 --- /dev/null +++ b/UsefulTime.Api/Migrations/StorageBrokerModelSnapshot.cs @@ -0,0 +1,53 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using UsefulTime.Api.Brokers.Storages; + +namespace UsefulTime.Api.Migrations +{ + [DbContext(typeof(StorageBroker))] + partial class StorageBrokerModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "8.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UsefulTime.Api.Models.VideoMetadatas.VideoMetadata", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("BlobPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Thubnail") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("VideoMetadatas"); + }); + } + } +} diff --git a/UsefulTime.Api/Models/VideoMetadatas/VideoMetadata.cs b/UsefulTime.Api/Models/VideoMetadatas/VideoMetadata.cs new file mode 100644 index 0000000..0ca9bab --- /dev/null +++ b/UsefulTime.Api/Models/VideoMetadatas/VideoMetadata.cs @@ -0,0 +1,17 @@ +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +namespace UsefulTime.Api.Models.VideoMetadatas +{ + public class VideoMetadata + { + public Guid Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public string BlobPath { get; set; } + public string Thubnail { get; set; } + public DateTimeOffset CreatedDate { get; set; } + public DateTimeOffset UpdatedDate { get; set; } + } +} diff --git a/UsefulTime.Api/Program.cs b/UsefulTime.Api/Program.cs index 48863a6..071b0bc 100644 --- a/UsefulTime.Api/Program.cs +++ b/UsefulTime.Api/Program.cs @@ -1,25 +1,35 @@ -var builder = WebApplication.CreateBuilder(args); +//================================================= +//Copyright (c) Coalition of Good-Hearted Engineers +//Free To Use To Find Comfort and Pease +//================================================= +using UsefulTime.Api.Brokers.Storages; -// Add services to the container. +public class Program +{ + private static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); + builder.Services.AddControllers(); -var app = builder.Build(); + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + builder.Services.AddTransient(); -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} + var app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } -app.UseHttpsRedirection(); + app.UseHttpsRedirection(); -app.UseAuthorization(); + app.UseAuthorization(); -app.MapControllers(); + app.MapControllers(); -app.Run(); + app.Run(); + } +} \ No newline at end of file diff --git a/UsefulTime.Api/UsefulTime.Api.csproj b/UsefulTime.Api/UsefulTime.Api.csproj index 39dc33b..b4f1cfd 100644 --- a/UsefulTime.Api/UsefulTime.Api.csproj +++ b/UsefulTime.Api/UsefulTime.Api.csproj @@ -7,8 +7,18 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + diff --git a/UsefulTime.Api/appsettings.Development.json b/UsefulTime.Api/appsettings.Development.json index 0c208ae..a5fd441 100644 --- a/UsefulTime.Api/appsettings.Development.json +++ b/UsefulTime.Api/appsettings.Development.json @@ -1,4 +1,7 @@ { + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=UsefulMSDBCore;Trusted_Connection=True;MultipleActiveResultSets=true" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/UsefulTime.Unit.Tests/UsefulTime.Unit.Tests.csproj b/UsefulTime.Unit.Tests/UsefulTime.Unit.Tests.csproj index c5c07e2..6df7bd8 100644 --- a/UsefulTime.Unit.Tests/UsefulTime.Unit.Tests.csproj +++ b/UsefulTime.Unit.Tests/UsefulTime.Unit.Tests.csproj @@ -10,10 +10,16 @@ - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +