def shop_buy(data: dict, user: str): products: Dict[str, int] = data["products"] wallet_uuid: str = data["wallet_uuid"] key: str = data["key"] for product in products: if product not in game_info["items"]: return item_not_found if not exists_wallet(wallet_uuid): return wallet_not_found bought_products: List[dict] = [] price: int = 0 for product, quantity in products.items(): price += game_info["items"][product]["price"] * quantity if price > 0: response: dict = pay_shop(wallet_uuid, key, price, products) if "error" in response: return response for product, quantity in products.items(): for _ in range(quantity): item: Inventory = Inventory.create( product, user, game_info["items"][product]["related_ms"]) bought_products.append(item.serialize) return {"bought_products": bought_products}
def create(data: dict, microservice: str) -> dict: name: str = data["item_name"] if name not in game_info["items"]: return item_not_found item: Inventory = Inventory.create(name, data["owner"], data["related_ms"]) return item.serialize
def add_inventory(cls, payload: inventory.InventoryPost, db: Session): """create a new inventory""" # check inventory title exists # if Inventory.check_title_exists(title=payload.title, db=db): # raise HTTPException(status_code=409, detail="the inventory already exists") try: # add the inventory record = Inventory(public_id=str(uuid.uuid4()), title=payload.title.strip().title(), isbn_no=payload.isbn_no, buying_price=payload.buying_price, selling_price=payload.selling_price, uid=payload.uid) created_record = record.create(db=db) send_log_to_queue('Successfully Save Inventory Record') return created_record except Exception as e: send_log_to_queue('Failed Save Inventory') raise HTTPException(status_code=500, detail='Server Error')