feat(contacts): switch contacts UX to email-first flow
Some checks failed
CI / test (push) Failing after 18s

- expose email in user search/contact responses

- add add-contact-by-email API endpoint

- show email in contacts/search and add contact form by email in Contacts tab
This commit is contained in:
2026-03-08 11:51:02 +03:00
parent 897defc39d
commit cbd1b008bb
6 changed files with 77 additions and 5 deletions

View File

@@ -4,11 +4,12 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.auth.service import get_current_user
from app.database.session import get_db
from app.users.models import User
from app.users.schemas import UserProfileUpdate, UserRead, UserSearchRead
from app.users.schemas import ContactByEmailRequest, UserProfileUpdate, UserRead, UserSearchRead
from app.users.service import (
add_contact,
block_user,
get_user_by_id,
get_user_by_email,
get_user_by_username,
list_blocked_users,
list_contacts,
@@ -101,6 +102,23 @@ async def add_contact_endpoint(
await add_contact(db, user_id=current_user.id, contact_user_id=user_id)
@router.post("/contacts/by-email", status_code=status.HTTP_204_NO_CONTENT)
async def add_contact_by_email_endpoint(
payload: ContactByEmailRequest,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> None:
target = await get_user_by_email(db, payload.email)
if not target:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
if target.id == current_user.id:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Cannot add yourself")
is_blocked = await has_block_relation_between_users(db, user_a_id=current_user.id, user_b_id=target.id)
if is_blocked:
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Cannot add contact while blocked")
await add_contact(db, user_id=current_user.id, contact_user_id=target.id)
@router.delete("/{user_id}/contacts", status_code=status.HTTP_204_NO_CONTENT)
async def remove_contact_endpoint(
user_id: int,