Skip to content

Commit

Permalink
Merge pull request #63 from 2jun0/GDET-74
Browse files Browse the repository at this point in the history
GDET-74: 유저의 랭킹 점수 필드 구현
  • Loading branch information
2jun0 authored Mar 18, 2024
2 parents 05fa747 + 27d2fc6 commit 8122d16
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
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

0 comments on commit 8122d16

Please sign in to comment.