Ignore:
Timestamp:
08/24/26 20:57:09 (13 days ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Parents:
a6e33d1
Message:

Added corrected entitef from the ER diagram and changes for the logic to be coresponding to the ddl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ChapterX.Infrastructure/Data/DataContext/ApplicationDbContext.cs

    ra6e33d1 re882b92  
    1919        public DbSet<Likes> Likes { get; init; }
    2020        public DbSet<Collaboration> Collaborations { get; init; }
    21         public DbSet<Notify> Notifies { get; init; }
    2221        public DbSet<AISuggestion> AISuggestions { get; init; }
    2322        public DbSet<Admin> Admins { get; init; }
     
    2625        public DbSet<HasGenre> HasGenres { get; init; }
    2726        public DbSet<NeedApproval> NeedApprovals { get; init; }
    28         public DbSet<Status> Statuses { get; init; }
    29         public DbSet<ContentType> ContentTypes { get; init; }
    30         public DbSet<SuggestionType> SuggestionTypes { get; init; }
    31         public DbSet<Roles> Roles { get; init; }
    32         public DbSet<PermissionLevel> PermissionLevels { get; init; }
    3327
    3428        public Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
     
    6054                e.HasKey(x => x.Id);
    6155                e.Property(x => x.Id).HasColumnName("user_id");
     56                e.Property(x => x.AssignedAt).HasColumnName("assigned_at");
    6257                e.HasOne(x => x.User).WithOne(u => u.Admin).HasForeignKey<Admin>(x => x.Id);
    6358            });
     
    6964                e.HasKey(x => x.Id);
    7065                e.Property(x => x.Id).HasColumnName("user_id");
     66                e.Property(x => x.JoinedAt).HasColumnName("joined_at");
    7167                e.HasOne(x => x.User).WithOne(u => u.RegularUser).HasForeignKey<RegularUser>(x => x.Id);
    7268            });
     
    7874                e.HasKey(x => x.Id);
    7975                e.Property(x => x.Id).HasColumnName("user_id");
     76                e.Property(x => x.Bio).HasColumnName("bio");
    8077                e.HasOne(x => x.User).WithOne(u => u.Writer).HasForeignKey<Writer>(x => x.Id);
    8178            });
     
    9289                e.Property(x => x.Image).HasColumnName("image");
    9390                e.Property(x => x.Content).HasColumnName("story_content");
     91                e.Property(x => x.Status).HasColumnName("status");
    9492                e.Property(x => x.UserId).HasColumnName("user_id");
    9593                e.Property(x => x.CreatedAt).HasColumnName("story_created_at");
    9694                e.Property(x => x.UpdatedAt).HasColumnName("story_updated_at");
    9795                e.HasOne(x => x.Writer).WithMany(w => w.Stories).HasForeignKey(x => x.UserId);
    98             });
    99 
    100             // STATUS
    101             modelBuilder.Entity<Status>(e =>
    102             {
    103                 e.ToTable("status");
    104                 e.HasKey(x => new { x.StoryId, x.StatusValue });
    105                 e.Ignore(x => x.Id);
    106                 e.Property(x => x.StoryId).HasColumnName("story_id");
    107                 e.Property(x => x.StatusValue).HasColumnName("status");
    108                 e.HasOne(x => x.Story).WithMany(s => s.Statuses).HasForeignKey(x => x.StoryId);
    10996            });
    11097
     
    158145                e.Property(x => x.UserId).HasColumnName("user_id");
    159146                e.Property(x => x.StoryId).HasColumnName("story_id");
    160                 e.Property(x => x.CreatedAt).HasColumnName("like_created_at");
     147                e.Property(x => x.LikedAt).HasColumnName("liked_at");
    161148                e.HasOne(x => x.User).WithMany(u => u.Likes).HasForeignKey(x => x.UserId);
    162149                e.HasOne(x => x.Story).WithMany(s => s.Likes).HasForeignKey(x => x.StoryId);
     
    213200                e.Property(x => x.Id).HasColumnName("notification_id");
    214201                e.Property(x => x.Content).HasColumnName("notification_content");
     202                e.Property(x => x.ContentType).HasColumnName("content_type");
    215203                e.Property(x => x.IsRead).HasColumnName("is_read");
     204                e.Property(x => x.Link).HasColumnName("link");
     205                e.Property(x => x.UserId).HasColumnName("user_id");
     206                e.Property(x => x.StoryId).HasColumnName("story_id");
    216207                e.Property(x => x.CreatedAt).HasColumnName("notification_created_at");
    217                 e.Property(x => x.RecipientUserId).HasColumnName("recipient_user_id");
    218                 e.Property(x => x.Type).HasColumnName("type");
    219                 e.Property(x => x.Link).HasColumnName("link");
    220             });
    221 
    222             // CONTENT_TYPE
    223             modelBuilder.Entity<ContentType>(e =>
    224             {
    225                 e.ToTable("content_type");
    226                 e.HasKey(x => new { x.NotificationId, x.ContentTypeValue });
    227                 e.Ignore(x => x.Id);
    228                 e.Property(x => x.NotificationId).HasColumnName("notification_id");
    229                 e.Property(x => x.ContentTypeValue).HasColumnName("content_type");
    230                 e.HasOne(x => x.Notification).WithMany(n => n.ContentTypes).HasForeignKey(x => x.NotificationId);
    231             });
    232 
    233             // NOTIFY
    234             modelBuilder.Entity<Notify>(e =>
    235             {
    236                 e.ToTable("notify");
    237                 e.HasKey(x => new { x.UserId, x.StoryId, x.NotificationId });
    238                 e.Ignore(x => x.Id);
    239                 e.Property(x => x.UserId).HasColumnName("user_id");
    240                 e.Property(x => x.StoryId).HasColumnName("story_id");
    241                 e.Property(x => x.NotificationId).HasColumnName("notification_id");
    242                 e.HasOne(x => x.User).WithMany(u => u.Notifies).HasForeignKey(x => x.UserId);
    243                 e.HasOne(x => x.Story).WithMany(s => s.Notifies).HasForeignKey(x => x.StoryId);
    244                 e.HasOne(x => x.Notification).WithMany(n => n.Notifies).HasForeignKey(x => x.NotificationId);
     208                e.HasOne(x => x.User).WithMany(u => u.Notifications).HasForeignKey(x => x.UserId);
     209                e.HasOne(x => x.Story).WithMany(s => s.Notifications).HasForeignKey(x => x.StoryId)
     210                    .IsRequired(false).OnDelete(DeleteBehavior.SetNull);
    245211            });
    246212
     
    253219                e.Property(x => x.OriginalText).HasColumnName("original_text");
    254220                e.Property(x => x.SuggestedText).HasColumnName("suggested_text");
     221                e.Property(x => x.SuggestionType).HasColumnName("suggestion_type");
    255222                e.Property(x => x.Accepted).HasColumnName("accepted");
    256223                e.Property(x => x.CreatedAt).HasColumnName("suggestion_created_at");
     
    258225                e.Property(x => x.StoryId).HasColumnName("story_id");
    259226                e.HasOne(x => x.Story).WithMany(s => s.AISuggestions).HasForeignKey(x => x.StoryId);
    260             });
    261 
    262             // SUGGESTION_TYPE
    263             modelBuilder.Entity<SuggestionType>(e =>
    264             {
    265                 e.ToTable("suggestion_type");
    266                 e.HasKey(x => new { x.SuggestionId, x.SuggestionTypeValue });
    267                 e.Ignore(x => x.Id);
    268                 e.Property(x => x.SuggestionId).HasColumnName("suggestion_id");
    269                 e.Property(x => x.SuggestionTypeValue).HasColumnName("suggestion_type");
    270                 e.HasOne(x => x.AISuggestion).WithMany(a => a.SuggestionTypes).HasForeignKey(x => x.SuggestionId);
    271227            });
    272228
     
    293249                e.Property(x => x.UserId).HasColumnName("user_id");
    294250                e.Property(x => x.StoryId).HasColumnName("story_id");
     251                e.Property(x => x.Role).HasColumnName("role");
     252                e.Property(x => x.PermissionLevel).HasColumnName("permission_level");
    295253                e.Property(x => x.CreatedAt).HasColumnName("collab_created_at");
    296254                e.HasOne(x => x.User).WithMany(u => u.Collaborations).HasForeignKey(x => x.UserId);
    297255                e.HasOne(x => x.Story).WithMany(s => s.Collaborations).HasForeignKey(x => x.StoryId);
    298256            });
    299 
    300             // ROLES
    301             modelBuilder.Entity<Roles>(e =>
    302             {
    303                 e.ToTable("roles");
    304                 e.HasKey(x => new { x.UserId, x.StoryId, x.RoleValue });
    305                 e.Ignore(x => x.Id);
    306                 e.Property(x => x.UserId).HasColumnName("user_id");
    307                 e.Property(x => x.StoryId).HasColumnName("story_id");
    308                 e.Property(x => x.RoleValue).HasColumnName("roles");
    309             });
    310 
    311             // PERMISSION_LEVEL
    312             modelBuilder.Entity<PermissionLevel>(e =>
    313             {
    314                 e.ToTable("permission_level");
    315                 e.HasKey(x => new { x.UserId, x.StoryId, x.Level });
    316                 e.Ignore(x => x.Id);
    317                 e.Property(x => x.UserId).HasColumnName("user_id");
    318                 e.Property(x => x.StoryId).HasColumnName("story_id");
    319                 e.Property(x => x.Level).HasColumnName("permission_level");
    320             });
    321257        }
    322258    }
Note: See TracChangeset for help on using the changeset viewer.