From c01b6e8c77b0961b1b68ddf3e51f20d5ffe43a9d Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 14 May 2023 19:54:40 +0300 Subject: [PATCH] Fix database schema --- Entities/Board.cs | 2 +- Entities/Card.cs | 5 ++-- Entities/Column.cs | 12 ++++++++++ Entities/User.cs | 1 + EntityConfiguration/CardConfiguration.cs | 11 +++++---- EntityConfiguration/ColumnConfiguration.cs | 27 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 Entities/Column.cs create mode 100644 EntityConfiguration/ColumnConfiguration.cs diff --git a/Entities/Board.cs b/Entities/Board.cs index 0759e01..a15675c 100644 --- a/Entities/Board.cs +++ b/Entities/Board.cs @@ -6,6 +6,6 @@ public virtual ICollection? Users { get; set; } = new HashSet(); - public virtual ICollection? Cards { get; set; } = new HashSet(); + public virtual ICollection? Columns { get; set; } = new HashSet(); } } diff --git a/Entities/Card.cs b/Entities/Card.cs index 590271d..c2422d5 100644 --- a/Entities/Card.cs +++ b/Entities/Card.cs @@ -4,12 +4,11 @@ { public string Name { get; set; } public string Description { get; set; } - public string Column { get; set; } public int SenderId { get; set; } - public int BoardId { get; set; } + public int ColumnId { get; set; } public virtual User Sender { get; set; } - public virtual Board Board { get; set; } + public virtual Column Column { get; set; } public virtual ICollection Comments { get; set; } = new HashSet(); } diff --git a/Entities/Column.cs b/Entities/Column.cs new file mode 100644 index 0000000..dfb40d8 --- /dev/null +++ b/Entities/Column.cs @@ -0,0 +1,12 @@ +namespace NG_2023_Kanban.Entities +{ + public class Column : BaseEntity + { + public string Name { get; set; } + public int BoardId { get; set; } + + public virtual Board Board { get; set; } + + public virtual ICollection? Cards { get; set; } = new HashSet(); + } +} diff --git a/Entities/User.cs b/Entities/User.cs index e504980..02aea97 100644 --- a/Entities/User.cs +++ b/Entities/User.cs @@ -10,6 +10,7 @@ public bool IsAdmin { get; set; } public virtual ICollection? Boards { get; set; } = new HashSet(); + public virtual ICollection? Cards { get; set; } = new HashSet(); public virtual ICollection? Comments { get; set; } = new HashSet(); } } diff --git a/EntityConfiguration/CardConfiguration.cs b/EntityConfiguration/CardConfiguration.cs index 4594909..c89a0b4 100644 --- a/EntityConfiguration/CardConfiguration.cs +++ b/EntityConfiguration/CardConfiguration.cs @@ -17,13 +17,16 @@ namespace NG_2023_Kanban.EntityConfiguration builder.Property(x => x.Description).IsRequired(); builder.Property(x => x.Description).HasMaxLength(100); - builder.Property(x => x.Column).IsRequired(); - builder.Property(x => x.Column).HasMaxLength(100); + builder + .HasOne(x => x.Sender) + .WithMany(x => x.Cards) + .HasForeignKey(x => x.SenderId) + .HasPrincipalKey(x => x.Id); builder - .HasOne(x => x.Board) + .HasOne(x => x.Column) .WithMany(x => x.Cards) - .HasForeignKey(x => x.BoardId) + .HasForeignKey(x => x.ColumnId) .HasPrincipalKey(x => x.Id); } } diff --git a/EntityConfiguration/ColumnConfiguration.cs b/EntityConfiguration/ColumnConfiguration.cs new file mode 100644 index 0000000..9f7175b --- /dev/null +++ b/EntityConfiguration/ColumnConfiguration.cs @@ -0,0 +1,27 @@ +using NG_2023_Kanban.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace NG_2023_Kanban.EntityConfiguration +{ + public class ColumnConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasIndex(x => x.Id); + builder.Property(x => x.Id).IsRequired(); + + builder.Property(x => x.Name).IsRequired(); + builder.Property(x => x.Name).HasMaxLength(100); + + builder.Property(x => x.Board).IsRequired(); + builder.Property(x => x.Board).HasMaxLength(100); + + builder + .HasOne(x => x.Board) + .WithMany(x => x.Columns) + .HasForeignKey(x => x.BoardId) + .HasPrincipalKey(x => x.Id); + } + } +}