update put method
This commit is contained in:
parent
dd04cedf0e
commit
d206a9f8a3
@ -163,7 +163,7 @@ async def update_users_me(current_user: Annotated[users.User, Depends(users_toke
|
|||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
@router.put("/users", tags=["users"], status_code=status.HTTP_201_CREATED)
|
@router.put("/users", tags=["users"], status_code=status.HTTP_201_CREATED)
|
||||||
async def update_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userSingle: users.UserIn | None = None, response: Response = Response):
|
async def update_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userSingle: users.UserIn | None = None):
|
||||||
if userSingle is None:
|
if userSingle is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
@ -173,7 +173,6 @@ async def update_users(authorize: Annotated[bool, Depends(permissions_checker.Pe
|
|||||||
|
|
||||||
user = user_repository.find_one_by({"$or":[{"username": {'$eq': userSingle.username}}, {"email": {"$eq": userSingle.email}}]})
|
user = user_repository.find_one_by({"$or":[{"username": {'$eq': userSingle.username}}, {"email": {"$eq": userSingle.email}}]})
|
||||||
if user is not None:
|
if user is not None:
|
||||||
response.status_code = status.HTTP_201_CREATED
|
|
||||||
if user.username == userSingle.username:
|
if user.username == userSingle.username:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_204_NO_CONTENT,
|
status_code=status.HTTP_204_NO_CONTENT,
|
||||||
@ -184,17 +183,16 @@ async def update_users(authorize: Annotated[bool, Depends(permissions_checker.Pe
|
|||||||
status_code=status.HTTP_204_NO_CONTENT,
|
status_code=status.HTTP_204_NO_CONTENT,
|
||||||
detail="email"
|
detail="email"
|
||||||
)
|
)
|
||||||
user.username = userSingle.username
|
|
||||||
user.password = users_token.get_password_hash(userSingle.password)
|
user = users.User(username=userSingle.username, password=users_token.get_password_hash(userSingle.password), email=userSingle.email)
|
||||||
user.roles = userSingle.roles
|
user.roles = userSingle.roles
|
||||||
user.email = userSingle.email
|
|
||||||
user.firstName = userSingle.firstName
|
user.firstName = userSingle.firstName
|
||||||
user.name = userSingle.name
|
user.name = userSingle.name
|
||||||
user.birth = userSingle.birth
|
user.birth = userSingle.birth
|
||||||
user.created_at = datetime.today()
|
user.created_at = datetime.today()
|
||||||
user_repository.save(user)
|
user_repository.save(user)
|
||||||
content = {"message": "user is created"}
|
content = {"message": "user is created"}
|
||||||
response = JSONResponse(content=content)
|
response = JSONResponse(content=content, status_code=status.HTTP_201_CREATED)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user