Change Over to new derive
This commit is contained in:
		
							parent
							
								
									771be89260
								
							
						
					
					
						commit
						6252ec87b9
					
				| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "awards")]
 | 
			
		||||
pub struct Award {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -12,11 +14,6 @@ pub struct Award {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Award {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "awards";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Award {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			@ -42,25 +39,4 @@ impl Award {
 | 
			
		|||
            .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
 | 
			
		||||
        let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Award,
 | 
			
		||||
            r#"
 | 
			
		||||
                UPDATE awards SET 
 | 
			
		||||
                name = $2,
 | 
			
		||||
                description = $3,
 | 
			
		||||
                modified_at = $4
 | 
			
		||||
                WHERE id = $1
 | 
			
		||||
                RETURNING *
 | 
			
		||||
                "#,
 | 
			
		||||
            self.id,
 | 
			
		||||
            self.name,
 | 
			
		||||
            self.description,
 | 
			
		||||
            curr_time
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "missions")]
 | 
			
		||||
pub struct Mission {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -14,11 +16,6 @@ pub struct Mission {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Mission {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "missions";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Mission {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			@ -44,25 +41,4 @@ impl Mission {
 | 
			
		|||
            .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
 | 
			
		||||
        let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Mission,
 | 
			
		||||
            r#"
 | 
			
		||||
                UPDATE missions SET 
 | 
			
		||||
                name = $2,
 | 
			
		||||
                description = $3,
 | 
			
		||||
                modified_at = $4
 | 
			
		||||
                WHERE id = $1
 | 
			
		||||
                RETURNING *
 | 
			
		||||
                "#,
 | 
			
		||||
            self.id,
 | 
			
		||||
            self.name,
 | 
			
		||||
            self.description,
 | 
			
		||||
            curr_time
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "qualifications")]
 | 
			
		||||
pub struct Qualification {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -12,11 +14,6 @@ pub struct Qualification {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Qualification {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "qualifications";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Qualification {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			@ -46,25 +43,4 @@ impl Qualification {
 | 
			
		|||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
 | 
			
		||||
        let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Qualification,
 | 
			
		||||
            r#"
 | 
			
		||||
                UPDATE qualifications SET 
 | 
			
		||||
                name = $2,
 | 
			
		||||
                description = $3,
 | 
			
		||||
                modified_at = $4
 | 
			
		||||
                WHERE id = $1
 | 
			
		||||
                RETURNING *
 | 
			
		||||
                "#,
 | 
			
		||||
            self.id,
 | 
			
		||||
            self.name,
 | 
			
		||||
            self.description,
 | 
			
		||||
            curr_time
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "ranks")]
 | 
			
		||||
pub struct Rank {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -12,11 +14,6 @@ pub struct Rank {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Rank {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "ranks";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Rank {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			@ -42,25 +39,4 @@ impl Rank {
 | 
			
		|||
            .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
 | 
			
		||||
        let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Rank,
 | 
			
		||||
            r#"
 | 
			
		||||
                UPDATE ranks SET 
 | 
			
		||||
                name = $2,
 | 
			
		||||
                description = $3,
 | 
			
		||||
                modified_at = $4
 | 
			
		||||
                WHERE id = $1
 | 
			
		||||
                RETURNING *
 | 
			
		||||
                "#,
 | 
			
		||||
            self.id,
 | 
			
		||||
            self.name,
 | 
			
		||||
            self.description,
 | 
			
		||||
            curr_time
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "trainings")]
 | 
			
		||||
pub struct Training {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -12,11 +14,6 @@ pub struct Training {
 | 
			
