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

GDET-74: 유저의 랭킹 점수 필드 구현 #63

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 ###
1 change: 1 addition & 0 deletions backend/src/auth/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 20 additions & 2 deletions backend/src/auth/router.py
Original file line number Diff line number Diff line change
@@ -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"])
Expand All @@ -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"
2 changes: 1 addition & 1 deletion backend/src/auth/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class UserRead(schemas.BaseUser[int]):
pass
rank_score: int
Loading