bug fixes
This commit is contained in:
parent
f02524b592
commit
192be95f84
5 changed files with 35 additions and 14 deletions
|
@ -18,6 +18,8 @@
|
|||
<link rel="stylesheet" href="/css/main.css">
|
||||
<link rel="stylesheet" href="/css/header.css">
|
||||
<link rel="stylesheet" href="/css/admin.css">
|
||||
|
||||
<script src="/js/admin.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
|
|
|
@ -22,8 +22,13 @@ async function post() {
|
|||
comments: []
|
||||
}
|
||||
data.posts.unshift(post)
|
||||
let html = parsePost(post)
|
||||
prepend(html, posts_block)
|
||||
let html = parsePost(post, data.users, data.self)
|
||||
|
||||
posts_block.insertBefore(
|
||||
html,
|
||||
posts_block.firstChild
|
||||
)
|
||||
|
||||
document.getElementById('popup').classList.add('hidden')
|
||||
}
|
||||
|
||||
|
|
|
@ -100,10 +100,10 @@ impl Check for PostPageRequest {
|
|||
}
|
||||
|
||||
async fn page(
|
||||
AuthorizedUser(_user): AuthorizedUser,
|
||||
AuthorizedUser(user): AuthorizedUser,
|
||||
Json(body): Json<PostPageRequest>,
|
||||
) -> Response {
|
||||
let Ok(posts) = Post::from_post_page(body.page) else {
|
||||
let Ok(posts) = Post::from_post_page(user.user_id, body.page) else {
|
||||
return ResponseCode::InternalServerError.text("Failed to fetch posts")
|
||||
};
|
||||
|
||||
|
@ -196,10 +196,10 @@ impl Check for UsersPostsRequest {
|
|||
}
|
||||
|
||||
async fn user(
|
||||
AuthorizedUser(_user): AuthorizedUser,
|
||||
AuthorizedUser(user): AuthorizedUser,
|
||||
Json(body): Json<UsersPostsRequest>,
|
||||
) -> Response {
|
||||
let Ok(posts) = Post::from_user_post_page(body.user_id, body.page) else {
|
||||
let Ok(posts) = Post::from_user_post_page(user.user_id, body.user_id, body.page) else {
|
||||
return ResponseCode::InternalServerError.text("Failed to fetch posts")
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ fn post_from_row(row: &Row) -> Result<Post, rusqlite::Error> {
|
|||
|
||||
let comments = comments::get_comments_page(0, post_id).unwrap_or_else(|_| Vec::new());
|
||||
let likes = likes::get_like_count(post_id).unwrap_or(None).unwrap_or(0);
|
||||
let liked = likes::get_liked(user_id, post_id).unwrap_or(false);
|
||||
|
||||
Ok(Post {
|
||||
post_id,
|
||||
|
@ -39,7 +38,7 @@ fn post_from_row(row: &Row) -> Result<Post, rusqlite::Error> {
|
|||
content,
|
||||
date,
|
||||
likes,
|
||||
liked,
|
||||
liked: false,
|
||||
comments,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,27 +28,42 @@ impl fmt::Debug for Post {
|
|||
|
||||
impl Post {
|
||||
#[instrument()]
|
||||
pub fn from_post_id(post_id: u64) -> Result<Self> {
|
||||
let Ok(Some(post)) = database::posts::get_post(post_id) else {
|
||||
pub fn from_post_id(self_id: u64, post_id: u64) -> Result<Self> {
|
||||
let Ok(Some(mut post)) = database::posts::get_post(post_id) else {
|
||||
return Err(ResponseCode::BadRequest.text("Post does not exist"))
|
||||
};
|
||||
|
||||
let liked = database::likes::get_liked(self_id, post.post_id).unwrap_or(false);
|
||||
post.liked = liked;
|
||||
|
||||
Ok(post)
|
||||
}
|
||||
|
||||
#[instrument()]
|
||||
pub fn from_post_page(page: u64) -> Result<Vec<Self>> {
|
||||
let Ok(posts) = database::posts::get_post_page(page) else {
|
||||
pub fn from_post_page(self_id: u64, page: u64) -> Result<Vec<Self>> {
|
||||
let Ok(mut posts) = database::posts::get_post_page(page) else {
|
||||
return Err(ResponseCode::BadRequest.text("Failed to fetch posts"))
|
||||
};
|
||||
|
||||
for post in &mut posts {
|
||||
let liked = database::likes::get_liked(self_id, post.post_id).unwrap_or(false);
|
||||
post.liked = liked;
|
||||
}
|
||||
|
||||
Ok(posts)
|
||||
}
|
||||
|
||||
#[instrument()]
|
||||
pub fn from_user_post_page(user_id: u64, page: u64) -> Result<Vec<Self>> {
|
||||
let Ok(posts) = database::posts::get_users_post_page(user_id, page) else {
|
||||
pub fn from_user_post_page(self_id: u64, user_id: u64, page: u64) -> Result<Vec<Self>> {
|
||||
let Ok(mut posts) = database::posts::get_users_post_page(user_id, page) else {
|
||||
return Err(ResponseCode::BadRequest.text("Failed to fetch posts"))
|
||||
};
|
||||
|
||||
for post in &mut posts {
|
||||
let liked = database::likes::get_liked(self_id, post.post_id).unwrap_or(false);
|
||||
post.liked = liked;
|
||||
}
|
||||
|
||||
Ok(posts)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue