mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 14:31:05 +00:00
feat: session & admin session fk not null
This commit is contained in:
parent
670c790f0f
commit
d0290155c5
10 changed files with 18 additions and 18 deletions
|
|
@ -13,7 +13,7 @@ impl Mutation {
|
|||
) -> Result<admin_session::Model, DbErr> {
|
||||
admin_session::ActiveModel {
|
||||
id: Set(random_uuid),
|
||||
admin_id: Set(Some(admin_id)),
|
||||
admin_id: Set(admin_id),
|
||||
ip_address: Set(ip_addr),
|
||||
created_at: Set(Utc::now().naive_local()),
|
||||
expires_at: Set(Utc::now()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ impl Mutation {
|
|||
) -> Result<session::Model, DbErr> {
|
||||
session::ActiveModel {
|
||||
id: Set(random_uuid),
|
||||
candidate_id: Set(Some(candidate_id)),
|
||||
candidate_id: Set(candidate_id),
|
||||
ip_address: Set(ip_addr),
|
||||
created_at: Set(Utc::now().naive_local()),
|
||||
expires_at: Set(Utc::now()
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ mod tests {
|
|||
|
||||
session::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
candidate_id: Set(Some(application.id)),
|
||||
candidate_id: Set(application.id),
|
||||
ip_address: Set("10.10.10.10".to_string()),
|
||||
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
expires_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
|
|
@ -104,7 +104,7 @@ mod tests {
|
|||
|
||||
admin_session::ActiveModel {
|
||||
id: Set(Uuid::new_v4()),
|
||||
admin_id: Set(Some(ADMIN_ID)),
|
||||
admin_id: Set(ADMIN_ID),
|
||||
ip_address: Set("10.10.10.10".to_string()),
|
||||
created_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
expires_at: Set(chrono::offset::Local::now().naive_local()),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ impl AuthenticableTrait for AdminService {
|
|||
return Err(ServiceError::ExpiredSession);
|
||||
}
|
||||
|
||||
let admin = Query::find_admin_by_id(db, session.admin_id.unwrap())
|
||||
let admin = Query::find_admin_by_id(db, session.admin_id)
|
||||
.await?
|
||||
.ok_or(ServiceError::CandidateNotFound)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ impl AuthenticableTrait for ApplicationService {
|
|||
|
||||
Self::extend_session_duration_to_14_days(db, session.clone()).await?;
|
||||
|
||||
let application = Query::find_application_by_id(db, session.candidate_id.unwrap())
|
||||
let application = Query::find_application_by_id(db, session.candidate_id)
|
||||
.await?
|
||||
.ok_or(ServiceError::CandidateNotFound)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::session_trait::UserSession;
|
|||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub admin_id: Option<i32>,
|
||||
pub admin_id: i32,
|
||||
pub ip_address: String,
|
||||
pub created_at: DateTime,
|
||||
pub expires_at: DateTime,
|
||||
|
|
|
|||
|
|
@ -27,16 +27,10 @@ pub struct Model {
|
|||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::parent::Entity")]
|
||||
Parent,
|
||||
#[sea_orm(has_many = "super::application::Entity")]
|
||||
Application,
|
||||
}
|
||||
|
||||
impl Related<super::parent::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Parent.def()
|
||||
}
|
||||
#[sea_orm(has_many = "super::parent::Entity")]
|
||||
Parent,
|
||||
}
|
||||
|
||||
impl Related<super::application::Entity> for Entity {
|
||||
|
|
@ -45,4 +39,10 @@ impl Related<super::application::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::parent::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Parent.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::session_trait::UserSession;
|
|||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub candidate_id: Option<i32>,
|
||||
pub candidate_id: i32,
|
||||
pub ip_address: String,
|
||||
pub created_at: DateTime,
|
||||
pub expires_at: DateTime,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl MigrationTrait for Migration {
|
|||
.unique_key()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Session::CandidateId).integer())
|
||||
.col(ColumnDef::new(Session::CandidateId).integer().not_null())
|
||||
.col(ColumnDef::new(Session::IpAddress).string().not_null())
|
||||
.col(ColumnDef::new(Session::CreatedAt).date_time().not_null())
|
||||
.col(ColumnDef::new(Session::ExpiresAt).date_time().not_null())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl MigrationTrait for Migration {
|
|||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(AdminSession::AdminId).integer())
|
||||
.col(ColumnDef::new(AdminSession::AdminId).integer().not_null())
|
||||
.col(ColumnDef::new(AdminSession::IpAddress).string().not_null())
|
||||
.col(ColumnDef::new(AdminSession::CreatedAt).date_time().not_null())
|
||||
.col(ColumnDef::new(AdminSession::ExpiresAt).date_time().not_null())
|
||||
|
|
|
|||
Loading…
Reference in a new issue