use diesel::sql_types::Integer; use diesel::sql_types::Nullable; use diesel::sql_types::SmallInt; use diesel::sql_types::Timestamp; use diesel::sql_types::Text; use diesel::sql_types::BigInt; use chrono::NaiveDateTime; use diesel::{Insertable, Queryable, QueryableByName, Selectable}; use serde::Serialize; #[derive(Queryable, Selectable, Serialize, Clone)] #[diesel(table_name = crate::schema::issues)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct Issue { pub id: i32, pub title: String, pub paragraph_count: Option, pub telegram_handle: String, pub created_at: Option } #[derive(QueryableByName, Serialize, Clone)] pub struct IssueWithSummaryAndVotes { #[diesel(sql_type = Integer)] pub id: i32, #[diesel(sql_type = Text)] pub title: String, #[diesel(sql_type = Text)] pub summary: String, #[diesel(sql_type = Nullable)] pub paragraph_count: Option, #[diesel(sql_type = Text)] pub telegram_handle: String, #[diesel(sql_type = Nullable)] pub created_at: Option, #[diesel(sql_type = BigInt)] pub total_votes: i64, #[diesel(sql_type = BigInt)] pub positive_votes: i64, } #[derive(Insertable)] #[diesel(table_name = crate::schema::issues)] pub struct NewIssue { pub title: String, pub paragraph_count: i16, pub telegram_handle: String, } #[derive(Queryable, Selectable)] #[diesel(table_name = crate::schema::sessions)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct Session { pub id: i64, pub session_id: String, pub auth_date: Option, pub username: Option, pub first_name: Option, pub last_name: Option, pub photo_url: Option } #[derive(Insertable)] #[diesel(table_name = crate::schema::sessions)] pub struct NewSession { pub user_id: Option, pub session_id: String, pub auth_date: i64, pub username: Option, pub first_name: Option, pub last_name: Option, pub photo_url: Option } #[derive(Queryable, Selectable, Serialize, Clone)] #[diesel(table_name = crate::schema::paragraphs)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct Paragraph { pub id: i64, pub content: String, pub index: i32, pub post_id: i32, } #[derive(Insertable)] #[diesel(table_name = crate::schema::paragraphs)] pub struct NewParagraph { pub content: Option, pub index: i32, pub post_id: i32, } #[derive(Queryable, Selectable, Serialize, Clone)] #[diesel(table_name = crate::schema::issue_votes)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct IssueVote { pub id: i64, pub positive: Option, pub issue_id: i32, pub user_id: i64, } #[derive(Insertable)] #[diesel(table_name = crate::schema::issue_votes)] pub struct NewIssueVote { pub positive: bool, pub issue_id: i32, pub user_id: i64, } #[derive(Queryable, Selectable, Serialize, Clone)] #[diesel(table_name = crate::schema::comments)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct Comment { pub id: i64, pub content: String, pub parent: Option, pub telegram_handle: String, pub issue_id: i32, pub created_at: Option } #[derive(Insertable)] #[diesel(table_name = crate::schema::comments)] pub struct NewComment { pub content: String, pub parent: Option, pub telegram_handle: String, pub issue_id: i32, pub created_at: NaiveDateTime } #[derive(Queryable, Selectable, Serialize, Clone)] #[diesel(table_name = crate::schema::comment_votes)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct CommentVote { pub id: i64, pub positive: Option, pub comment_id: i64, pub user_id: i64, } #[derive(Insertable)] #[diesel(table_name = crate::schema::comment_votes)] pub struct NewCommentVote { pub positive: Option, pub comment_id: Option, pub user_id: Option, }