feat: made accounts deleteable, other changes
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
c20c5c9343
commit
8f38879294
10 changed files with 116 additions and 35 deletions
|
@ -9,7 +9,7 @@ public static class CommentsRepository
|
|||
await using var db = new AppDBContext();
|
||||
return await db.Comments.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<List<CommentData>> getCommentsByBoardAsync(string board)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
@ -18,7 +18,7 @@ public static class CommentsRepository
|
|||
.Include(comment => comment.Image)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<CommentData> getCommentByIdAsync(int postId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
@ -30,8 +30,8 @@ public static class CommentsRepository
|
|||
.Include(comment => comment.Report)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public static async Task<CommentData> getCommentByGETAsync(string board, int get)
|
||||
|
||||
public static async Task<CommentData> getCommentByGETAsync(string board, int get)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
return await db.Comments
|
||||
|
@ -43,17 +43,15 @@ public static class CommentsRepository
|
|||
.Include(comment => comment.Report)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
/*public static async Task<PostData> getPostByIdAsync(int postId)
|
||||
|
||||
public static async Task deleteCommentFromUser(UserData u)
|
||||
{
|
||||
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);
|
||||
}*/
|
||||
var l = db.Users
|
||||
.Where(x => x.UserID == u.UserID);
|
||||
foreach (var e in l)
|
||||
db.Remove(e);
|
||||
}
|
||||
|
||||
public static async Task<int> createCommentAsync(CommentData commentData)
|
||||
{
|
||||
|
@ -64,16 +62,17 @@ public static class CommentsRepository
|
|||
Console.WriteLine($"Created comment with ID: {commentData.PostID}");
|
||||
return commentData.PostID;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> updateCommentAsync(CommentData commentToUpdate)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
db.Comments.Update(commentToUpdate);
|
||||
return await db.SaveChangesAsync() >= 1;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> deleteCommentAsync(int postId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
|
|
@ -9,7 +9,7 @@ public static class PostsRepository
|
|||
await using var db = new AppDBContext();
|
||||
return await db.Posts.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<List<PostData>> getPostsByBoardAsync(string board)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
@ -20,7 +20,7 @@ public static class PostsRepository
|
|||
.Include(post => post.User)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<PostData> getPostByIdAsync(int postId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
@ -32,7 +32,7 @@ public static class PostsRepository
|
|||
.FirstOrDefaultAsync();
|
||||
//return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId);
|
||||
}
|
||||
|
||||
|
||||
public static async Task<PostData> getPostByGETAsync(string board, int get)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
@ -55,16 +55,26 @@ public static class PostsRepository
|
|||
Console.WriteLine($"Created post with ID: {postToCreate.PostID}");
|
||||
return postToCreate.PostID;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static async Task deletePostsFromUser(UserData u)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
var l = db.Posts
|
||||
.Where(x => x.UserID == u.UserID);
|
||||
foreach (var e in l)
|
||||
db.Remove(e);
|
||||
}
|
||||
|
||||
public static async Task<bool> updatePostAsync(PostData postToUpdate)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
db.Posts.Update(postToUpdate);
|
||||
return await db.SaveChangesAsync() >= 1;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> deletePostAsync(int postId)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue