-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,7 @@ async def create_user(payload: schemas.CreateUserSchema, request: Request, db: S | |
# Check if user already exist | ||
user_query = db.query(models.User).filter( | ||
models.User.email == EmailStr(payload.email.lower())) | ||
user = user_query.first() | ||
if user: | ||
if user := user_query.first(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
raise HTTPException(status_code=status.HTTP_409_CONFLICT, | ||
detail='Account already exist') | ||
# Compare password and passwordConfirm | ||
|
@@ -111,12 +110,16 @@ def refresh_token(response: Response, request: Request, Authorize: AuthJWT = Dep | |
if not user_id: | ||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail='Could not refresh access token') | ||
user = db.query(models.User).filter(models.User.id == user_id).first() | ||
if not user: | ||
if ( | ||
user := db.query(models.User) | ||
.filter(models.User.id == user_id) | ||
.first() | ||
): | ||
access_token = Authorize.create_access_token( | ||
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN)) | ||
else: | ||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail='The user belonging to this token no logger exist') | ||
access_token = Authorize.create_access_token( | ||
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN)) | ||
Comment on lines
-114
to
-119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as e: | ||
error = e.__class__.__name__ | ||
if error == 'MissingTokenError': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,11 +45,11 @@ def update_post(id: str, post: schemas.UpdatePostSchema, db: Session = Depends(g | |
|
||
@router.get('/{id}', response_model=schemas.PostResponse) | ||
def get_post(id: str, db: Session = Depends(get_db), user_id: str = Depends(require_user)): | ||
post = db.query(models.Post).filter(models.Post.id == id).first() | ||
if not post: | ||
if post := db.query(models.Post).filter(models.Post.id == id).first(): | ||
return post | ||
else: | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, | ||
detail=f"No post with this id: {id} found") | ||
return post | ||
Comment on lines
-48
to
-52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
@router.delete('/{id}') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,4 @@ | |
|
||
@router.get('/me', response_model=schemas.UserResponse) | ||
def get_me(db: Session = Depends(get_db), user_id: str = Depends(oauth2.require_user)): | ||
user = db.query(models.User).filter(models.User.id == user_id).first() | ||
return user | ||
return db.query(models.User).filter(models.User.id == user_id).first() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Email.__init__
refactored with the following changes:remove-redundant-pass
)