mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2025-02-20 16:46:16 +00:00
- Use `Result` as much as possible - Display errors instead of panicking TODO (maybe in another PR? this one is already quite big): - Find a way to merge Ructe/ErrorPage types, so that we can have routes returning `Result<X, ErrorPage>` instead of panicking when we have an `Error` - Display more details about the error, to make it easier to debug (sorry, this isn't going to be fun to review, the diff is huge, but it is always the same changes)
32 lines
826 B
Rust
32 lines
826 B
Rust
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
|
|
|
use comments::Comment;
|
|
use schema::comment_seers;
|
|
use users::User;
|
|
use {Connection, Error, Result};
|
|
|
|
#[derive(Queryable, Serialize, Clone)]
|
|
pub struct CommentSeers {
|
|
pub id: i32,
|
|
pub comment_id: i32,
|
|
pub user_id: i32,
|
|
}
|
|
|
|
#[derive(Insertable, Default)]
|
|
#[table_name = "comment_seers"]
|
|
pub struct NewCommentSeers {
|
|
pub comment_id: i32,
|
|
pub user_id: i32,
|
|
}
|
|
|
|
impl CommentSeers {
|
|
insert!(comment_seers, NewCommentSeers);
|
|
|
|
pub fn can_see(conn: &Connection, c: &Comment, u: &User) -> Result<bool> {
|
|
comment_seers::table.filter(comment_seers::comment_id.eq(c.id))
|
|
.filter(comment_seers::user_id.eq(u.id))
|
|
.load::<CommentSeers>(conn)
|
|
.map_err(Error::from)
|
|
.map(|r| !r.is_empty())
|
|
}
|
|
}
|