The backend for PuffPastry, a DAO platform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

150 lines
3.9 KiB

  1. use diesel::sql_types::Integer;
  2. use diesel::sql_types::Nullable;
  3. use diesel::sql_types::SmallInt;
  4. use diesel::sql_types::Timestamp;
  5. use diesel::sql_types::Text;
  6. use diesel::sql_types::BigInt;
  7. use chrono::NaiveDateTime;
  8. use diesel::{Insertable, Queryable, QueryableByName, Selectable};
  9. use serde::Serialize;
  10. #[derive(Queryable, Selectable, Serialize, Clone)]
  11. #[diesel(table_name = crate::schema::issues)]
  12. #[diesel(check_for_backend(diesel::pg::Pg))]
  13. pub struct Issue {
  14. pub id: i32,
  15. pub title: String,
  16. pub paragraph_count: Option<i16>,
  17. pub telegram_handle: String,
  18. pub created_at: Option<NaiveDateTime>
  19. }
  20. #[derive(QueryableByName, Serialize, Clone)]
  21. pub struct IssueWithSummaryAndVotes {
  22. #[diesel(sql_type = Integer)]
  23. pub id: i32,
  24. #[diesel(sql_type = Text)]
  25. pub title: String,
  26. #[diesel(sql_type = Text)]
  27. pub summary: String,
  28. #[diesel(sql_type = Nullable<SmallInt>)]
  29. pub paragraph_count: Option<i16>,
  30. #[diesel(sql_type = Text)]
  31. pub telegram_handle: String,
  32. #[diesel(sql_type = Nullable<Timestamp>)]
  33. pub created_at: Option<NaiveDateTime>,
  34. #[diesel(sql_type = BigInt)]
  35. pub total_votes: i64,
  36. #[diesel(sql_type = BigInt)]
  37. pub positive_votes: i64,
  38. }
  39. #[derive(Insertable)]
  40. #[diesel(table_name = crate::schema::issues)]
  41. pub struct NewIssue {
  42. pub title: String,
  43. pub paragraph_count: i16,
  44. pub telegram_handle: String,
  45. }
  46. #[derive(Queryable, Selectable)]
  47. #[diesel(table_name = crate::schema::sessions)]
  48. #[diesel(check_for_backend(diesel::pg::Pg))]
  49. pub struct Session {
  50. pub id: i64,
  51. pub session_id: String,
  52. pub auth_date: Option<i64>,
  53. pub username: Option<String>,
  54. pub first_name: Option<String>,
  55. pub last_name: Option<String>,
  56. pub photo_url: Option<String>
  57. }
  58. #[derive(Insertable)]
  59. #[diesel(table_name = crate::schema::sessions)]
  60. pub struct NewSession {
  61. pub user_id: Option<i64>,
  62. pub session_id: String,
  63. pub auth_date: i64,
  64. pub username: Option<String>,
  65. pub first_name: Option<String>,
  66. pub last_name: Option<String>,
  67. pub photo_url: Option<String>
  68. }
  69. #[derive(Queryable, Selectable, Serialize, Clone)]
  70. #[diesel(table_name = crate::schema::paragraphs)]
  71. #[diesel(check_for_backend(diesel::pg::Pg))]
  72. pub struct Paragraph {
  73. pub id: i64,
  74. pub content: String,
  75. pub index: i32,
  76. pub post_id: i32,
  77. }
  78. #[derive(Insertable)]
  79. #[diesel(table_name = crate::schema::paragraphs)]
  80. pub struct NewParagraph {
  81. pub content: Option<String>,
  82. pub index: i32,
  83. pub post_id: i32,
  84. }
  85. #[derive(Queryable, Selectable, Serialize, Clone)]
  86. #[diesel(table_name = crate::schema::issue_votes)]
  87. #[diesel(check_for_backend(diesel::pg::Pg))]
  88. pub struct IssueVote {
  89. pub id: i64,
  90. pub positive: Option<bool>,
  91. pub issue_id: i32,
  92. pub user_id: i64,
  93. }
  94. #[derive(Insertable)]
  95. #[diesel(table_name = crate::schema::issue_votes)]
  96. pub struct NewIssueVote {
  97. pub positive: bool,
  98. pub issue_id: i32,
  99. pub user_id: i64,
  100. }
  101. #[derive(Queryable, Selectable, Serialize, Clone)]
  102. #[diesel(table_name = crate::schema::comments)]
  103. #[diesel(check_for_backend(diesel::pg::Pg))]
  104. pub struct Comment {
  105. pub id: i64,
  106. pub content: String,
  107. pub parent: Option<i64>,
  108. pub telegram_handle: String,
  109. pub issue_id: i32,
  110. pub created_at: Option<NaiveDateTime>
  111. }
  112. #[derive(Insertable)]
  113. #[diesel(table_name = crate::schema::comments)]
  114. pub struct NewComment {
  115. pub content: String,
  116. pub parent: Option<i64>,
  117. pub telegram_handle: String,
  118. pub issue_id: i32,
  119. pub created_at: NaiveDateTime
  120. }
  121. #[derive(Queryable, Selectable, Serialize, Clone)]
  122. #[diesel(table_name = crate::schema::comment_votes)]
  123. #[diesel(check_for_backend(diesel::pg::Pg))]
  124. pub struct CommentVote {
  125. pub id: i64,
  126. pub positive: Option<bool>,
  127. pub comment_id: i64,
  128. pub user_id: i64,
  129. }
  130. #[derive(Insertable)]
  131. #[diesel(table_name = crate::schema::comment_votes)]
  132. pub struct NewCommentVote {
  133. pub positive: Option<bool>,
  134. pub comment_id: Option<i64>,
  135. pub user_id: Option<i64>,
  136. }