Skip to content

Commit

Permalink
Merge pull request #23 from wafflestudio/vote-status-관리
Browse files Browse the repository at this point in the history
Vote status 관리
  • Loading branch information
odumag99 authored Jan 9, 2025
2 parents 0e40d00 + ab2db01 commit 9a6d6a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 5 additions & 1 deletion snuvote/app/vote/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ def __init__(self) -> None:

class WrongParticipationCodeError(HTTPException):
def __init__(self) -> None:
super().__init__(HTTP_403_FORBIDDEN, "Wrong participation code")
super().__init__(HTTP_403_FORBIDDEN, "Wrong participation code")

class EndedVoteError(HTTPException):
def __init__(self) -> None:
super().__init__(HTTP_403_FORBIDDEN, "Ended vote")
6 changes: 5 additions & 1 deletion snuvote/app/vote/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
# 프론트에서 제공되지 않은 경우
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ###
1 change: 0 additions & 1 deletion snuvote/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9a6d6a3

Please sign in to comment.