review: avoid using class in entity construction relying on T and EAV trait
This commit is contained in:
@@ -27,8 +27,11 @@ impl O {
|
||||
self.id = id.to_string();
|
||||
self
|
||||
}
|
||||
pub fn with_class(mut self, class: &str) -> Self {
|
||||
self.class = class.to_string();
|
||||
pub fn with_class<T>(mut self) -> Self
|
||||
where
|
||||
T: EAV,
|
||||
{
|
||||
self.class = T::class().to_string();
|
||||
self
|
||||
}
|
||||
pub fn with_ref_date(mut self, ref_date: u64) -> Self {
|
||||
|
||||
@@ -15,7 +15,7 @@ mod tests {
|
||||
impl From<Product> for Entity {
|
||||
fn from(value: Product) -> Entity {
|
||||
Entity::default()
|
||||
.with_class("product")
|
||||
.with_class::<Product>()
|
||||
.with_id(&value.id)
|
||||
.with_attribute("name", value.name)
|
||||
.with_attribute("price", value.price)
|
||||
|
||||
@@ -19,7 +19,7 @@ mod tests {
|
||||
impl From<OperationToCategory> for Entity {
|
||||
fn from(value: OperationToCategory) -> Entity {
|
||||
Entity::default()
|
||||
.with_class("operation_has_category")
|
||||
.with_class::<OperationToCategory>()
|
||||
.with_id(&value.id)
|
||||
.with_attribute("operation_id", value.operation_id)
|
||||
.with_attribute("category_id", value.category_id)
|
||||
@@ -49,7 +49,7 @@ mod tests {
|
||||
impl From<Category> for Entity {
|
||||
fn from(value: Category) -> Entity {
|
||||
Entity::default()
|
||||
.with_class("category")
|
||||
.with_class::<Category>()
|
||||
.with_id(&value.id)
|
||||
.with_attribute("label", value.label)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ mod tests {
|
||||
impl From<Operation> for Entity {
|
||||
fn from(value: Operation) -> Entity {
|
||||
Entity::default()
|
||||
.with_class("operation")
|
||||
.with_class::<Operation>()
|
||||
.with_id(&value.id)
|
||||
.with_attribute("date", value.date)
|
||||
.with_attribute("amount", value.amount)
|
||||
|
||||
Reference in New Issue
Block a user