-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from 2jun0/GDET-76
GDET-76: 퀴즈 정답 오답시 게임 점수 변화 구현
- Loading branch information
Showing
48 changed files
with
833 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/migration/versions/db66457957a9_0009_add_game_solved_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""0009-ADD-GAME-SOLVED-TABLE | ||
Revision ID: db66457957a9 | ||
Revises: 07a7ec136a04 | ||
Create Date: 2024-04-09 17:43:04.298908 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'db66457957a9' | ||
down_revision: Union[str, None] = '07a7ec136a04' | ||
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.create_table('solved_game', | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('game_id', sa.Integer(), nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['game_id'], ['game.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('user_id', 'game_id') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('solved_game') | ||
# ### end Alembic commands ### |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[pytest] | ||
env_override_existing_values = 1 | ||
env_files = | ||
.test.env | ||
.test.env | ||
asyncio_mode=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from ..repository import CRUDMixin, IRepository | ||
from .model import User | ||
|
||
|
||
class UserRepository(IRepository[User], CRUDMixin): | ||
model = User | ||
|
||
def __init__(self, session: AsyncSession) -> None: | ||
self._session = session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ..exception import BadRequestError | ||
|
||
|
||
class GameAlreadySolvedError(BadRequestError): | ||
DETAIL = "Game Already Solved" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from .model import SolvedGame | ||
from .repository import SolvedGameRepository | ||
|
||
|
||
class GameManager: | ||
def __init__(self, *, solved_game_repository: SolvedGameRepository) -> None: | ||
self._solved_game_repo = solved_game_repository | ||
|
||
async def solve_game(self, *, game_id: int, user_id: int): | ||
exists = await self.has_solved_game(game_id=game_id, user_id=user_id) | ||
if not exists: | ||
solved_game = SolvedGame(user_id=user_id, game_id=game_id) | ||
await self._solved_game_repo.create(model=solved_game) | ||
|
||
async def has_solved_game(self, *, game_id: int, user_id: int): | ||
return await self._solved_game_repo.exists_by_user_and_game(user_id=user_id, game_id=game_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from sqlmodel import select | ||
from sqlmodel.ext.asyncio.session import AsyncSession | ||
|
||
from ..repository import CRUDMixin, IRepository | ||
from .model import SolvedGame | ||
|
||
|
||
class SolvedGameRepository(IRepository[SolvedGame], CRUDMixin): | ||
model = SolvedGame | ||
|
||
def __init__(self, session: AsyncSession) -> None: | ||
self._session = session | ||
|
||
async def get_by_user_and_game(self, *, user_id: int, game_id: int) -> SolvedGame: | ||
stmt = select(SolvedGame).where(SolvedGame.user_id == user_id, SolvedGame.game_id == game_id) | ||
rs = await self._session.exec(stmt) | ||
return rs.one() | ||
|
||
async def exists_by_user_and_game(self, *, user_id: int, game_id: int) -> bool: | ||
stmt = select(SolvedGame).where(SolvedGame.user_id == user_id, SolvedGame.game_id == game_id) | ||
rs = await self._session.exec(stmt) | ||
return rs.one_or_none() is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.