move to rocket + refactor
This commit is contained in:
parent
b0e80dd3e8
commit
b8caa43972
11 changed files with 686 additions and 886 deletions
|
@ -34,8 +34,7 @@ impl Variant {
|
|||
.as_mapping()
|
||||
.unwrap()
|
||||
.get("amount")
|
||||
.map(|x| x.as_u64().unwrap())
|
||||
.unwrap_or(1),
|
||||
.map_or(1, |x| x.as_u64().unwrap()),
|
||||
depends: json
|
||||
.as_mapping()
|
||||
.unwrap()
|
||||
|
@ -43,11 +42,11 @@ impl Variant {
|
|||
.map(|x| {
|
||||
x.as_sequence()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|x| x.as_str().unwrap().to_string())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or(Vec::new()),
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,14 +103,10 @@ impl Variant {
|
|||
|
||||
// check if supply transaction exists
|
||||
let supply_t = cdb_col!(db, "supply");
|
||||
if supply_t
|
||||
.find_one(doc! { "_id": uuid }, None)
|
||||
supply_t
|
||||
.find_one(doc! { "_id": uuid}, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
.unwrap()?;
|
||||
|
||||
// todo : demand batch
|
||||
|
||||
|
@ -122,7 +117,7 @@ impl Variant {
|
|||
doc! {
|
||||
"_id": uuid,
|
||||
"destination": destination,
|
||||
"price": price.as_bson()
|
||||
"price": Into::<mongodb::bson::Bson>::into(price)
|
||||
},
|
||||
None,
|
||||
)
|
||||
|
@ -163,7 +158,7 @@ impl Variant {
|
|||
}
|
||||
|
||||
for transaction in &transactions {
|
||||
let r = col.insert_one(transaction.as_doc(), None).await.unwrap();
|
||||
col.insert_one(transaction.as_doc(), None).await.unwrap();
|
||||
|
||||
// update cache
|
||||
InventoryCache::push(&transaction.uuid).await;
|
||||
|
@ -177,8 +172,12 @@ impl Variant {
|
|||
BatchTransaction::new(transactions.iter().map(|x| x.uuid.clone()).collect());
|
||||
let col: mongodb::Collection<mongodb::bson::Document> =
|
||||
db.database("cdb").collection("transactions_batch");
|
||||
col.insert_one(batch.as_doc(), None).await.unwrap();
|
||||
batch.uuid
|
||||
let batch_uuid = batch.uuid.clone();
|
||||
|
||||
col.insert_one(Into::<mongodb::bson::Document>::into(batch), None)
|
||||
.await
|
||||
.unwrap();
|
||||
batch_uuid
|
||||
};
|
||||
|
||||
ret_uuid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue