diff --git a/Router/item.py b/Router/item.py index 7687aad..6138c54 100644 --- a/Router/item.py +++ b/Router/item.py @@ -66,14 +66,14 @@ def get_userItem_all(request : Request, user_id: str, category: str = Query(...) 500: {"description": "실패"} }) def consume_item(request : Request, user_item_consume: UserItemConsume): - result = UserItemService.consume_userItem(user_item_consume) - if result is False: - return JSONResponse(status_code=HTTP_400_BAD_REQUEST, content={"message": "Item consume failed"}) consume_history = ConsumeService.consume_history_db(user_item_consume) ConsumeService.purchase_history_save(consume_history) expectation = ConsumeService.calculate_consume_expectation(user_item_consume.user_id, user_item_consume.item_name) if expectation: ConsumeService.set_consume_expectation(user_item_consume.user_id, user_item_consume.item_name, expectation) + result = UserItemService.consume_userItem(user_item_consume, expectation) + if result is False: + return JSONResponse(status_code=HTTP_400_BAD_REQUEST, content={"message": "Item consume failed"}) return JSONResponse(status_code=HTTP_200_OK, content={"message": "Item consumed successfully"}) diff --git a/Service/useritem_service.py b/Service/useritem_service.py index 01e01f8..66fe600 100644 --- a/Service/useritem_service.py +++ b/Service/useritem_service.py @@ -118,11 +118,13 @@ def add_userItems(itemAdd : ItemAdd): db.commit() return True - def consume_userItem(userItemConsume: UserItemConsume, expectation: Optional[int] = None): + def consume_userItem(userItemConsume: UserItemConsume, expectation: int): with get_db() as db: useritem = db.query(UserItem).filter(UserItem.user_id == userItemConsume.user_id, UserItem.item_name == userItemConsume.item_name).first() if useritem.count - userItemConsume.consume_count < 0: return False useritem.count -= userItemConsume.consume_count + + useritem.consume_date = datetime.now() + timedelta(days=(expectation * useritem.count)) db.commit() return True \ No newline at end of file