Skip to content

Commit

Permalink
Add approval status to submissions
Browse files Browse the repository at this point in the history
Adds a new column to containt the approval status of a submission.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho committed Jan 8, 2024
1 parent e936566 commit e828431
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions entity/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod infrastructure;
pub mod opportunity;
pub mod ranking;
pub mod recreation;
pub mod sea_orm_active_enums;
pub mod speed_limit;
pub mod submission;
pub mod summary;
15 changes: 15 additions & 0 deletions entity/src/entities/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "approval_status")]
pub enum ApprovalStatus {
#[sea_orm(string_value = "Approved")]
Approved,
#[sea_orm(string_value = "Pending")]
Pending,
#[sea_orm(string_value = "Rejected")]
Rejected,
}
2 changes: 2 additions & 0 deletions entity/src/entities/submission.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
use super::sea_orm_active_enums::ApprovalStatus;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

Expand All @@ -18,6 +19,7 @@ pub struct Model {
pub region: Option<String>,
pub fips_code: String,
pub consent: bool,
pub status: Option<ApprovalStatus>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
9 changes: 9 additions & 0 deletions entity/src/wrappers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::entities::sea_orm_active_enums::ApprovalStatus;
use crate::entities::submission;
use sea_orm::{ActiveValue, IntoActiveModel};
use serde::{Deserialize, Serialize};
Expand All @@ -14,6 +15,7 @@ pub struct Submission {
pub region: Option<String>,
pub fips_code: String,
pub consent: bool,
pub status: Option<ApprovalStatus>,
}

impl IntoActiveModel<submission::ActiveModel> for Submission {
Expand All @@ -30,6 +32,7 @@ impl IntoActiveModel<submission::ActiveModel> for Submission {
region: ActiveValue::Set(self.region),
fips_code: ActiveValue::Set(self.fips_code),
consent: ActiveValue::Set(self.consent),
status: ActiveValue::Set(self.status),
}
}
}
Expand All @@ -50,6 +53,7 @@ mod tests {
let region = Some("texas".to_string());
let fips_code = "0123456".to_string();
let consent = true;
let status = Some(ApprovalStatus::Pending);
let wrapper = Submission {
first_name: first_name.clone(),
last_name: last_name.clone(),
Expand All @@ -61,6 +65,7 @@ mod tests {
region: region.clone(),
fips_code: fips_code.clone(),
consent,
status: status.clone(),
};
let active_model = wrapper.into_active_model();
let expected = submission::ActiveModel {
Expand All @@ -75,6 +80,7 @@ mod tests {
region: ActiveValue::Set(region),
fips_code: ActiveValue::Set(fips_code),
consent: ActiveValue::Set(consent),
status: ActiveValue::Set(status),
};
assert_eq!(active_model, expected);
}
Expand All @@ -91,6 +97,7 @@ mod tests {
let region = None;
let fips_code = "0123456".to_string();
let consent = true;
let status = Some(ApprovalStatus::Pending);
let wrapper = Submission {
first_name: first_name.clone(),
last_name: last_name.clone(),
Expand All @@ -102,6 +109,7 @@ mod tests {
region: region.clone(),
fips_code: fips_code.clone(),
consent,
status: status.clone(),
};
let active_model = wrapper.into_active_model();
let expected = submission::ActiveModel {
Expand All @@ -116,6 +124,7 @@ mod tests {
region: ActiveValue::Set(region),
fips_code: ActiveValue::Set(fips_code),
consent: ActiveValue::Set(consent),
status: ActiveValue::Set(status),
};
assert_eq!(active_model, expected);
}
Expand Down
35 changes: 33 additions & 2 deletions migration/src/m20231010_232527_city_submission.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use sea_orm_migration::prelude::*;
use sea_orm::{EnumIter, Iterable};
use sea_orm_migration::{prelude::*, sea_query::extension::postgres::Type};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Create the approval status type.
manager
.create_type(
Type::create()
.as_enum(ApprovalStatus::Table)
.values(ApprovalStatus::iter().skip(1))
.to_owned(),
)
.await?;

// Create the Submission table.
manager
.create_table(
Table::create()
Expand Down Expand Up @@ -33,9 +45,16 @@ impl MigrationTrait for Migration {
.default("0"),
)
.col(ColumnDef::new(Submission::Consent).boolean().not_null())
.col(
ColumnDef::new(Submission::Status)
.enumeration(ApprovalStatus::Table, ApprovalStatus::iter().skip(1))
.default(ApprovalStatus::Pending.to_string()),
)
.to_owned(),
)
.await
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Expand All @@ -59,4 +78,16 @@ enum Submission {
Region,
FIPSCode,
Consent,
Status,
}

#[derive(Iden, EnumIter)]
pub enum ApprovalStatus {
Table,
#[iden = "Pending"]
Pending,
#[iden = "Approved"]
Approved,
#[iden = "Rejected"]
Rejected,
}

0 comments on commit e828431

Please sign in to comment.