Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 18, 2024
1 parent 707d02d commit a75a276
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/backend/app/submission/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,14 @@ async def get_submissions_by_date(
return response


async def get_submission_by_project(project_id:int, skip:0, limit:100, db:Session):
async def get_submission_by_project(project_id: int, skip: 0, limit: 100, db: Session):
project = await project_crud.get_project(db, project_id)
s3_project_path = f"/{project.organisation_id}/{project_id}"
s3_submission_path = f"/{s3_project_path}/submission.zip"

try:
file = get_obj_from_bucket(settings.S3_BUCKET_NAME, s3_submission_path)
except ValueError as e:
except ValueError:
return 0, []

with zipfile.ZipFile(file, "r") as zip_ref:
Expand Down
24 changes: 12 additions & 12 deletions src/backend/app/submission/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
from typing import Optional

from fastapi import APIRouter, BackgroundTasks, Depends, Response, Query
from fastapi import APIRouter, BackgroundTasks, Depends, Query, Response
from fastapi.concurrency import run_in_threadpool
from fastapi.responses import FileResponse, JSONResponse
from osm_fieldwork.odk_merge import OdkMerge
Expand Down Expand Up @@ -358,35 +358,35 @@ async def get_submission_form_fields(
response = odk_form.form_fields(project.odkid, str(task_list[0]))
return response


@router.get("/submission_table/{project_id}")
async def submission_table(
background_tasks: BackgroundTasks,
project_id: int,
page: int = Query(1, ge=1),
results_per_page: int = Query(13, le=100),
db: Session = Depends(database.get_db)
):
"""
This api returns the submission table of a project.
page: int = Query(1, ge=1),
results_per_page: int = Query(13, le=100),
db: Session = Depends(database.get_db),
):
"""This api returns the submission table of a project.
It takes two parameter: project_id and task_id.
project_id: The ID of the project. This endpoint returns the submission table of this project.
task_id: The ID of the task. This endpoint returns the submission table of this task.
"""
skip = (page - 1) * results_per_page
limit = results_per_page
count, data = await submission_crud.get_submission_by_project(project_id, skip, limit, db)
count, data = await submission_crud.get_submission_by_project(
project_id, skip, limit, db
)
background_task_id = await project_crud.insert_background_task_into_database(
db, "sync_submission", project_id
)

background_tasks.add_task(
submission_crud.update_submission_in_s3, db, project_id, background_task_id
)
pagination = await project_crud.get_pagination(
page, count, results_per_page, count
)
pagination = await project_crud.get_pagination(page, count, results_per_page, count)
response = submission_schemas.PaginatedSubmissions(
results=data,
pagination=submission_schemas.PaginationInfo(**pagination.dict()),
)
return response
return response
5 changes: 4 additions & 1 deletion src/backend/app/submission/submission_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

"""Pydantic models for data submissions."""

from typing import List, Optional, Union
from typing import List, Optional

from pydantic import BaseModel


class PaginationInfo(BaseModel):
"""Pagination JSON return."""

has_next: bool
has_prev: bool
next_num: Optional[int]
Expand Down

0 comments on commit a75a276

Please sign in to comment.