Skip to content

Commit

Permalink
participate_vote에서 참여 코드 확인 절차도 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
odumag99 committed Jan 8, 2025
1 parent 9a40434 commit 5e986be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion snuvote/app/vote/dto/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ class CreateVoteRequest(BaseModel):


class ParticipateVoteRequest(BaseModel):
participated_choice_ids: List[int]
participated_choice_ids: List[int]
participation_code: str | None
10 changes: 9 additions & 1 deletion snuvote/app/vote/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ def __init__(self) -> None:

class ChoiceNotFoundError(HTTPException):
def __init__(self) -> None:
super().__init__(HTTP_404_NOT_FOUND, "Choice not found")
super().__init__(HTTP_404_NOT_FOUND, "Choice not found")

class ParticipationCodeNotProvidedError(HTTPException):
def __init__(self) -> None:
super().__init__(HTTP_403_FORBIDDEN, "Participation code not provided")

class WrongParticipationCodeError(HTTPException):
def __init__(self) -> None:
super().__init__(HTTP_403_FORBIDDEN, "Wrong participation code")
12 changes: 11 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
from snuvote.app.vote.errors import ChoiceNotFoundError, InvalidFieldFormatError, MultipleChoicesError, ParticipationCodeError, ParticipationCodeNotProvidedError, WrongParticipationCodeError
from snuvote.app.vote.dto.requests import ParticipateVoteRequest

from datetime import datetime, timedelta
Expand Down Expand Up @@ -51,6 +51,16 @@ def get_vote_by_vote_id(self, vote_id: int) -> Vote:
return self.vote_store.get_vote_by_vote_id(vote_id=vote_id)

def participate_vote(self, vote: Vote, user: User, participate_vote_request: ParticipateVoteRequest) -> None:

# 참여코드가 필요한 투표글인 경우
if vote.participation_code_required:
# 프론트에서 제공되지 않은 경우
if not participate_vote_request.participation_code:
raise ParticipationCodeNotProvidedError()
# 참여코드가 불일치하는 경우
if vote.participation_code != participate_vote_request.participation_code:
raise WrongParticipationCodeError()

# 중복 투표 불가능인데 중복 투표 했을 때
if not vote.multiple_choice and len(participate_vote_request.participated_choice_ids) > 1:
raise MultipleChoicesError()
Expand Down

0 comments on commit 5e986be

Please sign in to comment.