Skip to content

Commit

Permalink
chore:consume date update
Browse files Browse the repository at this point in the history
  • Loading branch information
jingooo5 committed Nov 2, 2024
1 parent 0d5adba commit f8ec4f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Router/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})


Expand Down
4 changes: 3 additions & 1 deletion Service/useritem_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f8ec4f6

Please sign in to comment.