diff --git a/LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs b/LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs new file mode 100644 index 0000000..ca31164 --- /dev/null +++ b/LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs @@ -0,0 +1,15 @@ +//----------------------------------------------------------- +// Copyright (c) Coalition of Good-Hearted Engineers +// Free To Use To Build Reliable Library Management Solutions +//----------------------------------------------------------- + +using LibraryManagement.Api.Models.Foundations.Books; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Api.Brokers.Storages +{ + public partial class StorageBroker + { + public DbSet Books { get; set; } + } +} diff --git a/LibraryManagement.Api/Brokers/Storages/StorageBroker.cs b/LibraryManagement.Api/Brokers/Storages/StorageBroker.cs new file mode 100644 index 0000000..e8eaaaa --- /dev/null +++ b/LibraryManagement.Api/Brokers/Storages/StorageBroker.cs @@ -0,0 +1,31 @@ +//----------------------------------------------------------- +// Copyright (c) Coalition of Good-Hearted Engineers +// Free To Use To Build Reliable Library Management Solutions +//----------------------------------------------------------- + +using EFxceptions; +using Microsoft.EntityFrameworkCore; + +namespace LibraryManagement.Api.Brokers.Storages +{ + public partial class StorageBroker : EFxceptionsContext + { + private readonly IConfiguration configuration; + + public StorageBroker(IConfiguration configuration) + { + this.configuration = configuration; + this.Database.Migrate(); + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + string connectionString = + this.configuration.GetConnectionString(name: "DefaultConnection"); + + optionsBuilder.UseSqlServer(connectionString); + } + + public override void Dispose() { } + } +} diff --git a/LibraryManagement.Api/LibraryManagement.Api.csproj b/LibraryManagement.Api/LibraryManagement.Api.csproj index c3240a8..fcfae9d 100644 --- a/LibraryManagement.Api/LibraryManagement.Api.csproj +++ b/LibraryManagement.Api/LibraryManagement.Api.csproj @@ -7,6 +7,16 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.Designer.cs b/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.Designer.cs new file mode 100644 index 0000000..5057562 --- /dev/null +++ b/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.Designer.cs @@ -0,0 +1,56 @@ +// +using System; +using LibraryManagement.Api.Brokers.Storages; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryManagement.Api.Migrations +{ + [DbContext(typeof(StorageBroker))] + [Migration("20250719192841_InitialCreateAllTables")] + partial class InitialCreateAllTables + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Books.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("BookTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReaderId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.cs b/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.cs new file mode 100644 index 0000000..287e6ba --- /dev/null +++ b/LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LibraryManagement.Api.Migrations +{ + /// + public partial class InitialCreateAllTables : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + BookId = table.Column(type: "uniqueidentifier", nullable: false), + ReaderId = table.Column(type: "uniqueidentifier", nullable: false), + BookTitle = table.Column(type: "nvarchar(max)", nullable: false), + Author = table.Column(type: "nvarchar(max)", nullable: false), + Genre = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.BookId); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + } + } +} diff --git a/LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs b/LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs new file mode 100644 index 0000000..5441c5c --- /dev/null +++ b/LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs @@ -0,0 +1,53 @@ +// +using System; +using LibraryManagement.Api.Brokers.Storages; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LibraryManagement.Api.Migrations +{ + [DbContext(typeof(StorageBroker))] + partial class StorageBrokerModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Books.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("BookTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Genre") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReaderId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LibraryManagement.Api/Models/Foundations/Books/Book.cs b/LibraryManagement.Api/Models/Foundations/Books/Book.cs new file mode 100644 index 0000000..a040264 --- /dev/null +++ b/LibraryManagement.Api/Models/Foundations/Books/Book.cs @@ -0,0 +1,16 @@ +//----------------------------------------------------------- +// Copyright (c) Coalition of Good-Hearted Engineers +// Free To Use To Build Reliable Library Management Solutions +//----------------------------------------------------------- + +namespace LibraryManagement.Api.Models.Foundations.Books +{ + public class Book + { + public Guid BookId { get; set; } + public Guid ReaderId { get; set; } + public string BookTitle { get; set; } + public string Author { get; set; } + public string Genre { get; set; } + } +} diff --git a/LibraryManagement.Api/Program.cs b/LibraryManagement.Api/Program.cs index e1faa7a..742dff7 100644 --- a/LibraryManagement.Api/Program.cs +++ b/LibraryManagement.Api/Program.cs @@ -3,6 +3,7 @@ // Free To Use To Build Reliable Library Management Solutions //----------------------------------------------------------- +using LibraryManagement.Api.Brokers.Storages; using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); @@ -13,6 +14,7 @@ Version = "v1" }; +builder.Services.AddDbContext(); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer();