Skip to content

Commit

Permalink
update: Refactored downloading of documents/logo
Browse files Browse the repository at this point in the history
  • Loading branch information
kojicmarko committed Mar 9, 2024
1 parent 7cb5d38 commit 60942bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/documents/router.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Annotated

from fastapi import APIRouter, Depends, Query, UploadFile, status
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session

from src.database import get_db
Expand Down Expand Up @@ -56,10 +55,9 @@ def download_document(
document: Annotated[doc_models.Document, Depends(get_doc_by_id)],
curr_user: Annotated[user_schemas.User, Depends(get_curr_user)],
db: Annotated[Session, Depends(get_db)],
) -> StreamingResponse:
) -> doc_schemas.Document:
is_participant(document.project_id, curr_user, db)
res = doc_service.read(document)
return StreamingResponse(res["Body"])
return doc_service.read(document)


@router.put("/documents/{doc_id}", status_code=status.HTTP_200_OK)
Expand Down
8 changes: 4 additions & 4 deletions src/documents/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Any
from uuid import UUID

from fastapi import HTTPException, UploadFile, status
Expand Down Expand Up @@ -34,10 +33,11 @@ def read_all(
)


def read(document: doc_models.Document) -> Any:
def read(document: doc_models.Document) -> doc_schemas.Document:
doc = doc_schemas.Document.model_validate(document)
res = s3.download(f"{doc.project_id}_{doc.name}", "documents")
return res
# Due to API Gateway problems we're only returning URL to the Document
# res = s3.download(f"{doc.project_id}_{doc.name}", "documents")
return doc


def create(
Expand Down
6 changes: 2 additions & 4 deletions src/logos/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from uuid import UUID

from fastapi import APIRouter, Depends, UploadFile, status
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session

from src.database import get_db
Expand Down Expand Up @@ -40,9 +39,8 @@ def upload_logo(
def download_logo(
proj_id: UUID,
proj_logo: Annotated[logo_models.Logo, Depends(get_logo_by_id)],
) -> StreamingResponse:
res = logo_service.read(proj_logo, proj_id)
return StreamingResponse(res["Body"])
) -> logo_schemas.Logo:
return logo_service.read(proj_logo, proj_id)


@router.put(
Expand Down
8 changes: 4 additions & 4 deletions src/logos/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Any
from uuid import UUID

from fastapi import HTTPException, UploadFile, status
Expand All @@ -14,10 +13,11 @@
s3 = S3Client()


def read(logo: logo_models.Logo, proj_id: UUID) -> Any:
def read(logo: logo_models.Logo, proj_id: UUID) -> logo_schemas.Logo:
logo_schema = logo_schemas.Logo.model_validate(logo)
res = s3.download(f"{proj_id}_{logo_schema.name}", "logos")
return res
# Due to API Gateway problems we're only returning URL to the Logo
# res = s3.download(f"{proj_id}_{logo_schema.name}", "logos")
return logo_schema


def create(
Expand Down

0 comments on commit 60942bc

Please sign in to comment.