Skip to content

Sourcery refactored main 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: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 27, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from berecik November 27, 2023 18:07
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -82 to +84
if ( uname == None and passwd == None):
if uname is None and passwd is None:
return {"message" : "invalid user"}
elif not valid_users.get(uname) == None:
elif valid_users.get(uname) is not None:
Copy link
Author

Choose a reason for hiding this comment

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

Function signup refactored with the following changes:

  • Use x is None rather than x == None [×3] (none-compare)
  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -105 to +110
if not valid_users.get(user.username) == None:
if valid_users.get(user.username) is not None:
return ValidUser(id=None, username = None, password = None, passphrase = None)
else:
valid_user = ValidUser(id=uuid1(), username= user.username, password = user.password, passphrase = hashpw(user.password.encode(),gensalt()))
valid_users[user.username] = valid_user
del pending_users[user.username]
return valid_user
valid_user = ValidUser(id=uuid1(), username= user.username, password = user.password, passphrase = hashpw(user.password.encode(),gensalt()))
valid_users[user.username] = valid_user
del pending_users[user.username]
return valid_user
Copy link
Author

Choose a reason for hiding this comment

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

Function approve_user refactored with the following changes:

Comment on lines -121 to +123
if username == None:
if username is None:
return {"message": "invalid user"}
else:
del valid_users[username]
return {"message": "deleted user"}
del valid_users[username]
return {"message": "deleted user"}
Copy link
Author

Choose a reason for hiding this comment

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

Function delete_user refactored with the following changes:

Comment on lines -134 to +139
if valid_users.get(username) == None:
if valid_users.get(username) is None:
return {"message": "user does not exist"}
else:
user = valid_users.get(username)
if checkpw(password.encode(), user.passphrase.encode()):
return user
else:
return {"message": "invalid user"}
user = valid_users.get(username)
return (
user
if checkpw(password.encode(), user.passphrase.encode())
else {"message": "invalid user"}
)
Copy link
Author

Choose a reason for hiding this comment

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

Function login refactored with the following changes:

Comment on lines -152 to +156
if valid_users.get(username) == None:
if valid_users.get(username) is None:
return {"message": "user does not exist"}
elif old_passw == '' or new_passw == '':
elif not old_passw or not new_passw:
characters = ascii_lowercase
temporary_passwd = ''.join(random.choice(characters) for i in range(passwd_len))
temporary_passwd = ''.join(
random.choice(characters) for _ in range(passwd_len)
)
Copy link
Author

Choose a reason for hiding this comment

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

Function change_password refactored with the following changes:

Comment on lines -309 to +315
if valid_users.get(username) == None:
if valid_users.get(username) is None:
return {"message": "user does not exist"}
elif discussion_posts.get(id) == None:
elif discussion_posts.get(id) is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function delete_discussion refactored with the following changes:

Comment on lines -319 to +328
if valid_users.get(username) == None:
if valid_users.get(username) is None:
return {"message": "user does not exist"}
elif discussion_posts.get(id) == None:
elif discussion_posts.get(id) is None:
return {"message": "post does not exist"}
else:
forum = discussion_posts[id]
return forum
return discussion_posts[id]
Copy link
Author

Choose a reason for hiding this comment

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

Function view_discussion refactored with the following changes:

Comment on lines -19 to +31
tour = Tour(id=tid, name=input.name, city=input.city, country=input.country, type=input.type, location=input.location,
amenities=input.amenities, feedbacks=list(), ratings=0.0, visits=0, isBooked=False)
tour = Tour(
id=tid,
name=input.name,
city=input.city,
country=input.country,
type=input.type,
location=input.location,
amenities=input.amenities,
feedbacks=[],
ratings=0.0,
visits=0,
isBooked=False,
)
Copy link
Author

Choose a reason for hiding this comment

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

Function add_tour_destination refactored with the following changes:

