From 6b8e90a332f6ea0f1378aa12b910eab78ea46b4c Mon Sep 17 00:00:00 2001 From: 2jun0 Date: Mon, 18 Mar 2024 17:58:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20user=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=97=90=20rank=5Fscore=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../07a7ec136a04_0008_add_rank_score_field.py | 37 +++++++++++++++++++ backend/src/auth/model.py | 1 + backend/src/auth/schema.py | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 backend/migration/versions/07a7ec136a04_0008_add_rank_score_field.py 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/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 From 27d2fc6057cdae0cb70b86feb7ce6500632a87f4 Mon Sep 17 00:00:00 2001 From: 2jun0 Date: Mon, 18 Mar 2024 18:06:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/auth/router.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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"