-
Notifications
You must be signed in to change notification settings - Fork 3
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 #114 from Studio-Yandex-Practicum/feature/wednesda…
…y_messages Feature/wednesday messages
- Loading branch information
Showing
10 changed files
with
279 additions
and
8 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
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
47 changes: 47 additions & 0 deletions
47
src/core/db/migrations/versions/abb6775f7512_add_match_review.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,47 @@ | ||
"""add match_review | ||
Revision ID: abb6775f7512 | ||
Revises: 6d584f53f8cf | ||
Create Date: 2023-12-04 20:54:36.381591 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "abb6775f7512" | ||
down_revision = "6d584f53f8cf" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"match_review", | ||
sa.Column("usersmatch_id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column( | ||
"user_answer", sa.Enum("IS_COMPLETE", "IS_NOT_COMPLETE", name="matchreviewanswerenum"), nullable=True | ||
), | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("created_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), | ||
sa.Column("updated_at", sa.Date(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["usersmatch_id"], | ||
["usersmatch.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("match_review") | ||
op.execute("drop type matchreviewanswerenum") | ||
# ### end Alembic commands ### |
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,31 @@ | ||
from sqlalchemy import select | ||
|
||
from src.core.db.models import MatchReview, UsersMatch | ||
from src.core.db.repository.base import AbstractRepository | ||
from src.core.exceptions.exceptions import ObjectAlreadyExistsError | ||
|
||
|
||
class MatchReviewRepository(AbstractRepository[MatchReview]): | ||
_model = MatchReview | ||
|
||
async def set_match_review_answer(self, match: UsersMatch, user_id: str, answer: str) -> MatchReview: | ||
if user_id == match.object_user_one.user_id: | ||
user = match.object_user_one | ||
elif user_id == match.object_user_two.user_id: | ||
user = match.object_user_two | ||
if await self.get_match_review_if_already_exists(usersmatch_id=match.id, user_id=user.id): | ||
raise ObjectAlreadyExistsError(self._model) # type: ignore[arg-type] | ||
return await self.create(MatchReview(usersmatch_id=match.id, user_id=user.id, user_answer=answer)) | ||
|
||
async def get_match_review_if_already_exists( | ||
self, | ||
usersmatch_id: int, | ||
user_id: int, | ||
) -> MatchReview | None: | ||
async with self._sessionmaker() as session: | ||
match_review = await session.scalar( | ||
select(self._model).where( | ||
(self._model.usersmatch_id == usersmatch_id) & (self._model.user_id == user_id) | ||
) | ||
) | ||
return match_review |
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.