diff --git a/app/main.py b/app/main.py index 73ba199..c22ce66 100644 --- a/app/main.py +++ b/app/main.py @@ -304,4 +304,20 @@ async def search_users(name: str, current_user: User = Depends(get_current_user) except pymongo.errors.OperationFailure: raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Regex may be wrongly formatted") - return users \ No newline at end of file + return users + +@app.get( + path="/user/{id}", + responses={401: {"model": HTTPError}, 422: {"model": HTTPError}, 404: {"model": HTTPError}}, + response_model=UserDTO +) +async def get_user(id: str, current_user: User = Depends(get_current_user)): + try: + user = users_collection.find_one({"_id": ObjectId(id)}) + except bson.errors.InvalidId: + objectid_misformatted() + + if user is None: + raise HTTPException(status_code=404, detail="User not found") + + return serializers.user_serialize(user) \ No newline at end of file