Skip to content

Commit

Permalink
^ generate_common_bmc_fns allows you to choose which CRUD functions i…
Browse files Browse the repository at this point in the history
…t will implement.
  • Loading branch information
jeremychone committed Feb 1, 2024
1 parent c63a597 commit f4b7aaa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 50 deletions.
2 changes: 1 addition & 1 deletion crates/libs/lib-core/src/model/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ generate_common_bmc_fns!(
Entity: Agent,
ForCreate: AgentForCreate,
ForUpdate: AgentForUpdate,
Filter: AgentFilter
Filter: AgentFilter,
);

// endregion: --- AgentBmc
Expand Down
102 changes: 54 additions & 48 deletions crates/libs/lib-core/src/model/base/macro_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,67 @@ macro_rules! generate_common_bmc_fns {
(
Bmc: $struct_name:ident,
Entity: $entity:ty,
ForCreate: $for_create:ty,
ForUpdate: $for_update:ty,
Filter: $filter:ty
$(ForCreate: $for_create:ty,)?
$(ForUpdate: $for_update:ty,)?
$(Filter: $filter:ty,)?
) => {
impl $struct_name {
pub async fn create(
ctx: &Ctx,
mm: &ModelManager,
entity_c: $for_create,
) -> Result<i64> {
base::create::<Self, _>(ctx, mm, entity_c).await
}
$(
pub async fn create(
ctx: &Ctx,
mm: &ModelManager,
entity_c: $for_create,
) -> Result<i64> {
base::create::<Self, _>(ctx, mm, entity_c).await
}
)?

pub async fn get(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
) -> Result<$entity> {
base::get::<Self, _>(ctx, mm, id).await
}
pub async fn get(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
) -> Result<$entity> {
base::get::<Self, _>(ctx, mm, id).await
}

pub async fn first(
ctx: &Ctx,
mm: &ModelManager,
filter: Option<Vec<$filter>>,
list_options: Option<ListOptions>,
) -> Result<Option<$entity>> {
base::first::<Self, _, _>(ctx, mm, filter, list_options).await
}
$(
pub async fn first(
ctx: &Ctx,
mm: &ModelManager,
filter: Option<Vec<$filter>>,
list_options: Option<ListOptions>,
) -> Result<Option<$entity>> {
base::first::<Self, _, _>(ctx, mm, filter, list_options).await
}

pub async fn list(
ctx: &Ctx,
mm: &ModelManager,
filter: Option<Vec<$filter>>,
list_options: Option<ListOptions>,
) -> Result<Vec<$entity>> {
base::list::<Self, _, _>(ctx, mm, filter, list_options).await
}
pub async fn list(
ctx: &Ctx,
mm: &ModelManager,
filter: Option<Vec<$filter>>,
list_options: Option<ListOptions>,
) -> Result<Vec<$entity>> {
base::list::<Self, _, _>(ctx, mm, filter, list_options).await
}
)?

pub async fn update(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
entity_u: $for_update,
) -> Result<()> {
base::update::<Self, _>(ctx, mm, id, entity_u).await
}
$(
pub async fn update(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
entity_u: $for_update,
) -> Result<()> {
base::update::<Self, _>(ctx, mm, id, entity_u).await
}
)?

pub async fn delete(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
) -> Result<()> {
base::delete::<Self>(ctx, mm, id).await
}
pub async fn delete(
ctx: &Ctx,
mm: &ModelManager,
id: i64,
) -> Result<()> {
base::delete::<Self>(ctx, mm, id).await
}
}
};
}
2 changes: 1 addition & 1 deletion crates/libs/lib-core/src/model/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ generate_common_bmc_fns!(
Entity: Conv,
ForCreate: ConvForCreate,
ForUpdate: ConvForUpdate,
Filter: ConvFilter
Filter: ConvFilter,
);

// Additional ConvBmc methods to manage the `ConvMsg` constructs.
Expand Down

0 comments on commit f4b7aaa

Please sign in to comment.