-
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
Merged
Merged
EventUser table #124
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
35ad55b
EventUser table
Georgon 397c116
EventUser table with right format
Georgon c272363
black format
petrCher 5254935
bug fix
petrCher f21e312
EventUser init
Georgon 9513e1f
Merge branch 'EventUser_table' of https://github.com/profcomff/timeta…
Georgon 7d4d213
EventUser fix
Georgon 2254c3c
EventUser fixed with format
Georgon ad6c63b
bug fix
petrCher aa6f76a
post event/{event_id}/visit/
Georgon ecddbdd
Merge branch 'EventUser_table' of https://github.com/profcomff/timeta…
Georgon 6094ad4
fixed user_event
Georgon c0d45e9
user_event formatted
Georgon 08859e4
user_event fixed
Georgon eb7ba9e
user_event formatted
Georgon f6a7a77
user_event fixed 2
Georgon c33e5d9
format
Georgon 5d39262
comment
Georgon 83c5cf5
format
Georgon d87a61c
comment 2
Georgon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,65 @@ | ||
| from auth_lib.fastapi import UnionAuth | ||
| from fastapi import APIRouter, Depends, HTTPException, status | ||
| from fastapi_sqlalchemy import db | ||
|
|
||
| from calendar_backend.exceptions import ObjectNotFound | ||
| from calendar_backend.models import Event, EventUser | ||
| from calendar_backend.routes.models.visit import VisitRequest, 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, visit: VisitRequest, auth: dict = Depends(UnionAuth(scopes=[])) | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| ) -> VisitResponse: | ||
| """ | ||
| Отметить посещение мероприятия для текущего пользователя. | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| """ | ||
| user_id = auth.get('id') | ||
| if user_id is None: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
| detail="User ID not found in authentication data", | ||
| ) | ||
|
|
||
| try: | ||
| _ = Event.get(event_id, with_deleted=False, session=db.session) | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| except ObjectNotFound: | ||
| raise HTTPException( | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail=f"Event with id {event_id} not found", | ||
| ) | ||
|
|
||
| existing = ( | ||
| db.session.query(EventUser) | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| .filter( | ||
| EventUser.event_id == event_id, | ||
| EventUser.user_id == user_id, | ||
| EventUser.is_deleted == False, | ||
| ) | ||
| .first() | ||
| ) | ||
|
|
||
| if existing: | ||
| existing.status = visit.status | ||
| db.session.flush() | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| result = existing | ||
| else: | ||
| result = EventUser.create( | ||
| session=db.session, | ||
| event_id=event_id, | ||
| user_id=user_id, | ||
| status=visit.status, | ||
| ) | ||
|
|
||
| db.session.commit() | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
|
|
||
| return VisitResponse( | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| id=result.id, | ||
| event_id=result.event_id, | ||
| user_id=result.user_id, | ||
| status=result.status, | ||
| updated_at=result.updated_at.isoformat(), | ||
| ) | ||
This file contains hidden or 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 hidden or 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,17 @@ | ||
| from pydantic import BaseModel | ||
|
|
||
| from calendar_backend.models import EventUserStatus | ||
|
|
||
|
|
||
| class VisitRequest(BaseModel): | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| status: EventUserStatus | ||
|
|
||
|
|
||
| class VisitResponse(BaseModel): | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
| id: int | ||
| event_id: int | ||
| user_id: int | ||
| status: EventUserStatus | ||
| updated_at: str # ISO-формат | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
|
|
||
| model_config = {"from_attributes": True} | ||
|
petrCher marked this conversation as resolved.
Outdated
|
||
This file contains hidden or 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,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 ### |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,6 @@ pytest | |
| pytest-cov | ||
| requests | ||
| pytest-mock | ||
| black | ||
| black==23.11.0 | ||
| isort | ||
| autoflake | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.