Skip to content

Commit

Permalink
feat: session & admin session fk not null
Browse files Browse the repository at this point in the history
  • Loading branch information
starvy committed Jan 15, 2023
1 parent 670c790 commit d029015
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/database/mutation/admin_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion core/src/database/mutation/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions core/src/database/query/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/admin_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/application_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/admin_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions entity/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ 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,
#[sea_orm(has_many = "super::parent::Entity")]
Parent,
}

impl Related<super::parent::Entity> for Entity {
impl Related<super::application::Entity> for Entity {
fn to() -> RelationDef {
Relation::Parent.def()
Relation::Application.def()
}
}

impl Related<super::application::Entity> for Entity {
impl Related<super::parent::Entity> for Entity {
fn to() -> RelationDef {
Relation::Application.def()
Relation::Parent.def()
}
}

Expand Down
2 changes: 1 addition & 1 deletion entity/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion migration/src/m20221025_154422_create_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion migration/src/m20221221_162232_create_admin_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit d029015

Please sign in to comment.