files support
This commit is contained in:
parent
ad8c293af1
commit
9be715e16a
|
|
@ -2,7 +2,11 @@ from loguru import logger
|
|||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from chain_service.database.models.chain import Chain
|
||||
|
||||
from chain_service.dependencies.chain_repository import ChainRepositoryDependency
|
||||
from chain_service.dependencies.file_uploader_service import (
|
||||
FileUploaderServiceDependency,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/chain")
|
||||
|
||||
|
|
@ -11,9 +15,11 @@ router = APIRouter(prefix="/chain")
|
|||
async def chain_upsert_controller(
|
||||
chain: Chain,
|
||||
chain_repository: ChainRepositoryDependency,
|
||||
file_uploader_service: FileUploaderServiceDependency,
|
||||
):
|
||||
try:
|
||||
upserted_chain = await chain_repository.upsert(chain)
|
||||
await file_uploader_service.upload_from_chain(upserted_chain)
|
||||
return upserted_chain
|
||||
|
||||
except Exception:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
from .planfix_client import PlanfixClientDependency
|
||||
|
||||
from chain_service.services.progress_action.factory import ProgressActionServiceFactory
|
||||
from chain_service.dependencies.uploaded_file_repository import (
|
||||
UploadedFileRepositoryDependency,
|
||||
)
|
||||
|
||||
from fastapi import Depends
|
||||
from typing import Annotated
|
||||
|
|
@ -7,8 +11,11 @@ from typing import Annotated
|
|||
|
||||
def get_progress_action_service_factory(
|
||||
planfix_client: PlanfixClientDependency,
|
||||
uploaded_file_repository: UploadedFileRepositoryDependency,
|
||||
) -> ProgressActionServiceFactory:
|
||||
return ProgressActionServiceFactory(planfix_client=planfix_client)
|
||||
return ProgressActionServiceFactory(
|
||||
planfix_client=planfix_client, uploaded_file_repository=uploaded_file_repository
|
||||
)
|
||||
|
||||
|
||||
ProgressActionServiceFactoryDependency = Annotated[
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
from .base import BaseProgressActionService
|
||||
|
||||
from chain_service.repositories.uploaded_file import UploadedFileRepository
|
||||
from chain_service.database.models.progress_chain import (
|
||||
CommentProgressAction,
|
||||
ProgressChain,
|
||||
)
|
||||
|
||||
from typing import List
|
||||
from loguru import logger
|
||||
from planfix_client import PlanfixClient
|
||||
|
||||
|
||||
|
|
@ -13,14 +16,41 @@ class CommentProgressActionService(BaseProgressActionService):
|
|||
def __init__(
|
||||
self,
|
||||
planfix_client: PlanfixClient,
|
||||
uploaded_file_repository: UploadedFileRepository,
|
||||
progress_chain: ProgressChain,
|
||||
progress_action: CommentProgressAction,
|
||||
):
|
||||
self.planfix_client = planfix_client
|
||||
self.uploaded_file_repository = uploaded_file_repository
|
||||
self.progress_chain = progress_chain
|
||||
self.progress_action = progress_action
|
||||
|
||||
async def process(self):
|
||||
await self.planfix_client.create_comment(
|
||||
task_id=self.progress_chain.task_id, description=self.progress_action.text
|
||||
)
|
||||
payload = {"task_id": self.progress_chain.task_id}
|
||||
|
||||
if self.progress_action.text:
|
||||
payload["description"] = self.progress_action.text
|
||||
|
||||
if self.progress_action.file_urls:
|
||||
payload["file_ids"] = await self.get_file_ids()
|
||||
|
||||
await self.planfix_client.create_comment(**payload)
|
||||
|
||||
async def get_file_ids(self) -> List[int]:
|
||||
file_ids = list()
|
||||
|
||||
for file_url in self.progress_action.file_urls:
|
||||
uploaded_file = await self.uploaded_file_repository.get_by_file_url(
|
||||
file_url
|
||||
)
|
||||
|
||||
if not uploaded_file:
|
||||
logger.error(
|
||||
f"Uploaded file id not found while running progress_action={self.progress_chain}"
|
||||
)
|
||||
|
||||
continue
|
||||
|
||||
file_ids.append(uploaded_file.file_id)
|
||||
|
||||
return file_ids
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from chain_service.repositories.uploaded_file import UploadedFileRepository
|
||||
from chain_service.database.models.progress_chain import (
|
||||
ProgressChain,
|
||||
BaseProgressAction,
|
||||
|
|
@ -12,8 +13,13 @@ from planfix_client import PlanfixClient
|
|||
|
||||
class ProgressActionServiceFactory:
|
||||
|
||||
def __init__(self, planfix_client: PlanfixClient):
|
||||
def __init__(
|
||||
self,
|
||||
planfix_client: PlanfixClient,
|
||||
uploaded_file_repository: UploadedFileRepository,
|
||||
):
|
||||
self.planfix_client = planfix_client
|
||||
self.uploaded_file_repository = uploaded_file_repository
|
||||
|
||||
def __call__(
|
||||
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
|
||||
|
|
@ -29,6 +35,7 @@ class ProgressActionServiceFactory:
|
|||
case "comment":
|
||||
return CommentProgressActionService(
|
||||
planfix_client=self.planfix_client,
|
||||
uploaded_file_repository=self.uploaded_file_repository,
|
||||
progress_chain=progress_chain,
|
||||
progress_action=progress_action,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user