Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs
Original file line number Diff line number Diff line change
@@ -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<Book> Books { get; set; }
}
}
31 changes: 31 additions & 0 deletions LibraryManagement.Api/Brokers/Storages/StorageBroker.cs
Original file line number Diff line number Diff line change
@@ -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");

Check warning on line 24 in LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.

Check warning on line 24 in LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

View workflow job for this annotation

GitHub Actions / Build

Converting null literal or possible null value to non-nullable type.

optionsBuilder.UseSqlServer(connectionString);
}

public override void Dispose() { }
}
}
10 changes: 10 additions & 0 deletions LibraryManagement.Api/LibraryManagement.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EFxceptions" Version="0.4.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.18" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RESTFulSense" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace LibraryManagement.Api.Migrations
{
/// <inheritdoc />
public partial class InitialCreateAllTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
BookId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ReaderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
BookTitle = table.Column<string>(type: "nvarchar(max)", nullable: false),
Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
Genre = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.BookId);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Books");
}
}
}
53 changes: 53 additions & 0 deletions LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// <auto-generated />
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<Guid>("BookId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");

b.Property<string>("Author")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("BookTitle")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Genre")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<Guid>("ReaderId")
.HasColumnType("uniqueidentifier");

b.HasKey("BookId");

b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}
16 changes: 16 additions & 0 deletions LibraryManagement.Api/Models/Foundations/Books/Book.cs
Original file line number Diff line number Diff line change
@@ -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; }

Check warning on line 12 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'BookTitle' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'BookTitle' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Author { get; set; }

Check warning on line 13 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Author' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Author' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Genre { get; set; }

Check warning on line 14 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Genre' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in LibraryManagement.Api/Models/Foundations/Books/Book.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Genre' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
2 changes: 2 additions & 0 deletions LibraryManagement.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -13,6 +14,7 @@
Version = "v1"
};

builder.Services.AddDbContext<StorageBroker>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

Expand Down