Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize just the right fields when creating new entities #79

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions entity/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ pub struct Model {
#[serde(skip_deserializing)]
pub status_changed_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}

Expand Down
3 changes: 3 additions & 0 deletions entity/src/coachees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use utoipa::ToSchema;
#[schema(as = entity::users::Model)] // OpenAPI schema
#[sea_orm(schema_name = "refactor_platform", table_name = "users")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
Expand All @@ -18,8 +19,10 @@ pub struct Model {
pub password: String,
pub github_username: Option<String>,
pub github_profile_url: Option<String>,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}
Expand Down
3 changes: 3 additions & 0 deletions entity/src/coaches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use utoipa::ToSchema;
#[schema(as = entity::users::Model)] // OpenAPI schema
#[sea_orm(schema_name = "refactor_platform", table_name = "users")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
Expand All @@ -18,8 +19,10 @@ pub struct Model {
pub password: String,
pub github_username: Option<String>,
pub github_profile_url: Option<String>,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}
Expand Down
3 changes: 3 additions & 0 deletions entity/src/coaching_relationships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ use utoipa::ToSchema;
table_name = "coaching_relationships"
)]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
pub organization_id: Id,
pub coach_id: Id,
pub coachee_id: Id,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}
Expand Down
5 changes: 5 additions & 0 deletions entity/src/coaching_sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ use utoipa::ToSchema;
#[schema(as = entity::coaching_sessions::Model)]
#[sea_orm(schema_name = "refactor_platform", table_name = "coaching_sessions")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
pub coaching_relationship_id: Id,
pub date: DateTime,
pub timezone: String,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}

Expand Down
3 changes: 3 additions & 0 deletions entity/src/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ use utoipa::ToSchema;
#[schema(as = entity::organizations::Model)] // OpenAPI schema
#[sea_orm(schema_name = "refactor_platform", table_name = "organizations")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
pub name: String,
pub logo: Option<String>,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}
Expand Down
5 changes: 4 additions & 1 deletion entity/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ use utoipa::ToSchema;
#[schema(as = entity::users::Model)] // OpenAPI schema
#[sea_orm(schema_name = "refactor_platform", table_name = "users")]
pub struct Model {
#[serde(skip_deserializing)]
#[sea_orm(primary_key)]
pub id: Id,
#[sea_orm(unique)]
pub email: String,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub display_name: Option<String>,
#[serde(skip)]
#[serde(skip_serializing)]
pub password: String,
pub github_username: Option<String>,
pub github_profile_url: Option<String>,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub created_at: DateTimeWithTimeZone,
#[serde(skip_deserializing)]
#[schema(value_type = String, format = DateTime)] // Applies to OpenAPI schema
pub updated_at: DateTimeWithTimeZone,
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/controller/user_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use service::config::ApiVersion;

use log::*;

/// CREATE a new User.
/// CREATE a new User
#[utoipa::path(
post,
path = "/users",
Expand All @@ -16,7 +16,7 @@ use log::*;
),
request_body = entity::users::Model,
responses(
(status = 200, description = "Successfully created a new Coaching Relationship", body = [entity::users::Model]),
(status = 200, description = "Successfully created a new User", body = [entity::users::Model]),
(status = 401, description = "Unauthorized"),
(status = 405, description = "Method not allowed")
),
Expand Down