Skip to content
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

refact(backend-lifespan): improving type checking and incorporating lifespan as an alternative to on_event #394

Merged
merged 8 commits into from
Jun 28, 2024

Conversation

Krr0ptioN
Copy link
Collaborator

@Krr0ptioN Krr0ptioN commented Jun 24, 2024

Description

This PR aims to resolve few type checking errors and replacing deprecated features of Fast API with new alternative ones.

API Changes

  • Replacing existing ‍on_event for graceful shutdown and disposability with lifespan.
  • Improving type checking and eliminating linting errors

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests (stories, interaction tests, unit tests, e2e tests) to cover my changes.

@Krr0ptioN Krr0ptioN added refactor Refactoring existing design and implementation backend related to the backend labels Jun 24, 2024
@Krr0ptioN Krr0ptioN self-assigned this Jun 24, 2024
Copy link

vercel bot commented Jun 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marzneshin ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:16pm

@Krr0ptioN Krr0ptioN changed the title Refact/backend refact(backend-lifespan): improving type checking and incorporating lifespan as an alternative to on_event Jun 24, 2024
Copy link

sonarcloud bot commented Jun 24, 2024

if not payload.get("created_at"):
return
if dbadmin.password_reset_at > payload.get("created_at"):
if bool(dbadmin.password_reset_at):
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to cast into boolean

if db_user is User and db_user.key == key:
return db_user
else:
raise HTTPException(status_code=404, detail="User not found")
Copy link
Collaborator

Choose a reason for hiding this comment

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

no detail here

@@ -90,15 +89,15 @@ def get_user(
def parse_start_date(start: str | None = None):
if not start:
return datetime.fromtimestamp(
datetime.utcnow().timestamp() - 30 * 24 * 3600
datetime.now().timestamp() - 30 * 24 * 3600
Copy link
Collaborator

Choose a reason for hiding this comment

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

switch back to utcnow for now so api support is not broken

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually causes internal problem

)
else:
return datetime.fromisoformat(start)


def parse_end_date(end: str | None = None):
if not end:
return datetime.utcnow()
return datetime.now()
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@@ -95,10 +95,10 @@ def modify_admin(
raise HTTPException(status_code=404, detail="Admin not found")

# If a sudoer admin wants to edit another sudoer
if (username != admin.username) and dbadmin.is_sudo:
if username != admin.username and bool(dbadmin.is_sudo):
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to cast to bool here too

@@ -111,10 +111,10 @@ def remove_admin(username: str, db: DBDep, admin: SudoAdminDep):
if not dbadmin:
raise HTTPException(status_code=404, detail="Admin not found")

if dbadmin.is_sudo:
if bool(dbadmin.is_sudo):
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend related to the backend refactor Refactoring existing design and implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants