feat: creatives and external channels
This commit is contained in:
23
src/usecase/creative/delete_creative.py
Normal file
23
src/usecase/creative/delete_creative.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src import domain, dto
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def delete_creative(self: 'Usecase', input: dto.DeleteCreativeInput) -> None:
|
||||
async with self.database.transaction():
|
||||
creative = await self.database.get_creative(input.user_id, input.creative_id)
|
||||
if not creative:
|
||||
log.warning('User %s attempted to delete unavailable creative %s', input.user_id, input.creative_id)
|
||||
raise domain.CreativeNotFound(input.creative_id)
|
||||
|
||||
if creative.purchases_count > 0:
|
||||
log.warning('Creative %s is used in purchases and cannot be deleted', input.creative_id)
|
||||
raise domain.CreativeInUse(input.creative_id)
|
||||
|
||||
await self.database.delete_creative(input.creative_id)
|
||||
Reference in New Issue
Block a user