		|||
    pub modified_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Training {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "trainings";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Training {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			@ -42,25 +39,4 @@ impl Training {
 | 
			
		|||
            .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
 | 
			
		||||
        let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Training,
 | 
			
		||||
            r#"
 | 
			
		||||
                UPDATE trainings SET 
 | 
			
		||||
                name = $2,
 | 
			
		||||
                description = $3,
 | 
			
		||||
                modified_at = $4
 | 
			
		||||
                WHERE id = $1
 | 
			
		||||
                RETURNING *
 | 
			
		||||
                "#,
 | 
			
		||||
            self.id,
 | 
			
		||||
            self.name,
 | 
			
		||||
            self.description,
 | 
			
		||||
            curr_time
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										53
									
								
								src/db/tables/groups.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/db/tables/groups.rs
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,53 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
    CurrPool,
 | 
			
		||||
    tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "roster_groups")]
 | 
			
		||||
pub struct Groups {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub name: String,
 | 
			
		||||
    pub manager_id: ForeignKey<User>,
 | 
			
		||||
    pub sort_order: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Groups {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Groups,
 | 
			
		||||
            r#"
 | 
			
		||||
                INSERT INTO roster_groups (name, manager_id, sort_order)
 | 
			
		||||
                VALUES ($1, $2, $3)
 | 
			
		||||
                RETURNING *
 | 
			
		||||
            "#,
 | 
			
		||||
            self.name,
 | 
			
		||||
            *self.manager_id,
 | 
			
		||||
            self.sort_order,
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_one(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(Groups, "SELECT * FROM roster_groups WHERE id = $1", id)
 | 
			
		||||
            .fetch_one(pool)
 | 
			
		||||
            .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
    pub async fn get_by_manager_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
            Groups,
 | 
			
		||||
            "SELECT * FROM roster_groups WHERE manager_id = $1",
 | 
			
		||||
            id
 | 
			
		||||
        )
 | 
			
		||||
        .fetch_all(pool)
 | 
			
		||||
        .await?;
 | 
			
		||||
        Ok(session)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ use sqlx::{Decode, Encode, QueryBuilder, Type, postgres::PgRow};
 | 
			
		|||
 | 
			
		||||
pub mod assignables;
 | 
			
		||||
pub mod attendance;
 | 
			
		||||
pub mod groups;
 | 
			
		||||
pub mod records;
 | 
			
		||||
pub mod sessions;
 | 
			
		||||
pub mod user;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,8 @@ use crate::db::{
 | 
			
		|||
    tables::{ForeignKey, TableMeta, assignables::awards::Award, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "records_awards")]
 | 
			
		||||
pub struct AwardRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
| 
						 | 
				
			
			@ -15,11 +17,6 @@ pub struct AwardRecord {
 | 
			
		|||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for AwardRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_awards";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl AwardRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,8 @@ use crate::db::{
 | 
			
		|||
    tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "records_missions")]
 | 
			
		||||
pub struct MissionRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
| 
						 | 
				
			
			@ -15,11 +17,6 @@ pub struct MissionRecord {
 | 
			
		|||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for MissionRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_missions";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl MissionRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,8 @@ use crate::db::{
 | 
			
		|||
    tables::{ForeignKey, TableMeta, assignables::qualifications::Qualification, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "records_qualifications")]
 | 
			
		||||
pub struct QualificationRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
| 
						 | 
				
			
			@ -15,11 +17,6 @@ pub struct QualificationRecord {
 | 
			
		|||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for QualificationRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_qualifications";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl QualificationRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,8 @@ use crate::db::{
 | 
			
		|||
    tables::{ForeignKey, TableMeta, assignables::ranks::Rank, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "records_ranks")]
 | 
			
		||||
pub struct RankRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
| 
						 | 
				
			
			@ -15,11 +17,6 @@ pub struct RankRecord {
 | 
			
		|||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for RankRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_ranks";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl RankRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{
 | 
			
		||||
| 
						 | 
				
			
			@ -6,7 +7,8 @@ use crate::db::{
 | 
			
		|||
    tables::{ForeignKey, TableMeta, assignables::trainings::Training, user::User},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "records_trainings")]
 | 
			
		||||
pub struct TrainingRecord {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: ForeignKey<User>,
 | 
			
		||||
| 
						 | 
				
			
			@ -15,11 +17,6 @@ pub struct TrainingRecord {
 | 
			
		|||
    pub created_at: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for TrainingRecord {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "records_trainings";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TrainingRecord {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,20 +1,18 @@
 | 
			
		|||
use anyhow::Result;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "sessions")]
 | 
			
		||||
pub struct Session {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub user_id: i64,
 | 
			
		||||
    pub session_key: String,
 | 
			
		||||
    pub expires: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for Session {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "sessions";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Session {
 | 
			
		||||
    pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
 | 
			
		||||
        let session = sqlx::query_as!(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,13 @@
 | 
			
		|||
use anyhow::bail;
 | 
			
		||||
use persmgr_derive::TableMeta;
 | 
			
		||||
use sqlx::prelude::FromRow;
 | 
			
		||||
 | 
			
		||||
use crate::db::{CurrPool, tables::TableMeta};
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow)]
 | 
			
		||||
use crate::db::{
 | 
			
		||||
    CurrPool,
 | 
			
		||||
    tables::{ForeignKey, TableMeta, assignables::ranks::Rank, groups::Groups},
 | 
			
		||||
};
 | 
			
		||||
#[derive(Debug, Default, Clone, FromRow, TableMeta)]
 | 
			
		||||
#[meta(table = "users")]
 | 
			
		||||
pub struct User {
 | 
			
		||||
    pub id: i64,
 | 
			
		||||
    pub email: String,
 | 
			
		||||
| 
						 | 
				
			
			@ -11,12 +16,8 @@ pub struct User {
 | 
			
		|||
    pub pw_hash: String,
 | 
			
		||||
    pub pw_salt: String,
 | 
			
		||||
    pub pfp_id: i64,
 | 
			
		||||
    pub rank_id: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TableMeta for User {
 | 
			
		||||
    type PrimaryKey = i64;
 | 
			
		||||
    const TABLE: &'static str = "users";
 | 
			
		||||
    pub rank_id: ForeignKey<Rank>,
 | 
			
		||||
    pub group_id: ForeignKey<Groups>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl User {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user