Comment on lines -27 to +33
if approved_users.get(touristId) == None and tours.get(tid) == None:
if approved_users.get(touristId) is None and tours.get(tid) is None:
raise PostFeedbackException(detail='tourist and tour details invalid', status_code=403)
assessId = uuid1()
assessment = Assessment(id=assessId, post=post, tour_id= tid, tourist_id=touristId)
assessment = Assessment(id=assessId, post=post, tour_id= tid, tourist_id=touristId)
feedback_tour[assessId] = assessment
tours[tid].ratings = (tours[tid].ratings + post.rating)/2

Copy link
Author

Choose a reason for hiding this comment

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

Function post_tourist_feedback refactored with the following changes:

if feedback_tour.get(assessId) == None:
if feedback_tour.get(assessId) is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function update_tour_rating refactored with the following changes:

if approved_users.get(touristId) == None and feedback_tour.get(assessId):
if approved_users.get(touristId) is None and feedback_tour.get(assessId):
Copy link
Author

Choose a reason for hiding this comment

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

Function delete_tourist_feedback refactored with the following changes:

Comment on lines -42 to +48
tourist = Tourist(id=userid, login=login, date_signed=datetime.now(), booked=0, tours=list() )
tourist = Tourist(
id=userid,
login=login,
date_signed=datetime.now(),
booked=0,
tours=[],
)
Copy link
Author

Choose a reason for hiding this comment

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

Function signup refactored with the following changes:

Comment on lines -60 to +72
tourist_list = [ tourist for tourist in approved_users.values() if tourist['login']['username'] == username and tourist['login']['password'] == password]
if len(tourist_list) == 0 or tourist_list == None:
tourist_list = [ tourist for tourist in approved_users.values() if tourist['login']['username'] == username and tourist['login']['password'] == password]
if not tourist_list or tourist_list is None:
return JSONResponse(content={"message": "invalid operation"}, status_code=status.HTTP_403_FORBIDDEN)
else:
tourist = tourist_list[0]
tour_json = jsonable_encoder(tourist)
bg_task.add_task(audit_log_transaction, touristId=str(tourist['login']['id']), message="login")
return JSONResponse(content=tour_json, status_code=status.HTTP_200_OK)
tourist = tourist_list[0]
tour_json = jsonable_encoder(tourist)
bg_task.add_task(audit_log_transaction, touristId=str(tourist['login']['id']), message="login")
return JSONResponse(content=tour_json, status_code=status.HTTP_200_OK)
Copy link
Author

Choose a reason for hiding this comment

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

Function login refactored with the following changes:

Comment on lines -103 to +107
if tours[id].amenities != None:
amenities = tours[id].amenities
amenities_json = jsonable_encoder(amenities)
return JSONResponse(content=amenities_json)
else:
return {"message": "no amenities"}
if tours[id].amenities is None:
return {"message": "no amenities"}
amenities = tours[id].amenities
amenities_json = jsonable_encoder(amenities)
return JSONResponse(content=amenities_json)
Copy link
Author

Choose a reason for hiding this comment

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

Function show_amenities refactored with the following changes:

Comment on lines -34 to +35
if approved_users.get(touristId) == None:
raise HTTPException(status_code=500, detail="details are missing")
if approved_users.get(touristId) is None:
raise HTTPException(status_code=500, detail="details are missing")
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_booking refactored with the following changes:

account = {"id": id, "username": username, "password": password, "type": type}
return account
return {"id": id, "username": username, "password": password, "type": type}
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_login refactored with the following changes:

Comment on lines -26 to +33
user = {"id": id, "firstname": firstname, "lastname": lastname, "middle": middle, "bday": bday, "pos": pos, "login": login}
return user
return {
"id": id,
"firstname": firstname,
"lastname": lastname,
"middle": middle,
"bday": bday,
"pos": pos,
"login": login,
}
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_details refactored with the following changes:

