Skip to content

Commit 0119dbc

Browse files
Merge pull request #13 from DilmurodDeveloper/users/DilmurodDeveloper/data-reader-migrate
DATA: Model & Migrate Readers
2 parents a8dcf22 + e900663 commit 0119dbc

File tree

6 files changed

+228
-0
lines changed

6 files changed

+228
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.Readers;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace LibraryManagement.Api.Brokers.Storages
10+
{
11+
public partial class StorageBroker
12+
{
13+
public DbSet<Reader> Readers { get; set; }
14+
}
15+
}

LibraryManagement.Api/Migrations/20250719194034_AddReaderRelationToBook.Designer.cs

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace LibraryManagement.Api.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class AddReaderRelationToBook : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.CreateTable(
14+
name: "Readers",
15+
columns: table => new
16+
{
17+
ReaderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
18+
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
19+
LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
20+
DateOfBirth = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
21+
},
22+
constraints: table =>
23+
{
24+
table.PrimaryKey("PK_Readers", x => x.ReaderId);
25+
});
26+
27+
migrationBuilder.CreateIndex(
28+
name: "IX_Books_ReaderId",
29+
table: "Books",
30+
column: "ReaderId");
31+
32+
migrationBuilder.AddForeignKey(
33+
name: "FK_Books_Readers_ReaderId",
34+
table: "Books",
35+
column: "ReaderId",
36+
principalTable: "Readers",
37+
principalColumn: "ReaderId",
38+
onDelete: ReferentialAction.Cascade);
39+
}
40+
41+
/// <inheritdoc />
42+
protected override void Down(MigrationBuilder migrationBuilder)
43+
{
44+
migrationBuilder.DropForeignKey(
45+
name: "FK_Books_Readers_ReaderId",
46+
table: "Books");
47+
48+
migrationBuilder.DropTable(
49+
name: "Readers");
50+
51+
migrationBuilder.DropIndex(
52+
name: "IX_Books_ReaderId",
53+
table: "Books");
54+
}
55+
}
56+
}

LibraryManagement.Api/Migrations/StorageBrokerModelSnapshot.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,48 @@ protected override void BuildModel(ModelBuilder modelBuilder)
4545

4646
b.HasKey("BookId");
4747

48+
b.HasIndex("ReaderId");
49+
4850
b.ToTable("Books");
4951
});
52+
53+
modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Readers.Reader", b =>
54+
{
55+
b.Property<Guid>("ReaderId")
56+
.ValueGeneratedOnAdd()
57+
.HasColumnType("uniqueidentifier");
58+
59+
b.Property<DateTimeOffset>("DateOfBirth")
60+
.HasColumnType("datetimeoffset");
61+
62+
b.Property<string>("FirstName")
63+
.IsRequired()
64+
.HasColumnType("nvarchar(max)");
65+
66+
b.Property<string>("LastName")
67+
.IsRequired()
68+
.HasColumnType("nvarchar(max)");
69+
70+
b.HasKey("ReaderId");
71+
72+
b.ToTable("Readers");
73+
});
74+
75+
modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Books.Book", b =>
76+
{
77+
b.HasOne("LibraryManagement.Api.Models.Foundations.Readers.Reader", "Reader")
78+
.WithMany("Books")
79+
.HasForeignKey("ReaderId")
80+
.OnDelete(DeleteBehavior.Cascade)
81+
.IsRequired();
82+
83+
b.Navigation("Reader");
84+
});
85+
86+
modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Readers.Reader", b =>
87+
{
88+
b.Navigation("Books");
89+
});
5090
#pragma warning restore 612, 618
5191
}
5292
}

LibraryManagement.Api/Models/Foundations/Books/Book.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Free To Use To Build Reliable Library Management Solutions
44
//-----------------------------------------------------------
55

6+
using LibraryManagement.Api.Models.Foundations.Readers;
7+
68
namespace LibraryManagement.Api.Models.Foundations.Books
79
{
810
public class Book
@@ -12,5 +14,6 @@ public class Book
1214
public string BookTitle { get; set; }
1315
public string Author { get; set; }
1416
public string Genre { get; set; }
17+
public Reader Reader { get; set; }
1518
}
1619
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.Books;
7+
8+
namespace LibraryManagement.Api.Models.Foundations.Readers
9+
{
10+
public class Reader
11+
{
12+
public Guid ReaderId { get; set; }
13+
public string FirstName { get; set; }
14+
public string LastName { get; set; }
15+
public DateTimeOffset DateOfBirth { get; set; }
16+
public List<Book> Books { get; set; }
17+
}
18+
}

0 commit comments

Comments
 (0)