feat: добавить отзывы, milestone-платежи, портфолио, skill-tests и верификацию (фичи Upwork/Fiverr)
Фичи конкурентов внедрены: - Reviews API + UI — система отзывов с рейтингом 1-5 звёзд - Milestones (Upwork-style) — разделение escrow на этапы с submit/approve - Portfolio — портфолио фрилансера с превью работ и технологиями - Skill Tests (Upwork-style) — сертификация навыков с тестами - Verification Badges — верификация email/phone/id/bank Модели: Milestone, PortfolioItem, SkillTest/SkillTestResult, Verification
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""Endpoints для верификации профиля."""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.security import get_current_user
|
||||
from app.models.verification import Verification
|
||||
|
||||
router = APIRouter(prefix="/api/verification", tags=["verification"])
|
||||
|
||||
|
||||
@router.get("/me")
|
||||
async def me_verification(user: dict = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
"""Получить статус верификации текущего пользователя."""
|
||||
|
||||
result = await db.execute(select(Verification).where(Verification.user_id == user["id"]))
|
||||
verification = result.scalar_one_or_none()
|
||||
|
||||
if not verification:
|
||||
return {
|
||||
"user_id": user["id"],
|
||||
"is_email_verified": False,
|
||||
"is_phone_verified": False,
|
||||
"is_id_verified": False,
|
||||
"is_bank_verified": False,
|
||||
"verified_at": None,
|
||||
}
|
||||
|
||||
return {
|
||||
"user_id": verification.user_id,
|
||||
"is_email_verified": verification.is_email_verified,
|
||||
"is_phone_verified": verification.is_phone_verified,
|
||||
"is_id_verified": verification.is_id_verified,
|
||||
"is_bank_verified": verification.is_bank_verified,
|
||||
"verified_at": str(verification.verified_at) if verification.verified_at else None,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/email/verify")
|
||||
async def verify_email(user: dict = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
"""Подтвердить email."""
|
||||
|
||||
result = await db.execute(select(Verification).where(Verification.user_id == user["id"]))
|
||||
verification = result.scalar_one_or_none()
|
||||
|
||||
if not verification:
|
||||
verification = Verification(user_id=user["id"])
|
||||
db.add(verification)
|
||||
|
||||
verification.is_email_verified = True
|
||||
await db.commit()
|
||||
|
||||
return {"status": "email_verified"}
|
||||
|
||||
|
||||
@router.post("/phone/verify")
|
||||
async def verify_phone(user: dict = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
"""Подтвердить телефон."""
|
||||
|
||||
result = await db.execute(select(Verification).where(Verification.user_id == user["id"]))
|
||||
verification = result.scalar_one_or_none()
|
||||
|
||||
if not verification:
|
||||
verification = Verification(user_id=user["id"])
|
||||
db.add(verification)
|
||||
|
||||
verification.is_phone_verified = True
|
||||
await db.commit()
|
||||
|
||||
return {"status": "phone_verified"}
|
||||
Reference in New Issue
Block a user