Comment on lines -16 to +18
if keywords_recipe.get(id) == None:
keywords = list()
keywords.append(keyword)
keywords_recipe[id] = keywords
else:
keywords = keywords_recipe[id]
keywords.append(keyword)
keywords_recipe[id] = keywords
keywords = [] if keywords_recipe.get(id) is None else keywords_recipe[id]
keywords.append(keyword)
keywords_recipe[id] = keywords
Copy link
Author

Choose a reason for hiding this comment

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

Function KeywordRepository.add_keywords refactored with the following changes:

recipes_list = [val.name for val in recipes.values()]
return recipes_list
return [val.name for val in recipes.values()]
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_recipe_names refactored with the following changes:

Comment on lines -23 to +30
logger.info('Request to access ' + request.url.path)
logger.info(f'Request to access {request.url.path}')
try:
response = await call_next(request)
except Exception as ex:
logger.error(f"Request to " + request.url.path + " failed: {ex}")
logger.error(f"Request to {request.url.path}" + " failed: {ex}")
response = JSONResponse(content={"success": False}, status_code=500)
finally:
logger.info('Successfully accessed ' + request.url.path)
logger.info(f'Successfully accessed {request.url.path}')
Copy link
Author

Choose a reason for hiding this comment

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

Function log_middleware refactored with the following changes:

Comment on lines -14 to +32


class StudentSettings(BaseSettings):
application:str = 'Student Management System'
webmaster:str = 'sjctrags@university.com'
created:date = '2021-11-10'




class ServerSettings(BaseSettings):
production_server:str
prod_port:int
development_server:str
development_server:str
dev_port:int




class Config:
env_file = os.getcwd() + '/configuration/erp_settings.properties'
env_file = f'{os.getcwd()}/configuration/erp_settings.properties'
Copy link
Author

Choose a reason for hiding this comment

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

Lines 14-28 refactored with the following changes:

if not account == None:
if account is not None:
Copy link
Author

Choose a reason for hiding this comment

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

Function approved_signup refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)
  • Use x is None rather than x == None (none-compare)

Comment on lines -51 to +53
result = login_service.update_login_password(user_id, newpass)
if result:
if result := login_service.update_login_password(user_id, newpass):
return JSONResponse(content={'message':'password changed successfully'}, status_code=201)
else:
else:
Copy link
Author

Choose a reason for hiding this comment

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

Function change_password refactored with the following changes:

Comment on lines -62 to +63
result = faculty_service.add_faculty(faculty)
if result:
if result := faculty_service.add_faculty(faculty):
return jsonable_encoder(faculty)
else:
else:
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_profile refactored with the following changes:

result = faculty_service.update_faculty(faculty_id, profile_dict )
if result:
if result := faculty_service.update_faculty(faculty_id, profile_dict):
return JSONResponse(content={'message':'profile updated successfully'}, status_code=201)
else:
else:
Copy link
Author

Choose a reason for hiding this comment

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

Function update_profile refactored with the following changes:

Comment on lines -19 to +17
result = self.repo.delete_faculty(faculty_id)
return result
return self.repo.delete_faculty(faculty_id)
Copy link
Author

Choose a reason for hiding this comment

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

Function FacultyService.remove_faculty refactored with the following changes:

result = self.repo.insert_login(login)
return result
return self.repo.insert_login(login)
Copy link
Author

Choose a reason for hiding this comment

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

Function FacultyLoginService.add_faculty_login refactored with the following changes:

Comment on lines -15 to +14
result = self.repo.update_password(user_id, newpass)
return result
return self.repo.update_password(user_id, newpass)
Copy link
Author

Choose a reason for hiding this comment

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

Function FacultyLoginService.update_login_password refactored with the following changes:

Comment on lines -19 to +17
result = self.repo.delete_login(user_id)
return result
return self.repo.delete_login(user_id)
Copy link
Author

Choose a reason for hiding this comment

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

Function FacultyLoginService.remove_faculty_login refactored with the following changes:

result = self.repo.insert_item(signup)
return result
return self.repo.insert_item(signup)
Copy link
Author

Choose a reason for hiding this comment

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

Function FacultySignupService.add_signup refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants