diff --git a/ImageBoardServerApp/Data/AppDBContext.cs b/ImageBoardServerApp/Data/AppDBContext.cs index 3841952..9538872 100644 --- a/ImageBoardServerApp/Data/AppDBContext.cs +++ b/ImageBoardServerApp/Data/AppDBContext.cs @@ -8,6 +8,7 @@ internal sealed class AppDBContext : DbContext public DbSet Posts { get; set; } public DbSet Images { get; set; } public DbSet Comments { get; set; } + public DbSet Reports { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlite("Data Source=./Data/Nils.db"); @@ -31,5 +32,18 @@ internal sealed class AppDBContext : DbContext mb.Entity() .HasMany(user => user.Comments) .WithOne(comment => comment.User); + + mb.Entity() + .HasOne(report => report.UserReported) + .WithMany(user => user.RecivedReports); + mb.Entity() + .HasOne(report => report.UserReporter) + .WithMany(user => user.SubmittedReports); + mb.Entity() + .HasOne(report => report.ReportedPost) + .WithOne(post => post.Report); + mb.Entity() + .HasOne(report => report.ReportedComment) + .WithOne(comment => comment.Report); } } \ No newline at end of file diff --git a/ImageBoardServerApp/Data/CommentData.cs b/ImageBoardServerApp/Data/CommentData.cs index 14a5c5d..ee51257 100644 --- a/ImageBoardServerApp/Data/CommentData.cs +++ b/ImageBoardServerApp/Data/CommentData.cs @@ -39,4 +39,6 @@ public class CommentData [Required] public long CreatedAt { get; set; } + public ReportData? Report { get; set; } + } \ No newline at end of file diff --git a/ImageBoardServerApp/Data/PostData.cs b/ImageBoardServerApp/Data/PostData.cs index 35ec225..6f54e37 100644 --- a/ImageBoardServerApp/Data/PostData.cs +++ b/ImageBoardServerApp/Data/PostData.cs @@ -40,4 +40,6 @@ public class PostData public string Board { get; set; } public List Comments { get; set; } + + public ReportData? Report { get; set; } } \ No newline at end of file diff --git a/ImageBoardServerApp/Data/Repository/ReportsRepository.cs b/ImageBoardServerApp/Data/Repository/ReportsRepository.cs new file mode 100644 index 0000000..5fc1a36 --- /dev/null +++ b/ImageBoardServerApp/Data/Repository/ReportsRepository.cs @@ -0,0 +1,45 @@ +using Microsoft.EntityFrameworkCore; + +namespace ImageBoardServerApp.Data.Repository; + +public static class ReportsRepository +{ + public static async Task> getReportsAsync() + { + await using var db = new AppDBContext(); + return await db.Reports.ToListAsync(); + } + + public static async Task getReportByIdAsync(int reportId) + { + await using var db = new AppDBContext(); + return await db.Reports.FirstOrDefaultAsync(report => report.ReportID == reportId); + } + + public static async Task createReportAsync(ReportData reportData) + { + await using var db = new AppDBContext(); + await db.Reports.AddAsync(reportData); + if (await db.SaveChangesAsync() >= 1) + { + return reportData.ReportID; + } + + return -1; + } + + public static async Task updateReportAsync(ReportData reportData) + { + await using var db = new AppDBContext(); + db.Reports.Update(reportData); + return await db.SaveChangesAsync() >= 1; + } + + public static async Task deleteReportAsync(int reportId) + { + await using var db = new AppDBContext(); + ReportData reportData = await getReportByIdAsync(reportId); + db.Remove(reportData); + return await db.SaveChangesAsync() >= 1; + } +} \ No newline at end of file diff --git a/ImageBoardServerApp/Data/UserData.cs b/ImageBoardServerApp/Data/UserData.cs index 7ed22df..b397f65 100644 --- a/ImageBoardServerApp/Data/UserData.cs +++ b/ImageBoardServerApp/Data/UserData.cs @@ -33,4 +33,8 @@ public class UserData [Required] public string Role { get; set; } + + public List SubmittedReports { get; set; } + + public List RecivedReports { get; set; } } \ No newline at end of file