Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(self, user: models.User, url: str, email: List[EmailStr]):
self.sender = 'Codevo <admin@admin.com>'
self.email = email
self.url = url
pass
Copy link
Author

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:


async def sendMail(self, subject, template):
# Define the config
Expand Down
15 changes: 9 additions & 6 deletions app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_user refactored with the following changes:

raise HTTPException(status_code=status.HTTP_409_CONFLICT,
detail='Account already exist')
# Compare password and passwordConfirm
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function refresh_token refactored with the following changes:

except Exception as e:
error = e.__class__.__name__
if error == 'MissingTokenError':
Expand Down
6 changes: 3 additions & 3 deletions app/routers/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_post refactored with the following changes:



@router.delete('/{id}')
Expand Down
3 changes: 1 addition & 2 deletions app/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_me refactored with the following changes: