diff --git a/backend/migration/versions/07a7ec136a04_0008_add_rank_score_field.py b/backend/migration/versions/07a7ec136a04_0008_add_rank_score_field.py new file mode 100644 index 0000000..8123577 --- /dev/null +++ b/backend/migration/versions/07a7ec136a04_0008_add_rank_score_field.py @@ -0,0 +1,37 @@ +"""0008-ADD-RANK-SCORE-FIELD + +Revision ID: 07a7ec136a04 +Revises: cc7150130bcf +Create Date: 2024-03-18 17:56:35.329602 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import sqlmodel +from sqlalchemy.dialects import mysql + +# revision identifiers, used by Alembic. +revision: str = '07a7ec136a04' +down_revision: Union[str, None] = 'cc7150130bcf' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('game_alias', 'game_id', + existing_type=mysql.INTEGER(), + nullable=True) + op.add_column('user', sa.Column('rank_score', sa.Integer(), nullable=False)) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user', 'rank_score') + op.alter_column('game_alias', 'game_id', + existing_type=mysql.INTEGER(), + nullable=False) + # ### end Alembic commands ### diff --git a/backend/src/auth/model.py b/backend/src/auth/model.py index 482f8f8..57da2ae 100644 --- a/backend/src/auth/model.py +++ b/backend/src/auth/model.py @@ -10,6 +10,7 @@ class User(CreatedAtMixin, UpdatedAtMixin, SQLModelBaseUserDB, table=True): oauth_accounts: list["OAuthAccount"] = Relationship( back_populates="user", sa_relationship_kwargs={"lazy": "joined", "cascade": "all, delete"} ) + rank_score: int = Field(default=0, nullable=False) class OAuthAccount(CreatedAtMixin, UpdatedAtMixin, SQLModelBaseOAuthAccount, table=True): diff --git a/backend/src/auth/router.py b/backend/src/auth/router.py index 3863bd1..63b88b9 100644 --- a/backend/src/auth/router.py +++ b/backend/src/auth/router.py @@ -1,8 +1,10 @@ -from fastapi import APIRouter +from fastapi import APIRouter, status +from fastapi_users import schemas from ..config import settings from .dependency import CURRENT_USER_DEP from .oauth2 import facebook_oauth_client, google_oauth_client +from .schema import UserRead from .user import auth_backend, fastapi_users router = APIRouter(tags=["auth"]) @@ -22,6 +24,22 @@ ) +@router.get( + "/me", + response_model=UserRead, + name="users:current_user", + responses={ + status.HTTP_401_UNAUTHORIZED: { + "description": "Missing token or inactive user.", + }, + }, +) +async def me( + user: CURRENT_USER_DEP, +): + return schemas.model_validate(UserRead, user) + + @router.post("/auth/check") def check(current_user: CURRENT_USER_DEP): - return "ok" + "ok" diff --git a/backend/src/auth/schema.py b/backend/src/auth/schema.py index c31016d..ac3d9f4 100644 --- a/backend/src/auth/schema.py +++ b/backend/src/auth/schema.py @@ -2,4 +2,4 @@ class UserRead(schemas.BaseUser[int]): - pass + rank_score: int