diff --git a/ImageBoardServerApp/Data/AppDBContext.cs b/ImageBoardServerApp/Data/AppDBContext.cs index 767d846..79b3689 100644 --- a/ImageBoardServerApp/Data/AppDBContext.cs +++ b/ImageBoardServerApp/Data/AppDBContext.cs @@ -9,6 +9,7 @@ internal sealed class AppDBContext : DbContext public DbSet Images { get; set; } public DbSet Comments { get; set; } public DbSet Reports { get; set; } + public DbSet Boards { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/ImageBoardServerApp/Data/BoardData.cs b/ImageBoardServerApp/Data/BoardData.cs index a2d75a2..0bf750d 100644 --- a/ImageBoardServerApp/Data/BoardData.cs +++ b/ImageBoardServerApp/Data/BoardData.cs @@ -1,16 +1,24 @@ using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace ImageBoardServerApp.Data; public class BoardData { + [Required] + [DatabaseGenerated((DatabaseGeneratedOption.Identity))] + [Key] public int BoardID { get; set; } + [Required] public string Tag { get; set; } + [Required] public string Topic { get; set; } + [Required] public int maxThreads { get; set; } - + [Required] + public bool isLocked { get; set; } } \ No newline at end of file diff --git a/ImageBoardServerApp/Data/Repository/BoardsRepository.cs b/ImageBoardServerApp/Data/Repository/BoardsRepository.cs new file mode 100644 index 0000000..01fd7df --- /dev/null +++ b/ImageBoardServerApp/Data/Repository/BoardsRepository.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore; + +namespace ImageBoardServerApp.Data.Repository; + +public static class BoardsRepository +{ + public static async Task> getBoardsAsync() + { + await using var db = new AppDBContext(); + return await db.Boards + .ToListAsync(); + } + + public static async Task getBoardsByIdAsync(int boardID) + { + await using var db = new AppDBContext(); + return await db.Boards.FirstOrDefaultAsync(board => board.BoardID == boardID); + } + + public static async Task getBoardByTagAsync(string tag) + { + await using var db = new AppDBContext(); + return await db.Boards + .Where(board => board.Tag == tag) + .FirstOrDefaultAsync(); + } + + public static async Task createBoardAsync(BoardData boardToCreate) + { + await using var db = new AppDBContext(); + await db.Boards.AddAsync(boardToCreate); + if (await db.SaveChangesAsync() >= 1) + { + Console.WriteLine($"Created user with ID: {boardToCreate.BoardID}"); + return boardToCreate.BoardID; + } + + return -1; + } + + public static async Task updateBoardAsync(BoardData boardToCreate) + { + await using var db = new AppDBContext(); + db.Boards.Update(boardToCreate); + return await db.SaveChangesAsync() >= 1; + } + + public static async Task deleteBoardAsync(int boardId) + { + await using var db = new AppDBContext(); + BoardData boardToDelete = await getBoardsByIdAsync(boardId); + db.Remove(boardToDelete); + return await db.SaveChangesAsync() >= 1; + } +} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Basic/BoardPage.razor b/ImageBoardServerApp/Pages/Basic/BoardPage.razor new file mode 100644 index 0000000..66053f8 --- /dev/null +++ b/ImageBoardServerApp/Pages/Basic/BoardPage.razor @@ -0,0 +1,21 @@ +@page "/{boardTag}/" +@using ImageBoardServerApp.Data.Repository +@using System.ComponentModel.DataAnnotations + + + +@code { + + [Parameter] + [Required] + public string boardTag { get; set; } + + private BoardData m; + + + protected override async Task OnParametersSetAsync() + { + m = await BoardsRepository.getBoardByTagAsync(boardTag); + } + +} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Boards/Art.razor b/ImageBoardServerApp/Pages/Boards/Art.razor deleted file mode 100644 index ba632c0..0000000 --- a/ImageBoardServerApp/Pages/Boards/Art.razor +++ /dev/null @@ -1,14 +0,0 @@ -@page "/art/" - - - -@code { - - private BoardData m { get; set; } = new() - { - BoardID = 0, - maxThreads = 10, - Tag = "art", - Topic = "Art" - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Boards/Au.razor b/ImageBoardServerApp/Pages/Boards/Au.razor deleted file mode 100644 index 8179161..0000000 --- a/ImageBoardServerApp/Pages/Boards/Au.razor +++ /dev/null @@ -1,14 +0,0 @@ -@page "/au/" - - - -@code { - - private BoardData m { get; set; } = new() - { - BoardID = 0, - maxThreads = 10, - Tag = "au", - Topic = "Autism" - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Boards/E.razor b/ImageBoardServerApp/Pages/Boards/E.razor deleted file mode 100644 index e73c04b..0000000 --- a/ImageBoardServerApp/Pages/Boards/E.razor +++ /dev/null @@ -1,14 +0,0 @@ -@page "/e/" - - - -@code { - - private BoardData m { get; set; } = new() - { - BoardID = 0, - maxThreads = 10, - Tag = "e", - Topic = "Everything" - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Boards/Tec.razor b/ImageBoardServerApp/Pages/Boards/Tec.razor deleted file mode 100644 index 237c9b8..0000000 --- a/ImageBoardServerApp/Pages/Boards/Tec.razor +++ /dev/null @@ -1,14 +0,0 @@ -@page "/tec/" - - - -@code { - - private BoardData m { get; set; } = new() - { - BoardID = 0, - maxThreads = 10, - Tag = "tec", - Topic = "Technology" - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Pages/Boards/Vg.razor b/ImageBoardServerApp/Pages/Boards/Vg.razor deleted file mode 100644 index 9e186ee..0000000 --- a/ImageBoardServerApp/Pages/Boards/Vg.razor +++ /dev/null @@ -1,14 +0,0 @@ -@page "/vg/" - - - -@code { - - private BoardData m { get; set; } = new() - { - BoardID = 0, - maxThreads = 10, - Tag = "vg", - Topic = "Video Games" - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/Components/Board.razor b/ImageBoardServerApp/Shared/Components/Board.razor index 7b7cb18..e7feb3a 100644 --- a/ImageBoardServerApp/Shared/Components/Board.razor +++ b/ImageBoardServerApp/Shared/Components/Board.razor @@ -49,7 +49,7 @@ private List posts; - protected override async Task OnInitializedAsync() + protected override async Task OnParametersSetAsync() { posts = await TheManager.getPostList(board.Tag); } diff --git a/ImageBoardServerApp/Shared/NavMenu.razor b/ImageBoardServerApp/Shared/NavMenu.razor index 6d670ef..81cabe2 100644 --- a/ImageBoardServerApp/Shared/NavMenu.razor +++ b/ImageBoardServerApp/Shared/NavMenu.razor @@ -1,13 +1,14 @@ @using ImageBoardServerApp.Auth +@using ImageBoardServerApp.Data.Repository @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navManager @@ -70,4 +54,12 @@ await customAuthStateProvider.UpdateAuthenticationStateAsync(null); navManager.NavigateTo("/", true); } + + public List boards { get; set; } + + protected override async Task OnInitializedAsync() + { + boards = await BoardsRepository.getBoardsAsync(); + } + } \ No newline at end of file diff --git a/ImageBoardServerApp/Util/Boards.cs b/ImageBoardServerApp/Util/Boards.cs deleted file mode 100644 index 60d1fb6..0000000 --- a/ImageBoardServerApp/Util/Boards.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace ImageBoardServerApp.Data; - -public class Boards -{ - private List posts = new List() - { - - }; -} \ No newline at end of file diff --git a/ImageBoardServerApp/Util/TheManager.cs b/ImageBoardServerApp/Util/TheManager.cs index 257125d..9d06061 100644 --- a/ImageBoardServerApp/Util/TheManager.cs +++ b/ImageBoardServerApp/Util/TheManager.cs @@ -22,7 +22,7 @@ public class TheManager public static long getBumpValue(PostData post) { - return (post.IsSticky ? 999999999999999999 : 10 * 60000 - getDiff(post) + ( 60000 * (post.Comments.Count + 1))) ; + return (post.IsSticky ? 999999999999999999 + getDiff(post) : 10 * 60000 - getDiff(post) + ( 60000 * (post.Comments.Count + 1))) ; } public static async Task> getPostList(string boardTag) diff --git a/ImageBoardServerApp/_Imports.razor b/ImageBoardServerApp/_Imports.razor index 9ae8f44..c11d557 100644 --- a/ImageBoardServerApp/_Imports.razor +++ b/ImageBoardServerApp/_Imports.razor @@ -10,7 +10,6 @@ @using Radzen.Blazor @using ImageBoardServerApp @using ImageBoardServerApp.Pages -@using ImageBoardServerApp.Pages.Boards @using ImageBoardServerApp.Pages.Accounts @using ImageBoardServerApp.Pages.Basic @using ImageBoardServerApp.Pages.Status