from bson.objectid import ObjectId
from fastapi import APIRouter, Depends, HTTPException, status
from mongomapper.errors import DocumentNotFoundError

from app.models import User, Tip
from app.dependencies import get_current_user

router = APIRouter(prefix='/tipping_jar')

@router.get('/')
def list_tips(current_user: User = Depends(get_current_user)):
  """Lists tips made by the current user"""
  tips = Tip.all(target=current_user.reference)
  return [tip.json() for tip in tips]

@router.get('/{tip_id}')
def get_tip(tip_id: str, current_user: User = Depends(get_current_user)):
  """Get a tip made by the current user"""
  try:
    tip = Tip.get(tip_id, target=current_user.reference)
  except DocumentNotFoundError:
    raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
  
  return tip.json()
from bson.objectid import ObjectId
from fastapi import APIRouter, Depends, HTTPException, status
from mongomapper.errors import DocumentNotFoundError

from app.models import User, Tip
from app.dependencies import get_current_user

router = APIRouter(prefix='/tipping_jar')

@router.get('/')
def list_tips(current_user: User = Depends(get_current_user)):
  """Lists tips made by the current user"""
  tips = Tip.all(target=current_user.reference)
  return [tip.json() for tip in tips]

@router.get('/{tip_id}')
def get_tip(tip_id: str, current_user: User = Depends(get_current_user)):
  """Get a tip made by the current user"""
  try:
    tip = Tip.get(tip_id, target=current_user.reference)
  except DocumentNotFoundError:
    raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
  
  return tip.json()
Lists tips made by the current user Get a tip made by the current user