Skip to content

Commit 89c18d2

Browse files
committed
Make sure a new Organization can accept the field and also ensure slug's value is unique.
1 parent 2ba33d3 commit 89c18d2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

entity/src/organizations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Model {
1515
#[sea_orm(unique)]
1616
pub name: String,
1717
pub logo: Option<String>,
18-
#[serde(skip_deserializing)]
18+
#[sea_orm(unique)]
1919
pub slug: String,
2020
#[serde(skip_deserializing)]
2121
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema

entity_api/src/organization.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ pub async fn create(db: &DatabaseConnection, organization_model: Model) -> Resul
1919
let now = Utc::now();
2020

2121
let organization_active_model: ActiveModel = ActiveModel {
22-
logo: Set(organization_model.logo),
2322
name: Set(organization_model.name),
23+
logo: Set(organization_model.logo),
24+
slug: Set(organization_model.slug),
2425
created_at: Set(now.into()),
2526
updated_at: Set(now.into()),
2627
..Default::default()
@@ -34,9 +35,9 @@ pub async fn update(db: &DatabaseConnection, id: Id, model: Model) -> Result<Mod
3435

3536
let active_model: ActiveModel = ActiveModel {
3637
id: Unchanged(organization.id),
37-
logo: Set(model.logo),
3838
name: Set(model.name),
39-
slug: Unchanged(organization.slug),
39+
logo: Set(model.logo),
40+
slug: Set(organization.slug),
4041
updated_at: Unchanged(organization.updated_at),
4142
created_at: Unchanged(organization.created_at),
4243
};

0 commit comments

Comments
 (0)