Can create a family
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use crate::schema::users;
|
||||
use crate::schema::{families, memberships, users};
|
||||
use diesel::prelude::*;
|
||||
|
||||
/// User ID holder
|
||||
@ -51,3 +51,46 @@ pub struct NewUser<'a> {
|
||||
pub email: &'a str,
|
||||
pub time_create: i64,
|
||||
}
|
||||
|
||||
/// Family ID holder
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
|
||||
pub struct FamilyID(pub i32);
|
||||
|
||||
#[derive(Queryable, Debug, serde::Serialize)]
|
||||
pub struct Family {
|
||||
pub id: i32,
|
||||
pub time_create: i64,
|
||||
pub name: String,
|
||||
pub invitation_code: String,
|
||||
}
|
||||
|
||||
impl Family {
|
||||
pub fn id(&self) -> FamilyID {
|
||||
FamilyID(self.id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = families)]
|
||||
pub struct NewFamily<'a> {
|
||||
pub name: &'a str,
|
||||
pub invitation_code: String,
|
||||
pub time_create: i64,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, serde::Serialize)]
|
||||
pub struct Membership {
|
||||
user_id: i32,
|
||||
family_id: i32,
|
||||
time_create: i64,
|
||||
is_admin: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = memberships)]
|
||||
pub struct NewMembership {
|
||||
pub user_id: i32,
|
||||
pub family_id: i32,
|
||||
pub time_create: i64,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
|
Reference in New Issue
Block a user