feat: VK OAuth flow, catalog sync improvements, and expanded test suite
- Add VK OAuth implicit flow: /vk-auth redirect, /vk-callback JS page, /vk-callback/save endpoint with state validation - Add VK_CLIENT_ID/VK_CLIENT_SECRET to config - Add refresh_token/token_expires_at columns to vk_connections (migration 0006) - Fix vk_catalog task: handle price/thumb_photo as string or dict (VK API v5.199) - Fix connections/vk/test: use groups.getById instead of market.getAlbums (works with both user and group tokens) - Add orphan deletion to mirror_to_vk: VK products not in Evotor are removed - Handle ungrouped Evotor products: push to "Без категории" VK album - Respect SyncConfig.is_enabled in mirror_to_vk - Add product count column to catalog groups page - Add group name column to catalog products page - Expand test suite: 73 new tests covering connections routes, catalog routes, vk_sync task logic, and catalog task helpers (138 total, all passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from web.auth.session import get_current_user
|
||||
@@ -99,9 +100,19 @@ async def catalog_groups(store_evotor_id: str, request: Request, db: Session = D
|
||||
.all()
|
||||
)
|
||||
enabled_ids = _enabled_group_ids(db, user.id, store_evotor_id)
|
||||
|
||||
counts_q = (
|
||||
db.query(CachedProduct.group_evotor_id, func.count().label("cnt"))
|
||||
.filter(CachedProduct.user_id == user.id, CachedProduct.store_evotor_id == store_evotor_id)
|
||||
.group_by(CachedProduct.group_evotor_id)
|
||||
.all()
|
||||
)
|
||||
product_counts = {row.group_evotor_id: row.cnt for row in counts_q}
|
||||
|
||||
return _render(request, "catalog/groups.html", {
|
||||
"user": user, "store": store, "groups": groups,
|
||||
"enabled_ids": enabled_ids,
|
||||
"product_counts": product_counts,
|
||||
})
|
||||
|
||||
|
||||
@@ -135,12 +146,14 @@ async def catalog_products(store_evotor_id: str, request: Request, db: Session =
|
||||
.order_by(CachedGroup.name)
|
||||
.all()
|
||||
)
|
||||
group_map = {g.evotor_id: g.name for g in groups}
|
||||
return _render(request, "catalog/products.html", {
|
||||
"user": user,
|
||||
"store": store,
|
||||
"products": products,
|
||||
"groups": groups,
|
||||
"group_id": group_id,
|
||||
"group_map": group_map,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user