1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
//! Models for user
use rocket::serde::{Deserialize, Serialize};
use uuid::Uuid;
// use crate::pgdb::{self, prelude::*};
use super::{burrow::BurrowMetadata, content::Post};
/// User data
///
/// ## Fields
///
/// - `id`: Uuid, user's uuid
/// - `name`: String, username
#[derive(Serialize, Deserialize)]
pub struct UserData {
pub id: Uuid,
pub name: String,
}
/// User Info
///
/// ## Fields
///
/// - `username`: &str, username
/// - `password`: &str, user's password
/// - `email`: &str, user's email
/// - `verification_code`: &str, verification code
#[derive(Deserialize)]
pub struct UserInfo<'r> {
pub username: &'r str,
pub password: &'r str,
pub email: &'r str,
pub verification_code: &'r str,
}
/// User Reset Info
///
/// ## Fields
///
/// - `password`: &str, user's password
/// - `email`: &str, user's email
/// - `verification_code`: &str, verification code
#[derive(Deserialize)]
pub struct UserResetInfo<'r> {
pub password: &'r str,
pub email: &'r str,
pub verification_code: &'r str,
}
/// Input struct of `user_change_password`
///
/// ## Fields
///
/// - `password`: &str, user's old password
/// - `new_password`: &str, new password
#[derive(Deserialize)]
pub struct UserChangePassword<'r> {
pub password: &'r str,
pub new_password: &'r str,
}
/// User Email
///
/// ## Fields
///
/// - `email`: String, user's email
#[derive(Serialize, Deserialize)]
pub struct UserEmail {
pub email: String,
}
/// User Login Info
///
/// ## Fields
///
/// - `username`: &str, username
/// - `password`: &str, user's password
#[derive(Deserialize)]
pub struct UserLoginInfo<'r> {
pub username: &'r str,
pub password: &'r str,
}
/// Response struct of `user_sign_up`
///
/// ## Fields
///
/// - `default_burrow`: i64, burrow_id of assigned default burrow
#[derive(Serialize, Deserialize)]
pub struct UserResponse {
pub default_burrow: i64,
}
/// Response struct of `get_collection`
///
/// ## Fields
///
/// - `post`: struct Post, information of post
/// - `is_update`: bool, if post is updated since last view
#[derive(Serialize, Deserialize)]
pub struct UserGetCollectionResponse {
pub post: Post,
pub is_update: bool,
}
/// Response struct of `get_follow`
///
/// ## Fields
///
/// - `burrow`: struct BurrowMetadata, information of burrow
/// - `is_update`: bool, if burrow is updated since last view
#[derive(Serialize, Deserialize)]
pub struct UserGetFollowResponse {
pub burrow: BurrowMetadata,
pub is_update: bool,
}
// pub struct UserGetFavResponse {
// pub post_id: i64,
// pub title: String,
// pub tags: String,
// pub burrow_id: i64,
// pub burrow_name: String,
// }
// pub struct GetBatch {}
// impl GetBatch {
// async fn get_post(
// burrow: &pgdb::burrow::Model,
// inner_conn: DatabaseConnection,
// ) -> Result<i64, Box<dyn std::error::Error>> {
// let post_num: i64 = match ContentPost::find()
// .filter(pgdb::content_post::Column::BurrowId.eq(burrow.burrow_id))
// .all(&inner_conn)
// .await
// {
// Ok(posts) => match posts.len().try_into() {
// Ok(n) => n,
// Err(e) => {
// error!("[GET-BURROW] TryInto Error: {:?}", e.to_string());
// -1
// }
// },
// Err(e) => {
// error!("[GET-BURROW] Database Error: {:?}", e.to_string());
// -1
// }
// };
// Ok(post_num)
// }
// }