removed many unneeded async definitions. The main controller remains async

This commit is contained in:
Lucas Jensen
2024-05-03 13:21:47 -07:00
parent 032feebe23
commit 5bb28ed923
15 changed files with 144 additions and 147 deletions

View File

@@ -13,8 +13,8 @@ class UserController(BaseController):
super().__init__()
self.db: UserQueries = user_queries
async def get_users(self) -> list[User]:
data = await self.db.select_all_series()
def get_users(self) -> list[User]:
data = self.db.select_all_series()
try:
return [User(**e) for e in data]
except Exception as e:
@@ -23,8 +23,8 @@ class UserController(BaseController):
detail=f"Error creating user objects: {e}",
)
async def get_user_by_id(self, id: int) -> User:
if (data := await self.db.select_one_by_id(id)) is None:
def get_user_by_id(self, id: int) -> User:
if (data := self.db.select_one_by_id(id)) is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
)
@@ -36,8 +36,8 @@ class UserController(BaseController):
detail=f"Error creating user object: {e}",
)
async def get_user_by_email(self, email: str) -> User:
if (data := await self.db.get_one_by_email(email)) is None:
def get_user_by_email(self, email: str) -> User:
if (data := self.db.get_one_by_email(email)) is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="User does not exist"
)
@@ -49,8 +49,8 @@ class UserController(BaseController):
detail=f"Error creating user object: {e}",
)
async def get_user_by_sub(self, sub: str) -> User:
if (data := await self.db.get_one_by_sub(sub)) is None:
def get_user_by_sub(self, sub: str) -> User:
if (data := self.db.get_one_by_sub(sub)) is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
)
@@ -62,9 +62,9 @@ class UserController(BaseController):
detail=f"Error creating user object: {e}",
)
async def create_user(self, token: HTTPAuthorizationCredentials) -> User:
def create_user(self, token: HTTPAuthorizationCredentials) -> User:
email, sub = oauth_token.email_and_sub(token)
user: User = await self.get_user_by_email(email)
user: User = self.get_user_by_email(email)
if user.sub is None:
await self.db.update_sub(user.email, sub)
return await self.get_user_by_sub(sub)
self.db.update_sub(user.email, sub)
return self.get_user_by_sub(sub)