feat: made boards dynamic and save to the db
This commit is contained in:
parent
8ebc78b754
commit
97e4b0026b
14 changed files with 107 additions and 110 deletions
|
@ -9,6 +9,7 @@ internal sealed class AppDBContext : DbContext
|
||||||
public DbSet<ImageData> Images { get; set; }
|
public DbSet<ImageData> Images { get; set; }
|
||||||
public DbSet<CommentData> Comments { get; set; }
|
public DbSet<CommentData> Comments { get; set; }
|
||||||
public DbSet<ReportData> Reports { get; set; }
|
public DbSet<ReportData> Reports { get; set; }
|
||||||
|
public DbSet<BoardData> Boards { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace ImageBoardServerApp.Data;
|
namespace ImageBoardServerApp.Data;
|
||||||
|
|
||||||
public class BoardData
|
public class BoardData
|
||||||
{
|
{
|
||||||
|
[Required]
|
||||||
|
[DatabaseGenerated((DatabaseGeneratedOption.Identity))]
|
||||||
|
[Key]
|
||||||
public int BoardID { get; set; }
|
public int BoardID { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
public string Tag { get; set; }
|
public string Tag { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
public string Topic { get; set; }
|
public string Topic { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
public int maxThreads { get; set; }
|
public int maxThreads { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public bool isLocked { get; set; }
|
||||||
}
|
}
|
55
ImageBoardServerApp/Data/Repository/BoardsRepository.cs
Normal file
55
ImageBoardServerApp/Data/Repository/BoardsRepository.cs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ImageBoardServerApp.Data.Repository;
|
||||||
|
|
||||||
|
public static class BoardsRepository
|
||||||
|
{
|
||||||
|
public static async Task<List<BoardData>> getBoardsAsync()
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
return await db.Boards
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<BoardData> getBoardsByIdAsync(int boardID)
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
return await db.Boards.FirstOrDefaultAsync(board => board.BoardID == boardID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<BoardData> getBoardByTagAsync(string tag)
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
return await db.Boards
|
||||||
|
.Where(board => board.Tag == tag)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<int> 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<bool> updateBoardAsync(BoardData boardToCreate)
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
db.Boards.Update(boardToCreate);
|
||||||
|
return await db.SaveChangesAsync() >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> deleteBoardAsync(int boardId)
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
BoardData boardToDelete = await getBoardsByIdAsync(boardId);
|
||||||
|
db.Remove(boardToDelete);
|
||||||
|
return await db.SaveChangesAsync() >= 1;
|
||||||
|
}
|
||||||
|
}
|
21
ImageBoardServerApp/Pages/Basic/BoardPage.razor
Normal file
21
ImageBoardServerApp/Pages/Basic/BoardPage.razor
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
@page "/{boardTag}/"
|
||||||
|
@using ImageBoardServerApp.Data.Repository
|
||||||
|
@using System.ComponentModel.DataAnnotations
|
||||||
|
|
||||||
|
<Board board="@m"/>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
[Required]
|
||||||
|
public string boardTag { get; set; }
|
||||||
|
|
||||||
|
private BoardData m;
|
||||||
|
|
||||||
|
|
||||||
|
protected override async Task OnParametersSetAsync()
|
||||||
|
{
|
||||||
|
m = await BoardsRepository.getBoardByTagAsync(boardTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
@page "/art/"
|
|
||||||
|
|
||||||
<Board board="@m"/>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
private BoardData m { get; set; } = new()
|
|
||||||
{
|
|
||||||
BoardID = 0,
|
|
||||||
maxThreads = 10,
|
|
||||||
Tag = "art",
|
|
||||||
Topic = "Art"
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
@page "/au/"
|
|
||||||
|
|
||||||
<Board board="@m"/>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
private BoardData m { get; set; } = new()
|
|
||||||
{
|
|
||||||
BoardID = 0,
|
|
||||||
maxThreads = 10,
|
|
||||||
Tag = "au",
|
|
||||||
Topic = "Autism"
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
@page "/e/"
|
|
||||||
|
|
||||||
<Board board="@m"/>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
private BoardData m { get; set; } = new()
|
|
||||||
{
|
|
||||||
BoardID = 0,
|
|
||||||
maxThreads = 10,
|
|
||||||
Tag = "e",
|
|
||||||
Topic = "Everything"
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
@page "/tec/"
|
|
||||||
|
|
||||||
<Board board="@m"/>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
private BoardData m { get; set; } = new()
|
|
||||||
{
|
|
||||||
BoardID = 0,
|
|
||||||
maxThreads = 10,
|
|
||||||
Tag = "tec",
|
|
||||||
Topic = "Technology"
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
@page "/vg/"
|
|
||||||
|
|
||||||
<Board board="@m"/>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
private BoardData m { get; set; } = new()
|
|
||||||
{
|
|
||||||
BoardID = 0,
|
|
||||||
maxThreads = 10,
|
|
||||||
Tag = "vg",
|
|
||||||
Topic = "Video Games"
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
private List<PostData> posts;
|
private List<PostData> posts;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
posts = await TheManager.getPostList(board.Tag);
|
posts = await TheManager.getPostList(board.Tag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
@using ImageBoardServerApp.Auth
|
@using ImageBoardServerApp.Auth
|
||||||
|
@using ImageBoardServerApp.Data.Repository
|
||||||
@inject AuthenticationStateProvider authStateProvider
|
@inject AuthenticationStateProvider authStateProvider
|
||||||
@inject NavigationManager navManager
|
@inject NavigationManager navManager
|
||||||
|
|
||||||
<div class="top-row ps-3 navbar navbar-dark">
|
<div class="top-row ps-3 navbar navbar-dark">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="">IB v0.1.3</a>
|
<a class="navbar-brand" href="">BB v0.1.4</a>
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<a class="navbar-brand" @onclick="logout" href="javascript:void(0)" >[Logout]</a>
|
<a class="navbar-brand" @onclick="logout" href="javascript:void(0)" >[Logout]</a>
|
||||||
|
@ -26,31 +27,14 @@
|
||||||
<span class="oi oi-home" aria-hidden="true"></span> Home
|
<span class="oi oi-home" aria-hidden="true"></span> Home
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
@foreach (BoardData b in boards)
|
||||||
|
{
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="e">
|
<NavLink class="nav-link" href="@b.Tag">
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> /e/ - Everything
|
<span class="oi oi-list-rich" aria-hidden="true"></span> /@b.Tag/ - @b.Topic
|
||||||
</NavLink>
|
|
||||||
</div>
|
|
||||||
<div class="nav-item px-3">
|
|
||||||
<NavLink class="nav-link" href="tec">
|
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> /tec/ - Technology
|
|
||||||
</NavLink>
|
|
||||||
</div>
|
|
||||||
<div class="nav-item px-3">
|
|
||||||
<NavLink class="nav-link" href="art">
|
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> /art/ - Art
|
|
||||||
</NavLink>
|
|
||||||
</div>
|
|
||||||
<div class="nav-item px-3">
|
|
||||||
<NavLink class="nav-link" href="vg">
|
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> /vg/ - Video Games
|
|
||||||
</NavLink>
|
|
||||||
</div>
|
|
||||||
<div class="nav-item px-3">
|
|
||||||
<NavLink class="nav-link" href="au">
|
|
||||||
<span class="oi oi-list-rich" aria-hidden="true"></span> /au/ - Autism
|
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -70,4 +54,12 @@
|
||||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
||||||
navManager.NavigateTo("/", true);
|
navManager.NavigateTo("/", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<BoardData> boards { get; set; }
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
boards = await BoardsRepository.getBoardsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
namespace ImageBoardServerApp.Data;
|
|
||||||
|
|
||||||
public class Boards
|
|
||||||
{
|
|
||||||
private List<PostData> posts = new List<PostData>()
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ public class TheManager
|
||||||
|
|
||||||
public static long getBumpValue(PostData post)
|
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<List<PostData>> getPostList(string boardTag)
|
public static async Task<List<PostData>> getPostList(string boardTag)
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
@using Radzen.Blazor
|
@using Radzen.Blazor
|
||||||
@using ImageBoardServerApp
|
@using ImageBoardServerApp
|
||||||
@using ImageBoardServerApp.Pages
|
@using ImageBoardServerApp.Pages
|
||||||
@using ImageBoardServerApp.Pages.Boards
|
|
||||||
@using ImageBoardServerApp.Pages.Accounts
|
@using ImageBoardServerApp.Pages.Accounts
|
||||||
@using ImageBoardServerApp.Pages.Basic
|
@using ImageBoardServerApp.Pages.Basic
|
||||||
@using ImageBoardServerApp.Pages.Status
|
@using ImageBoardServerApp.Pages.Status
|
||||||
|
|
Loading…
Reference in a new issue