diff --git a/snuvote/app/vote/errors.py b/snuvote/app/vote/errors.py index fe70a9a..d3e9f56 100644 --- a/snuvote/app/vote/errors.py +++ b/snuvote/app/vote/errors.py @@ -42,4 +42,8 @@ def __init__(self) -> None: class WrongParticipationCodeError(HTTPException): def __init__(self) -> None: - super().__init__(HTTP_403_FORBIDDEN, "Wrong participation code") \ No newline at end of file + super().__init__(HTTP_403_FORBIDDEN, "Wrong participation code") + +class EndedVoteError(HTTPException): + def __init__(self) -> None: + super().__init__(HTTP_403_FORBIDDEN, "Ended vote") \ No newline at end of file diff --git a/snuvote/app/vote/service.py b/snuvote/app/vote/service.py index 7313e40..5eccf65 100644 --- a/snuvote/app/vote/service.py +++ b/snuvote/app/vote/service.py @@ -3,7 +3,7 @@ from fastapi import Depends from snuvote.database.models import Vote, User, Choice, ChoiceParticipation from snuvote.app.vote.store import VoteStore -from snuvote.app.vote.errors import ChoiceNotFoundError, InvalidFieldFormatError, MultipleChoicesError, ParticipationCodeError, ParticipationCodeNotProvidedError, WrongParticipationCodeError +from snuvote.app.vote.errors import ChoiceNotFoundError, InvalidFieldFormatError, MultipleChoicesError, ParticipationCodeError, ParticipationCodeNotProvidedError, WrongParticipationCodeError, EndedVoteError from snuvote.app.vote.dto.requests import ParticipateVoteRequest from datetime import datetime, timedelta @@ -52,6 +52,10 @@ def get_vote_by_vote_id(self, vote_id: int) -> Vote: def participate_vote(self, vote: Vote, user: User, participate_vote_request: ParticipateVoteRequest) -> None: + # 종료 시간 이후인 경우 + if datetime.now() > vote.end_datetime: + raise EndedVoteError() + # 참여코드가 필요한 투표글인 경우 if vote.participation_code_required: # 프론트에서 제공되지 않은 경우 diff --git a/snuvote/database/alembic/versions/2025_01_09_1507-ac9dd8c234ab_deprecated_status_field_from_vote.py b/snuvote/database/alembic/versions/2025_01_09_1507-ac9dd8c234ab_deprecated_status_field_from_vote.py new file mode 100644 index 0000000..2a53ff9 --- /dev/null +++ b/snuvote/database/alembic/versions/2025_01_09_1507-ac9dd8c234ab_deprecated_status_field_from_vote.py @@ -0,0 +1,30 @@ +"""deprecated Status field from Vote + +Revision ID: ac9dd8c234ab +Revises: e5616988a7c5 +Create Date: 2025-01-09 15:07:03.665278 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +# revision identifiers, used by Alembic. +revision: str = 'ac9dd8c234ab' +down_revision: Union[str, None] = 'e5616988a7c5' +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.drop_column('vote', 'status') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('vote', sa.Column('status', mysql.TINYINT(display_width=1), autoincrement=False, nullable=False)) + # ### end Alembic commands ### diff --git a/snuvote/database/models.py b/snuvote/database/models.py index 5ca6735..8f80550 100644 --- a/snuvote/database/models.py +++ b/snuvote/database/models.py @@ -35,7 +35,6 @@ class Vote(Base): create_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False) title: Mapped[str] = mapped_column(String(100), nullable=False) content: Mapped[str] = mapped_column(Text, nullable=False) - status: Mapped[bool] = mapped_column(Boolean, nullable=False) end_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False) participation_code_required: Mapped[bool] = mapped_column(Boolean, nullable=False) participation_code: Mapped[str] = mapped_column(String(20), nullable=True)