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.Reader.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.Readers;
using Microsoft.EntityFrameworkCore;

namespace LibraryManagement.Api.Brokers.Storages
{
public partial class StorageBroker
{
public DbSet<Reader> Readers { get; set; }
}
}

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,56 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace LibraryManagement.Api.Migrations
{
/// <inheritdoc />
public partial class AddReaderRelationToBook : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Readers",
columns: table => new
{
ReaderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateOfBirth = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Readers", x => x.ReaderId);
});

migrationBuilder.CreateIndex(
name: "IX_Books_ReaderId",
table: "Books",
column: "ReaderId");

migrationBuilder.AddForeignKey(
name: "FK_Books_Readers_ReaderId",
table: "Books",
column: "ReaderId",
principalTable: "Readers",
principalColumn: "ReaderId",
onDelete: ReferentialAction.Cascade);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Books_Readers_ReaderId",
table: "Books");

migrationBuilder.DropTable(
name: "Readers");

migrationBuilder.DropIndex(
name: "IX_Books_ReaderId",
table: "Books");
}
}
}
40 changes: 40 additions & 0 deletions LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,48 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("BookId");

b.HasIndex("ReaderId");

b.ToTable("Books");
});

modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Readers.Reader", b =>
{
b.Property<Guid>("ReaderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");

b.Property<DateTimeOffset>("DateOfBirth")
.HasColumnType("datetimeoffset");

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

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

b.HasKey("ReaderId");

b.ToTable("Readers");
});

modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Books.Book", b =>
{
b.HasOne("LibraryManagement.Api.Models.Foundations.Readers.Reader", "Reader")
.WithMany("Books")
.HasForeignKey("ReaderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Reader");
});

modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Readers.Reader", b =>
{
b.Navigation("Books");
});
#pragma warning restore 612, 618
}
}
Expand Down
3 changes: 3 additions & 0 deletions LibraryManagement.Api/Models/Foundations/Books/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
// Free To Use To Build Reliable Library Management Solutions
//-----------------------------------------------------------

using LibraryManagement.Api.Models.Foundations.Readers;

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 14 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 15 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 16 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.
public Reader Reader { get; set; }

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

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'Reader' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
18 changes: 18 additions & 0 deletions LibraryManagement.Api/Models/Foundations/Readers/Reader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//-----------------------------------------------------------
// Copyright (c) Coalition of Good-Hearted Engineers
// Free To Use To Build Reliable Library Management Solutions
//-----------------------------------------------------------

using LibraryManagement.Api.Models.Foundations.Books;

namespace LibraryManagement.Api.Models.Foundations.Readers
{
public class Reader
{
public Guid ReaderId { get; set; }
public string FirstName { get; set; }

Check warning on line 13 in LibraryManagement.Api/Models/Foundations/Readers/Reader.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'FirstName' 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/Readers/Reader.cs

View workflow job for this annotation

GitHub Actions / Build

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

Check warning on line 14 in LibraryManagement.Api/Models/Foundations/Readers/Reader.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'LastName' 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/Readers/Reader.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable property 'LastName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public DateTimeOffset DateOfBirth { get; set; }
public List<Book> Books { get; set; }

Check warning on line 16 in LibraryManagement.Api/Models/Foundations/Readers/Reader.cs

View workflow job for this annotation

GitHub Actions / Build

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