use crate::{
naive_now,
schema::{comment, comment_like, comment_saved},
+ ApubObject,
Crud,
Likeable,
Saveable,
}
}
+impl ApubObject<CommentForm> for Comment {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ use crate::schema::comment::dsl::*;
+ comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
+ }
+
+ fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+ use crate::schema::comment::dsl::*;
+ insert_into(comment)
+ .values(comment_form)
+ .on_conflict(ap_id)
+ .do_update()
+ .set(comment_form)
+ .get_result::<Self>(conn)
+ }
+}
+
impl Comment {
pub fn update_ap_id(
conn: &PgConnection,
.get_result::<Self>(conn)
}
- pub fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
- }
-
pub fn permadelete_for_creator(
conn: &PgConnection,
for_creator_id: i32,
.set((content.eq(new_content), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
-
- pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
- use crate::schema::comment::dsl::*;
- insert_into(comment)
- .values(comment_form)
- .on_conflict(ap_id)
- .do_update()
- .set(comment_form)
- .get_result::<Self>(conn)
- }
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]