Skip to content

Commit

Permalink
refactor: small refactor to use path params
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Sep 21, 2024
1 parent da7de12 commit 215211c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 82 deletions.
93 changes: 16 additions & 77 deletions src/backend/app/submissions/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,74 +414,7 @@ async def submission_table(
return response


# FIXME remove it since separate endpoint is not required now.
# @router.get("/task_submissions/{project_id}")
# async def task_submissions(
# task_id: int,
# project: db_models.DbProject = Depends(project_deps.get_project_by_id),
# page: int = Query(1, ge=1),
# limit: int = Query(13, le=100),
# submission_id: Optional[str] = None,
# submitted_by: Optional[str] = None,
# review_state: Optional[str] = None,
# submitted_date: Optional[str] = Query(
# None, title="Submitted Date", description="Date in format (e.g., 'YYYY-MM-DD')"
# ),
# db: Session = Depends(database.get_db),
# current_user: AuthUser = Depends(mapper),
# ):
# """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.

# task_id: The ID of the task.
# """
# skip = (page - 1) * limit
# filters = {
# "$top": limit,
# "$skip": skip,
# "$count": True,
# "$wkt": True,
# }

# if submitted_date:
# filters["$filter"] = (
# "__system/submissionDate ge {}T00:00:00+00:00 "
# "and __system/submissionDate le {}T23:59:59.999+00:00"
# ).format(submitted_date, submitted_date)

# if submitted_by:
# if "$filter" in filters:
# filters["$filter"] += f"and (username eq '{submitted_by}')"
# else:
# filters["$filter"] = f"username eq '{submitted_by}'"

# if review_state:
# if "$filter" in filters:
# filters["$filter"] += f" and (__system/reviewState eq '{review_state}')"
# else:
# filters["$filter"] = f"__system/reviewState eq '{review_state}'"

# data, count = await submission_crud.get_submission_by_task(
# project, task_id, filters, db
# )
# pagination = await project_crud.get_pagination(page, count, limit, count)
# response = submission_schemas.PaginatedSubmissions(
# results=data,
# pagination=submission_schemas.PaginationInfo(**pagination.model_dump()),
# )
# if submission_id:
# submission_detail = await submission_crud.get_submission_detail(
# project, task_id, submission_id, db
# )
# response = submission_detail.get("value", [])[0]

# return response


@router.get("/submission-detail")
@router.get("/{submission_id}")
async def submission_detail(
submission_id: str,
db: Session = Depends(database.get_db),
Expand Down Expand Up @@ -597,42 +530,48 @@ async def conflate_geojson(
) from e


@router.get("/get-submission-photo")
@router.get("/{submission_id}/photos")
async def submission_photo(
submission_id: str,
db: Session = Depends(database.get_db),
) -> dict:
"""Get submission photo.
"""Get submission photos.
Retrieves the S3 path of the submission photo for the given submission ID.
Retrieves the S3 paths of the submission photos for the given submission ID.
Args:
submission_id (str): The ID of the submission.
db (Session): The database session.
Returns:
dict: A dictionary containing the S3 path of the submission photo.
If no photo is found,
the dictionary will contain a None value for the S3 path.
If no photo is found,
the dictionary will contain a None value for the S3 path.
Raises:
HTTPException: If an error occurs while retrieving the submission photo.
"""
try:
sql = text("""
SELECT s3_path FROM submission_photos WHERE submission_id = :submission_id
SELECT
s3_path
FROM
submission_photos
WHERE
submission_id = :submission_id;
""")
results = db.execute(sql, {"submission_id": submission_id}).fetchall()

# Extract the s3_path from each result and return as a list
s3_paths = [result.s3_path for result in results] if results else []

return {"image_url": s3_paths}
return {"image_urls": s3_paths}

except Exception as e:
log.warning(
f"Failed to get submission photo for submission {submission_id}: {e}"
f"Failed to get submission photos for submission {submission_id}: {e}"
)
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Failed to get submission photo",
detail="Failed to get submission photos",
) from e
6 changes: 1 addition & 5 deletions src/frontend/src/views/SubmissionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ const SubmissionDetails = () => {

useEffect(() => {
dispatch(
SubmissionService(
`${
import.meta.env.VITE_API_URL
}/submission/submission-detail?submission_id=${paramsInstanceId}&project_id=${projectId}`,
),
SubmissionService(`${import.meta.env.VITE_API_URL}/submission/${paramsInstanceId}?project_id=${projectId}`),
);
}, [projectId, paramsInstanceId]);

Expand Down

0 comments on commit 215211c

Please sign in to comment.