백오피스 추가 및 이미지태그 예외처리

This commit is contained in:
skkim committed 2026-05-04 13:32:09 +09:00
1 parent 1e3da98c6a
commit 37bf9f54ee
34 files changed
+1530 -73

No files matched your search

+20 -14
View File
@@ -1,18 +1,24 @@
from sqlalchemy import update
import logging
from sqlalchemy.ext.asyncio import AsyncSession
from app.user.models import User
from app.credit.exceptions import InsufficientCreditError
from app.credit.models import CreditTransactionType
from app.credit.services.credit_service import deduct_credit
logger = logging.getLogger(__name__)
async def consume_credit(user_uuid, session: AsyncSession) -> bool:
"""atomic UPDATE로 1크레딧 차감.
WHERE credits > 0 조건으로 음수 차감 방지 + PostgreSQL 행 락.
차감 성공 여부 반환.
"""
result = await session.execute(
update(User)
.where(User.user_uuid == user_uuid, User.credits > 0)
.values(credits=User.credits - 1)
)
return result.rowcount > 0
async def consume_credit(user_uuid: str, session: AsyncSession, *, reason: str = "video generation") -> bool:
"""크레딧 1 차감. 기존 호출처와 시그니처 호환 유지."""
try:
await deduct_credit(
session=session,
user_uuid=user_uuid,
amount=1,
type=CreditTransactionType.CONSUME,
reason=reason,
)
return True
except InsufficientCreditError:
return False