diff --git a/app/routes/pins.py b/app/routes/pins.py index 96cfa9a..54e4154 100644 --- a/app/routes/pins.py +++ b/app/routes/pins.py @@ -263,5 +263,38 @@ async def get_pin_shares(id: str, current_user: User = Depends(get_current_user) return {"shares": shares_list} + except bson.errors.InvalidId: + objectid_misformatted() + +@pins_router.delete( + path="/{id}/share/{friend_id}", + responses={401: {"model": HTTPError}, 404: {"model": HTTPError}, 422: {"model": HTTPError}, 403: {"model": HTTPError}} +) +async def delete_pin_share(id: str, friend_id: str, current_user: User = Depends(get_current_user)): + try: + # Vérifier si le pin existe et appartient à l'utilisateur courant + pin = pins_collection.find_one({"_id": ObjectId(id)}) + check_pin_is_null(pin) + + if pin["user_id"] != current_user.uid: + # Vérifier si l'utilisateur a le pin partagé avec lui + permission = pin_permissions_collection.find_one({ + "pin_id": ObjectId(id), + "user_id": current_user.uid + }) + if not permission: + raise HTTPException(status_code=403, detail="You don't have permission to delete this pin share") + + # Supprimer la permission de partage pour l'utilisateur + result = pin_permissions_collection.delete_one({ + "pin_id": ObjectId(id), + "user_id": ObjectId(friend_id) + }) + + if result.deleted_count == 0: + raise HTTPException(status_code=404, detail="Pin share not found or you don't have permission to delete it") + + return {"message": "Pin share deleted successfully"} + except bson.errors.InvalidId: objectid_misformatted() \ No newline at end of file