feat: delete /api/v1/external_channels/import/

This commit is contained in:
Artem Tsyrulnikov
2025-11-11 23:15:50 +03:00
parent 552a3ddef2
commit 292bb0d49b
5 changed files with 1 additions and 82 deletions

View File

@@ -1,7 +1,7 @@
import uuid
from typing import Annotated
from fastapi import Depends, File, UploadFile
from fastapi import Depends
from fastapi.routing import APIRouter
from src import dependencies, dto
@@ -80,25 +80,3 @@ async def delete_external_channel(
)
await dependencies.get_usecase().delete_external_channel(input=input)
@external_channels_router.post('/import/{target_channel_id}')
async def import_external_channels(
target_channel_id: uuid.UUID,
current_user: Annotated[JWTPayload, Depends(dependencies.get_current_user)],
file: UploadFile = File(...),
) -> dto.ImportExternalChannelsOutput:
"""
Import external channels from Excel file (Tgstat export).
Note: This is a mock endpoint until Excel structure is clarified.
"""
file_content = await file.read()
input = dto.ImportExternalChannelsInput(
target_channel_id=target_channel_id,
user_id=current_user.user_id,
file_content=file_content,
)
return await dependencies.get_usecase().import_external_channels_from_excel(input=input)

View File

@@ -17,8 +17,6 @@ __all__ = (
'DeleteExternalChannelInput',
'UpdateExternalChannelInput',
'UpdateExternalChannelLinksInput',
'ImportExternalChannelsInput',
'ImportExternalChannelsOutput',
'CreativeOutput',
'GetCreativesInput',
'GetCreativesOutput',
@@ -56,8 +54,6 @@ from .external_channel import (
ExternalChannelOutput,
GetExternalChannelsInput,
GetExternalChannelsOutput,
ImportExternalChannelsInput,
ImportExternalChannelsOutput,
UpdateExternalChannelInput,
UpdateExternalChannelLinksInput,
)

View File

@@ -45,15 +45,3 @@ class UpdateExternalChannelInput(pydantic.BaseModel):
class UpdateExternalChannelLinksInput(pydantic.BaseModel):
add_target_channel_ids: list[uuid.UUID] = []
remove_target_channel_ids: list[uuid.UUID] = []
class ImportExternalChannelsInput(pydantic.BaseModel):
target_channel_id: uuid.UUID
user_id: uuid.UUID
file_content: bytes # Excel file content
class ImportExternalChannelsOutput(pydantic.BaseModel):
created_count: int
skipped_count: int
errors: list[str]

View File

@@ -13,7 +13,6 @@ from .creative.update_creative import update_creative
from .external_channel.create_external_channel import create_external_channel
from .external_channel.delete_external_channel import delete_external_channel
from .external_channel.get_external_channels import get_external_channels
from .external_channel.import_external_channels_from_excel import import_external_channels_from_excel
from .external_channel.update_external_channel import update_external_channel
from .external_channel.update_external_channel_links import update_external_channel_links
from .purchase.create_purchase import create_purchase
@@ -168,7 +167,6 @@ class Usecase:
delete_external_channel = delete_external_channel
update_external_channel = update_external_channel
update_external_channel_links = update_external_channel_links
import_external_channels_from_excel = import_external_channels_from_excel
get_creatives = get_creatives
get_creative = get_creative
create_creative = create_creative

View File

@@ -1,41 +0,0 @@
import logging
from typing import TYPE_CHECKING
from src import domain, dto
if TYPE_CHECKING:
from .. import Usecase
log = logging.getLogger(__name__)
async def import_external_channels_from_excel(
self: 'Usecase', input: dto.ImportExternalChannelsInput
) -> dto.ImportExternalChannelsOutput:
async with self.database.transaction():
target_channel = await self.database.get_target_channel(
user_id=input.user_id, channel_id=input.target_channel_id
)
if not target_channel:
log.warning(
'User %s attempted to import to unavailable target channel %s', input.user_id, input.target_channel_id
)
raise domain.TargetChannelNotFound(input.target_channel_id)
created_count = 0
skipped_count = 0
errors: list[str] = []
log.info(
'Excel import completed for target %s: %s created, %s skipped, %s errors',
input.target_channel_id,
created_count,
skipped_count,
len(errors),
)
return dto.ImportExternalChannelsOutput(
created_count=created_count,
skipped_count=skipped_count,
errors=errors,
)