fix(ballot): fix model references

This commit is contained in:
Alexandre Teles 2023-01-05 20:01:28 -03:00
parent 9df0161f68
commit 2a8587d6ae
2 changed files with 9 additions and 3 deletions

View File

@ -2,6 +2,7 @@ from redis import asyncio as aioredis
import app.utils.Logger as Logger import app.utils.Logger as Logger
from app.dependencies import load_config from app.dependencies import load_config
from app.utils.RedisConnector import RedisConnector from app.utils.RedisConnector import RedisConnector
from app.models.BallotModel import BallotModel
config: dict = load_config() config: dict = load_config()
@ -12,7 +13,7 @@ class Ballot:
BallotLogger = Logger.BallotLogger() BallotLogger = Logger.BallotLogger()
async def store(self, discord_hashed_id: str, ballot: str) -> bool: async def store(self, discord_hashed_id: str, ballot: BallotModel) -> bool:
"""Store a ballot. """Store a ballot.
Args: Args:
@ -26,7 +27,12 @@ class Ballot:
stored: bool = False stored: bool = False
try: try:
await self.redis.set(name=discord_hashed_id, value=ballot, nx=True) await self.redis.json().set(
name=discord_hashed_id,
path=".",
obj=ballot,
nx=True
)
await self.BallotLogger.log("STORE_BALLOT", None, discord_hashed_id) await self.BallotLogger.log("STORE_BALLOT", None, discord_hashed_id)
stored = True stored = True
except aioredis.RedisError as e: except aioredis.RedisError as e:

View File

@ -36,7 +36,7 @@ async def cast_ballot(request: Request, response: Response,
stored: bool = await ballot_controller.store( stored: bool = await ballot_controller.store(
Authorize.get_paseto_claims()['discord_hashed_id'], Authorize.get_paseto_claims()['discord_hashed_id'],
ballot.vote ballot
) )
if stored: if stored: