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,67 @@
|
||||
"""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.portfolio import PortfolioItem
|
||||
from app.models.user import User
|
||||
|
||||
router = APIRouter(prefix="/api/portfolio", tags=["portfolio"])
|
||||
|
||||
|
||||
@router.post("")
|
||||
async def create_portfolio_item(data: dict, db: AsyncSession = Depends(get_db), user: dict = Depends(get_current_user)):
|
||||
"""Добавить работу в портфолио."""
|
||||
|
||||
item = PortfolioItem(
|
||||
freelancer_id=user["id"],
|
||||
title=data.get("title", ""),
|
||||
description=data.get("description"),
|
||||
image_url=data.get("image_url"),
|
||||
live_url=data.get("live_url"),
|
||||
technologies=data.get("technologies", []),
|
||||
)
|
||||
db.add(item)
|
||||
await db.commit()
|
||||
await db.refresh(item)
|
||||
|
||||
return {"id": str(item.id)}
|
||||
|
||||
|
||||
@router.get("/user/{user_id}")
|
||||
async def list_portfolio(user_id: str, db: AsyncSession = Depends(get_db)):
|
||||
"""Список работ в портфолио пользователя."""
|
||||
|
||||
result = await db.execute(select(PortfolioItem).where(PortfolioItem.freelancer_id == user_id))
|
||||
items = result.scalars().all()
|
||||
|
||||
return [
|
||||
{
|
||||
"id": str(i.id),
|
||||
"title": i.title,
|
||||
"description": i.description,
|
||||
"image_url": i.image_url,
|
||||
"live_url": i.live_url,
|
||||
"technologies": i.technologies,
|
||||
"created_at": str(i.created_at),
|
||||
} for i in items
|
||||
]
|
||||
|
||||
|
||||
@router.delete("/{item_id}")
|
||||
async def delete_portfolio_item(item_id: str, user: dict = Depends(get_current_user), db: AsyncSession = Depends(get_db)):
|
||||
"""Удалить работу из портфолио."""
|
||||
|
||||
result = await db.execute(select(PortfolioItem).where(PortfolioItem.id == item_id))
|
||||
item = result.scalar_one_or_none()
|
||||
|
||||
if not item or item.freelancer_id != user["id"]:
|
||||
raise HTTPException(status_code=403, detail="Нет доступа")
|
||||
|
||||
await db.delete(item)
|
||||
await db.commit()
|
||||
|
||||
return {"status": "deleted"}
|
||||
Reference in New Issue
Block a user