fix: name, update values HTTPException

This commit is contained in:
TheNoxium 2025-04-18 17:31:37 +05:00
parent 1333992dc5
commit 29027bf9f8
5 changed files with 22 additions and 26 deletions

View File

@ -9,6 +9,7 @@ from fastapi import (
status, status,
) )
from fastapi import FastAPI
from fastapi_jwt_auth import AuthJWT from fastapi_jwt_auth import AuthJWT
@ -23,7 +24,8 @@ from api.schemas.endpoints.account import UserUpdate
from api.services.access_token_validadtion import AccessTokenValidadtion from api.services.access_token_validadtion import AccessTokenValidadtion
from api.services.user_role_validation import db_user_role_validation from api.services.user_role_validation import db_user_role_validation
from api.services.update_data_validation import put_user_data_validator from api.services.update_data_validation import put_user_data_changes
api_router = APIRouter( api_router = APIRouter(
prefix="/account", prefix="/account",
@ -96,12 +98,10 @@ async def put_account(
detail="Account not found") detail="Account not found")
update_values = put_user_data_validator(user_update,user) update_values = put_user_data_changes(user_update,user)
if update_values is None: if update_values is None:
raise HTTPException( return user
status_code=status.HTTP_409_CONFLICT,
detail="The provided data already exists in the database")
await put_user_id(connection, update_values, user) await put_user_id(connection, update_values, user)
@ -130,12 +130,11 @@ async def delete_account(
user_update = UserUpdate(status=Status.DELETED.value) user_update = UserUpdate(status=Status.DELETED.value)
update_values = put_user_id_validator(user_update,user) update_values = put_user_data_changes(user_update,user)
if update_values is None: if update_values is None:
raise HTTPException( return user
status_code=status.HTTP_409_CONFLICT,
detail="The provided data already exists in the database")
await put_user_id(connection, update_values, user) await put_user_id(connection, update_values, user)

View File

@ -22,9 +22,11 @@ from api.db.logic.keyring import get_key_id,post_add_key,put_key_id
from api.schemas.account.account import Role,Status from api.schemas.account.account import Role,Status
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
from api.schemas.account.account_keyring import AccountKeyring
from api.services.access_token_validadtion import AccessTokenValidadtion from api.services.access_token_validadtion import AccessTokenValidadtion
from api.services.user_role_validation import db_user_role_validation from api.services.user_role_validation import db_user_role_validation
from api.services.update_data_validation import put_key_data_validator from api.services.update_data_validation import put_key_data_changes
api_router = APIRouter( api_router = APIRouter(
@ -100,12 +102,11 @@ async def put_keyring(
detail="keyring not found") detail="keyring not found")
update_values = put_key_data_validator(keyring_update,keyring) update_values = put_key_data_changes(keyring_update,keyring)
if update_values is None: if update_values is None:
raise HTTPException( return keyring
status_code=status.HTTP_409_CONFLICT,
detail="The provided data already exists in the database")
await put_key_id(connection, update_values, keyring) await put_key_id(connection, update_values, keyring)
@ -135,12 +136,10 @@ async def delete_keyring(
keyring_update = AccountKeyringUpdate(status=Status.DELETED.value) keyring_update = AccountKeyringUpdate(status=Status.DELETED.value)
update_values = put_key_validator(keyring_update,keyring) update_values = put_key_data_changes(keyring_update,keyring)
if update_values is None: if update_values is None:
raise HTTPException( return keyring
status_code=status.HTTP_409_CONFLICT,
detail="The provided data already exists in the database")
await put_key_id(connection, update_values, keyring) await put_key_id(connection, update_values, keyring)

View File

@ -15,7 +15,7 @@ from sqlalchemy.ext.asyncio import AsyncConnection
from api.db.connection.session import get_connection_dep from api.db.connection.session import get_connection_dep
from api.db.logic.account import get_user_id, put_user_id,get_user_login from api.db.logic.account import get_user_id, put_user_id,get_user_login
from api.services.update_data_validation import put_user_data_validator from api.services.update_data_validation import put_user_data_changes
from api.schemas.endpoints.account import UserUpdate from api.schemas.endpoints.account import UserUpdate
@ -76,12 +76,10 @@ async def put_pofile(
detail="Account not found") detail="Account not found")
update_values = put_user_data_validator(user_updata,user) update_values = put_user_data_changes(user_updata,user)
if update_values is None: if update_values is None:
raise HTTPException( return user
status_code=status.HTTP_409_CONFLICT,
detail="The provided data already exists in the database")
await put_user_id(connection, update_values, user) await put_user_id(connection, update_values, user)

View File

@ -3,7 +3,7 @@ from typing import Optional
from api.schemas.endpoints.account import UserUpdate, Role, Status from api.schemas.endpoints.account import UserUpdate, Role, Status
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate, StatusKey, TypeKey from api.schemas.endpoints.account_keyring import AccountKeyringUpdate, StatusKey, TypeKey
def put_user_data_validator(update_data: UserUpdate, user) -> Optional[dict]: def put_user_data_changes(update_data: UserUpdate, user) -> Optional[dict]:
""" """
Сравнивает данные для обновления с текущими значениями пользователя. Сравнивает данные для обновления с текущими значениями пользователя.
Возвращает: Возвращает:
@ -36,7 +36,7 @@ def put_user_data_validator(update_data: UserUpdate, user) -> Optional[dict]:
return changes if changes else None return changes if changes else None
def put_key_data_validator(update_data: AccountKeyringUpdate, key) -> Optional[dict]: def put_key_data_changes(update_data: AccountKeyringUpdate, key) -> Optional[dict]:
""" """
Сравнивает данные для обновления с текущими значениями пользователя. Сравнивает данные для обновления с текущими значениями пользователя.
Возвращает: Возвращает:

View File

@ -40,7 +40,7 @@ async def init():
create_key_query = account_keyring_table.insert().values( create_key_query = account_keyring_table.insert().values(
owner_id=user_id, owner_id=user_id,
key_type=KeyType.PASSWORD, key_type=KeyType.PASSWORD,
key_id=KeyIdGenerator() key_id=KeyIdGenerator(),
key_value=hashed_password, key_value=hashed_password,
status=KeyStatus.ACTIVE, status=KeyStatus.ACTIVE,
) )