Fixed syntax misc issues

This commit is contained in:
Hannah dagemark 2026-08-10 23:11:21 +02:00
commit 9cc09014a4
3 changed files with 33 additions and 14 deletions

View file

@ -1,3 +1,5 @@
from sqlmodel import inspect
from app.database import (
add_to_database,
delete_from_database_where,
@ -17,10 +19,10 @@ def get_by_id(project_id: int):
return get_from_database_where_id(Project, project_id)
def get_with_parent(project_id: int):
def get_with_parent(project_id: int | None):
return get_from_database_where(
Project,
Project.parent_id,
Project.id, # type: ignore (Type correct on runtime)
project_id,
)
@ -35,11 +37,16 @@ def update(
update_attribute: str,
new_value: int | str | None,
):
if update_attribute not in inspect(Project).attrs:
raise ValueError(f"Invalid attribute: {update_attribute}")
attribute = getattr(Project, update_attribute)
return update_database_where(
Project,
Project.id,
Project.id, # type: ignore (Type correct on runtime)
project_id,
update_attribute,
attribute,
new_value,
)
@ -47,6 +54,6 @@ def update(
def delete(project_id: int):
return delete_from_database_where(
Project,
Project.id,
Project.id, # type: ignore (Type correct on runtime)
project_id,
)

View file

@ -1,3 +1,5 @@
from sqlmodel import inspect
from app.database import (
add_to_database,
delete_from_database_where,
@ -26,11 +28,16 @@ def update(
update_attribute: str,
new_value: int | str | None,
):
if update_attribute not in inspect(Service).attrs:
raise ValueError(f"Invalid attribute: {update_attribute}")
attribute = getattr(Service, update_attribute)
return update_database_where(
Service,
Service.id,
Service.id, # type: ignore (Type correct on runtime)
service_id,
update_attribute,
attribute,
new_value,
)
@ -38,6 +45,6 @@ def update(
def delete(service_id: int):
return delete_from_database_where(
Service,
Service.id,
Service.id, # type: ignore (Type correct on runtime)
service_id,
)

View file

@ -27,9 +27,14 @@ def get_password_hash(password: str):
def get_user(username: str):
user_dict = get_from_database_where(User, User.username, username, True)
if user_dict is not None:
return UserInDB(**user_dict)
user = get_from_database_where(
User,
User.username, # type: ignore (Type correct on runtime)
username,
True,
)
if user is not None:
return UserInDB.model_validate(user[0])
def authenticate_user(username: str, password: str):
@ -43,7 +48,7 @@ def authenticate_user(username: str, password: str):
def create_access_token(
data: dict[str, str],
data: dict[str, str | datetime],
expires_delta: timedelta | None = None,
):
to_encode = data.copy()
@ -52,7 +57,7 @@ def create_access_token(
else:
expire = datetime.now(UTC) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(
encoded_jwt = jwt.encode( # pyright: ignore[reportUnknownMemberType] (Third party skill issue)
to_encode,
Settings.secret_key,
algorithm=Settings.algorithm,
@ -67,7 +72,7 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
headers={"WWW-Authenticate": "Bearer"},
)
try:
payload = jwt.decode(
payload = jwt.decode( # pyright: ignore[reportUnknownMemberType] (Third party skill issue)
token,
Settings.secret_key,
algorithms=[Settings.algorithm],