2023-01-18 12:56:24 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
namespace ImageBoardServerApp.Data;
|
|
|
|
|
|
|
|
internal sealed class AppDBContext : DbContext
|
|
|
|
{
|
|
|
|
public DbSet<UserData> Users { get; set; }
|
|
|
|
public DbSet<PostData> Posts { get; set; }
|
|
|
|
public DbSet<ImageData> Images { get; set; }
|
|
|
|
public DbSet<CommentData> Comments { get; set; }
|
2023-02-11 14:47:39 +00:00
|
|
|
public DbSet<ReportData> Reports { get; set; }
|
2023-03-01 13:44:06 +00:00
|
|
|
public DbSet<BoardData> Boards { get; set; }
|
2023-01-18 12:56:24 +00:00
|
|
|
|
2023-02-12 20:38:00 +00:00
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
{
|
|
|
|
optionsBuilder.UseSqlite("Data Source=./Data/Nils.db");
|
|
|
|
}
|
2023-01-18 12:56:24 +00:00
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder mb)
|
|
|
|
{
|
|
|
|
mb.Entity<PostData>()
|
|
|
|
.HasMany(post => post.Comments)
|
|
|
|
.WithOne(comment => comment.Post);
|
|
|
|
mb.Entity<PostData>()
|
|
|
|
.HasOne(post => post.Image)
|
|
|
|
.WithOne(image => image.Post);
|
|
|
|
|
|
|
|
mb.Entity<CommentData>()
|
|
|
|
.HasOne(comment => comment.Image)
|
|
|
|
.WithOne(image => image.Comment);
|
|
|
|
|
|
|
|
mb.Entity<UserData>()
|
|
|
|
.HasMany(user => user.Posts)
|
|
|
|
.WithOne(post => post.User);
|
|
|
|
mb.Entity<UserData>()
|
|
|
|
.HasMany(user => user.Comments)
|
|
|
|
.WithOne(comment => comment.User);
|
2023-02-11 14:47:39 +00:00
|
|
|
|
|
|
|
mb.Entity<ReportData>()
|
|
|
|
.HasOne(report => report.UserReported)
|
|
|
|
.WithMany(user => user.RecivedReports);
|
|
|
|
mb.Entity<ReportData>()
|
|
|
|
.HasOne(report => report.UserReporter)
|
|
|
|
.WithMany(user => user.SubmittedReports);
|
|
|
|
mb.Entity<ReportData>()
|
|
|
|
.HasOne(report => report.ReportedPost)
|
|
|
|
.WithOne(post => post.Report);
|
|
|
|
mb.Entity<ReportData>()
|
|
|
|
.HasOne(report => report.ReportedComment)
|
|
|
|
.WithOne(comment => comment.Report);
|
2023-01-18 12:56:24 +00:00
|
|
|
}
|
|
|
|
}
|