Skip to content

Commit

Permalink
Show all chests+items endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
skyface753 committed Apr 11, 2024
1 parent 8bcddf1 commit 3ce834d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/api/v2/endpoints/chest/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def get_chest_items(chest_id: int, db: Session = Depends(get_db)):
chest.items = kistenItems
return chest

@router.get('/items/all',
response_model=List[ChestItemJoinedSchema],
tags=['chest-items'])
def get_all_chest_items(db: Session = Depends(get_db)):
# Get all chests
all_chests = []
chests = chest_crud.get_all_chests(db)
logging.info('Get: All chests: {}'.format(chests))
# Get all items for each chest
for chest in chests:
kistenItems = chest_crud.get_joined_items_by_chest_id(chest.id, db)
logging.info('Get: Items in chest {}: {}'.format(chest.id, kistenItems))
chest.items = kistenItems
all_chests.append(chest)
return all_chests

@router.post('/{chest_id}/items', response_model=ChestItemQuantityCreateSchema,
status_code=status.HTTP_201_CREATED, tags=['chest-items'])
def add_item_to_chest(chest_id: int, item: ChestItemQuantityCreateSchema, db: Session = Depends(get_db)):
Expand Down Expand Up @@ -168,4 +184,4 @@ def update_item_quantity_in_chest(chest_id: int, updated_quantity: ChestItemQuan

chest_crud.update_item_in_chest(chest_id, updated_quantity.item_id, updated_quantity.anzahl, db)
logging.info('Item {} in chest {} updated'.format(updated_quantity.item_id, chest_id))
return updated_quantity
return updated_quantity

0 comments on commit 3ce834d

Please sign in to comment.