fix: delete redundant meili adapter
This commit is contained in:
parent
7fd781b03d
commit
d8d026b057
2 changed files with 0 additions and 117 deletions
|
@ -1,98 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use derive_builder::Builder;
|
||||
use derive_getters::Getters;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::InventoryFTSMeili;
|
||||
use crate::inventory::application::port::output::full_text_search::{
|
||||
add_product_to_store::*, errors::*,
|
||||
};
|
||||
use crate::inventory::domain::{category_aggregate::*, product_aggregate::*};
|
||||
use crate::types::currency::*;
|
||||
//use super::errors::*;
|
||||
|
||||
#[derive(
|
||||
Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||
)]
|
||||
pub struct MeiliProduct {
|
||||
name: String,
|
||||
description: Option<String>,
|
||||
image: Option<String>, // string = file_name
|
||||
price: Price,
|
||||
category_name: String,
|
||||
product_id: Uuid,
|
||||
}
|
||||
|
||||
impl MeiliProduct {
|
||||
pub fn new(product: &Product, category: &Category) -> Self {
|
||||
Self {
|
||||
name: product.name().into(),
|
||||
description: product.description().clone(),
|
||||
image: product.image().clone(),
|
||||
price: product.price().clone(),
|
||||
category_name: category.name().into(),
|
||||
product_id: *product.product_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AddProductToStoreFTSPort for InventoryFTSMeili {
|
||||
async fn add_product_to_store(
|
||||
&self,
|
||||
product: &Product,
|
||||
category: &Category,
|
||||
) -> InventoryFTSResult<()> {
|
||||
let store_index = self.client.index(format!("inventory.{}",category.store_id()));
|
||||
let meili_product = MeiliProduct::new(product, category);
|
||||
store_index
|
||||
.add_documents(&[meili_product], Some("product_id"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::types::quantity::Quantity;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_meili() {
|
||||
let settings = crate::settings::tests::get_settings().await;
|
||||
let fts = InventoryFTSMeili::new(&settings.meili.url, &settings.meili.api_key);
|
||||
|
||||
let category = Category::default();
|
||||
let product = ProductBuilder::default()
|
||||
.name("test_meili_product".into())
|
||||
.description(Some("this is a test product".into()))
|
||||
.image(None)
|
||||
.price(
|
||||
PriceBuilder::default()
|
||||
.major(100)
|
||||
.minor(0)
|
||||
.currency(Currency::INR)
|
||||
.build()
|
||||
.unwrap(),
|
||||
)
|
||||
.quantity(Quantity::default())
|
||||
.sku_able(false)
|
||||
.deleted(false)
|
||||
.category_id(*category.category_id())
|
||||
.product_id(Uuid::new_v4())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
fts.add_product_to_store(&product, &category).await.unwrap();
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use meilisearch_sdk::client::*;
|
||||
|
||||
mod add_product_to_store;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InventoryFTSMeili {
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl InventoryFTSMeili {
|
||||
pub fn new(meili_url: &str, api_key: &str) -> Self {
|
||||
let client = Client::new(meili_url, Some(api_key)).unwrap();
|
||||
Self { client }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue