chore: cleanup

This commit is contained in:
limited_dev 2023-02-03 11:33:56 +01:00
parent 0e725b065a
commit f5ac34e639
17 changed files with 67 additions and 3 deletions

View file

@ -22,9 +22,24 @@ public static class CommentsRepository
public static async Task<CommentData> getCommentByIdAsync(int postId)
{
await using var db = new AppDBContext();
return await db.Comments.FirstOrDefaultAsync(comment => comment.PostID == postId);
return await db.Comments
.Where(comment => comment.CommentID == postId)
.Include(comment => comment.Image)
.Include(comment => comment.Post)
.FirstOrDefaultAsync();
}
/*public static async Task<PostData> getPostByIdAsync(int postId)
{
await using var db = new AppDBContext();
return await db.Posts
.Where(post => post.PostID == postId)
.Include(post => post.Image)
.Include(post => post.Comments)
.FirstOrDefaultAsync();
//return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId);
}*/
public static async Task<int> createCommentAsync(CommentData commentData)
{
await using var db = new AppDBContext();

View file

@ -17,6 +17,7 @@ public static class PostsRepository
.Where(post => post.Board.Equals(board))
.Include(post => post.Image)
.Include(post => post.Comments)
.Include(post => post.User)
.ToListAsync();
}
@ -27,6 +28,7 @@ public static class PostsRepository
.Where(post => post.PostID == postId)
.Include(post => post.Image)
.Include(post => post.Comments)
.Include(post => post.User)
.FirstOrDefaultAsync();
//return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId);
}

View file

@ -0,0 +1,17 @@
@page "/report/{type}/{board}/{id}"
@using System.ComponentModel.DataAnnotations
<h3>Report</h3>
@code {
[Parameter]
[Required]
public string type { get; set; }
[Parameter]
[Required]
public string board { get; set; }
[Parameter]
[Required]
public string id { get; set; }
}

View file

@ -1,6 +1,8 @@
@using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Auth
@using ImageBoardServerApp.Data
@using ImageBoardServerApp.Data.Repository
@inject AuthenticationStateProvider authStateProvider
<div class="threadHeader">
<span>[</span>
@ -35,7 +37,10 @@
</div>
<div class="threadFooter">
<span>[</span>
<a class="report" href="/report/@comment.Board/@comment.PostID/comment/@comment.CommentID" target="_blank">Report</a>
<a @onclick="@deletePost" href="javascript:void(0)">Delete</a>
<span>]</span>
<span>[</span>
<a class="report" href="/report/comment/@comment.Board/@comment.CommentID" target="_blank">Report</a>
<span>]</span>
</div>
}
@ -43,6 +48,20 @@
@code {
private async Task deletePost()
{
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
var user = await cauthStateProvder.GetAuthenticationStateAsync();
var usr = user.User;
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
if (foundusr.PermissionInteger >= 50 || comment.UserID == foundusr.UserID)
{
await CommentsRepository.deleteCommentAsync(comment.CommentID);
}
}
private static DateTime getTimeFromUnix(double javaTimeStamp)
{
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

View file

@ -13,6 +13,7 @@
}
<span class="title">@post.Title</span>
<span class="name">@post.Username</span>
<span class="roleAdmin" >##@post.User.Role</span>
<span class="date">@getTimeFromUnix(post.CreatedAt)</span>
<span class="post-id">No.@post.PostID</span>
</div>
@ -48,7 +49,7 @@
<a @onclick="@deletePost" href="javascript:void(0)">Delete</a>
<span>]</span>
<span>[</span>
<a class="report" href="/report/@post.Board/@post.PostID" target="_blank">Report</a>
<a class="report" href="/report/op/@post.Board/@post.PostID" target="_blank">Report</a>
<span>]</span>
@if (showOpenThread)
{

View file

@ -16,6 +16,10 @@
color: #339305;
}
.roleAdmin{
color: #ff191c;
}
.threadHeader{
text-align: left;
}

View file

@ -11,6 +11,12 @@
@using Radzen
@using Radzen.Blazor
@using ImageBoardServerApp
@using ImageBoardServerApp.Pages
@using ImageBoardServerApp.Pages.Boards
@using ImageBoardServerApp.Pages.Accounts
@using ImageBoardServerApp.Pages.Basic
@using ImageBoardServerApp.Pages.Components
@using ImageBoardServerApp.Pages.Status
@using ImageBoardServerApp.Shared
@using ImageBoardServerApp.Shared.Components
@using ImageBoardServerApp.Shared.Components.Forms