refactor: clean up code by adding missing commas and improving import order

This commit is contained in:
JSC
2025-07-02 10:46:53 +02:00
parent 171dbb9b63
commit 703212656f
20 changed files with 87 additions and 496 deletions

View File

@@ -1,9 +1,9 @@
"""User OAuth model for storing user's connected providers."""
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from sqlalchemy import String, DateTime, Text, ForeignKey
from sqlalchemy import DateTime, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import db
@@ -29,11 +29,11 @@ class UserOAuth(db.Model):
# Provider-specific user information
email: Mapped[str] = mapped_column(String(255), nullable=False)
name: Mapped[str] = mapped_column(String(255), nullable=False)
picture: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
picture: Mapped[str | None] = mapped_column(Text, nullable=True)
# Timestamps
created_at: Mapped[datetime] = mapped_column(
DateTime, default=datetime.utcnow, nullable=False
DateTime, default=datetime.utcnow, nullable=False,
)
updated_at: Mapped[datetime] = mapped_column(
DateTime,
@@ -45,13 +45,13 @@ class UserOAuth(db.Model):
# Unique constraint on provider + provider_id combination
__table_args__ = (
db.UniqueConstraint(
"provider", "provider_id", name="unique_provider_user"
"provider", "provider_id", name="unique_provider_user",
),
)
# Relationships
user: Mapped["User"] = relationship(
"User", back_populates="oauth_providers"
"User", back_populates="oauth_providers",
)
def __repr__(self) -> str:
@@ -73,11 +73,11 @@ class UserOAuth(db.Model):
@classmethod
def find_by_provider_and_id(
cls, provider: str, provider_id: str
cls, provider: str, provider_id: str,
) -> Optional["UserOAuth"]:
"""Find OAuth provider by provider name and provider ID."""
return cls.query.filter_by(
provider=provider, provider_id=provider_id
provider=provider, provider_id=provider_id,
).first()
@classmethod
@@ -88,7 +88,7 @@ class UserOAuth(db.Model):
provider_id: str,
email: str,
name: str,
picture: Optional[str] = None,
picture: str | None = None,
) -> "UserOAuth":
"""Create new OAuth provider or update existing one."""
oauth_provider = cls.find_by_provider_and_id(provider, provider_id)