Skip to content

Commit

Permalink
fix:filtering items when it's count is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
rocknroll17 committed Nov 2, 2024
1 parent f3746c0 commit 6c30eef
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Router/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def add_items(request: Request, itemadd: ItemAdd):
"""
유저가 보유한 모든 아이템을 가져온다.
"""
# 0개 제외
@router.get("/{user_id}/item", response_model=List[ItemRead])
def get_userItem_all(request : Request, user_id: str):
user_item_list = UserItemService.get_all_userItem(user_id)
Expand All @@ -38,7 +39,7 @@ def get_userItem_all(request : Request, user_id: str):

"""
유저가 아이템 소비
TODO : request body에 아이템 개수 추가
TODO : 소비 기록 추가
"""
@router.post("/consume")
def consume_item(request : Request, user_item_consume: UserItemConsume):
Expand Down
6 changes: 3 additions & 3 deletions Service/useritem_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init_userItem(user_id: str):

def get_all_userItem(user_id: str):
with get_db() as db:
return db.query(UserItem).filter(UserItem.user_id == user_id).all()
return db.query(UserItem).filter(UserItem.user_id == user_id, UserItem.count > 0).all()


def get_all_userItem_filtered_by_date(user_id, year: int, month: int):
Expand Down Expand Up @@ -79,8 +79,8 @@ def add_userItems(itemAdd : ItemAdd):
def consume_userItem(userItemConsume: UserItemConsume):
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.count < 0:
if useritem.count - userItemConsume.consume_count < 0:
return False
useritem.count -= userItemConsume.count
useritem.count -= userItemConsume.consume_count
db.commit()
return True
Empty file removed Utils/product_adder.py
Empty file.
1 change: 0 additions & 1 deletion Utils/product_list.txt

This file was deleted.

0 comments on commit 6c30eef

Please sign in to comment.