-
Notifications
You must be signed in to change notification settings - Fork 0
EventUser table #124
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
base: main
Are you sure you want to change the base?
EventUser table #124
Changes from all commits
35ad55b
397c116
c272363
5254935
f21e312
9513e1f
7d4d213
2254c3c
ad6c63b
aa6f76a
ecddbdd
6094ad4
c0d45e9
08859e4
eb7ba9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from auth_lib.fastapi import UnionAuth | ||
| from fastapi import APIRouter, Depends, Query | ||
| from fastapi_sqlalchemy import db | ||
|
|
||
| from calendar_backend.models import Event, EventUser | ||
| from calendar_backend.routes.models.visit import VisitResponse | ||
|
|
||
|
|
||
| router = APIRouter(prefix="/event", tags=["Event: Visit"]) | ||
|
|
||
|
|
||
| @router.post("/{event_id}/visit", response_model=VisitResponse) | ||
| async def set_event_visit_status( | ||
| event_id: int, | ||
| auth: dict = Depends(UnionAuth()), | ||
| visit: str = Query(enum=["no_status", "going", "not_going", "attended"], default="no_status"), | ||
| ) -> VisitResponse: | ||
| """ | ||
| Отметить посещение мероприятия для текущего пользователя. | ||
| """ | ||
| user_id = auth.get('id') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. удалить авторизацию |
||
|
|
||
| Event.get(event_id, with_deleted=False, session=db.session) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with_deleted=False необязательно прописывать, по умолчанию false |
||
|
|
||
| existing = ( | ||
| EventUser.get_all(session=db.session) | ||
| .filter(EventUser.event_id == event_id, EventUser.user_id == user_id) | ||
| .first() | ||
| ) | ||
|
|
||
| if existing: | ||
| result = EventUser.update(existing.id, session=db.session, status=visit) | ||
| else: | ||
| result = EventUser.create( | ||
| session=db.session, | ||
| event_id=event_id, | ||
| user_id=user_id, | ||
| status=visit, | ||
| ) | ||
|
|
||
| db.session.commit() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это лишнее, убрать |
||
| return VisitResponse.model_validate(result) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import datetime | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from calendar_backend.models import EventUserStatus | ||
|
|
||
|
|
||
| class VisitRequest(BaseModel): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. поменять на Base |
||
| status: EventUserStatus | ||
|
|
||
|
|
||
| class VisitResponse(BaseModel): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. наследованные брать от класса Base из соседнего файла Base, там уже прописано model_config = {"from_attributes": True} |
||
| id: int | ||
| event_id: int | ||
| user_id: int | ||
| status: EventUserStatus | ||
| updated_at: datetime.datetime | ||
|
|
||
| model_config = {"from_attributes": True} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. убрать |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """EventUser building | ||
|
|
||
| Revision ID: b060027b11b3 | ||
| Revises: 55a049fde8f4 | ||
| Create Date: 2026-04-20 17:56:39.185374 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'b060027b11b3' | ||
| down_revision = '55a049fde8f4' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table( | ||
| 'event_user', | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('event_id', sa.Integer(), nullable=False), | ||
| sa.Column('user_id', sa.Integer(), nullable=False), | ||
| sa.Column( | ||
| 'status', | ||
| sa.Enum('NO_STATUS', 'GOING', 'NOT_GOING', 'ATTENDED', name='eventuserstatus', native_enum=False), | ||
| nullable=False, | ||
| ), | ||
| sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
| sa.Column('is_deleted', sa.Boolean(), nullable=False), | ||
| sa.ForeignKeyConstraint( | ||
| ['event_id'], | ||
| ['event.id'], | ||
| ), | ||
| sa.PrimaryKeyConstraint('id'), | ||
| ) | ||
| op.drop_constraint(op.f('lesson_group_id_fkey'), 'event', type_='foreignkey') | ||
| op.drop_column('event', 'group_id') | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column('event', sa.Column('group_id', sa.INTEGER(), autoincrement=False, nullable=True)) | ||
| op.create_foreign_key(op.f('lesson_group_id_fkey'), 'event', 'group', ['group_id'], ['id']) | ||
| op.drop_table('event_user') | ||
| # ### end Alembic commands ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,6 @@ pytest | |
| pytest-cov | ||
| requests | ||
| pytest-mock | ||
| black | ||
| black==23.11.0 | ||
| isort | ||
| autoflake | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чисто из логики, attended надо убрать, так как пользователь не должен иметь возможность поставить инфу что посещена пара, нелогично