added patch and delete endpoint for category and patch endpoint for transaction..#13
added patch and delete endpoint for category and patch endpoint for transaction..#13aryaman-adhikari wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| if not request.state.user: | ||
| raise HTTPException(status_code=401, detail="Not authenticated") |
There was a problem hiding this comment.
Not required... Handle this in auth middleware in better way
| user_id = request.state.user.id | ||
| db.query(models.Transaction).filter( | ||
| models.Transaction.user_id == user_id | ||
| ).delete(synchronize_session=False) |
There was a problem hiding this comment.
what does this synchronize session do?
There was a problem hiding this comment.
when we delete in bulk there could be objects loaded by python in memoey soo in default session tries to scan the memory and if matches any object marks it as deleted and deletes from database . But when i make synchronize_session =false then our route doesn't care about the memory it just deletes from the database. Soo, the merit of using it is to skip the unnecessary scanning .Simply means don't care about memory just delete from the database .Both of them works though .In our case we need to delete i bulk i mean transactions could be in bulk soo why scanning in memory and wasting time just skip the process
| if not request.state.user: | ||
| raise HTTPException(status_code=401, detail="Not authenticated") | ||
| user_id = request.state.user.id |
| db.refresh(category) | ||
| return { | ||
| "message": "Category updated successfully", | ||
| "category": category |
| color: str | ||
| icon: str | ||
|
|
||
|
|
| user = get_user_from_token(token, db) | ||
| if user: | ||
| request.state.user = user | ||
| print("USER:", request.state.user) |
| except (KeyError, ValueError, DecodeError): | ||
| raise HTTPException(status_code=401, detail="Invalid authentication token") | ||
|
|
||
| return db.query(models.User).filter(models.User.id == user_id).first() |
There was a problem hiding this comment.
Handle error for when no user is found
| ): | ||
| users = db.query(models.User).all() | ||
| return {"users": users} | ||
| return users |
There was a problem hiding this comment.
return in a json and proper format
| current_user: models.User = Depends(require_auth), | ||
| ): | ||
| categories = db.query(models.Category).filter(models.Category.user_id == current_user.id).all() | ||
| return categories |
| ): | ||
| user_id = request.state.user.id | ||
| categories = db.query(models.Category).filter(models.Category.user_id == user_id).all() | ||
| categories = db.query(models.Category).filter( |
There was a problem hiding this comment.
This is a single category... rename it to category
|
|
||
| return {"categories": categories} | ||
| raise HTTPException(status_code=404, detail="Category not found") | ||
| return categories |
|
|
||
|
|
||
| if not category_to_delete: | ||
| @router.delete("/categories/{category_id}") |
There was a problem hiding this comment.
Maybe related transaction should be deleted first
| user = db.query(models.User).filter( | ||
| models.User.id == current_user.id | ||
| ).first() |
There was a problem hiding this comment.
We already get the user from the middleware
added patch and delete endpoint for category and patch endpoint for transaction..