Skip to content

Commit

Permalink
Fix response key for API consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKs committed Mar 21, 2022
1 parent 01e3ee2 commit 27293c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ notes
.coverage
htmlcov/
coverage.xml
.DS_Store
10 changes: 5 additions & 5 deletions app/api/api_v2/endpoints/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@


class DeletedFileResponse(BaseModel):
file_path: str = Field(...)
path: str = Field(...)


@router.delete('/files', response_model=DeletedFileResponse)
async def delete_file(
file_path: str,
path: str,
boto_session: AioBaseClient = Depends(get_boto),
user: User = Depends(cognito_signed_in),
db_session: AsyncSession = Depends(yield_db_session),
) -> dict[str, str]:
"""
Delete file with filename
"""
video_statement = select(Video).where(and_(Video.path == file_path, Video.user_id == user.id))
video_statement = select(Video).where(and_(Video.path == path, Video.user_id == user.id))
db_result = await db_session.exec(video_statement) # type: ignore
video = db_result.first()
if not video:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail='File not found. Ensure you own the file, and that the file already exist.',
)
await boto_session.delete_object(Bucket=settings.S3_BUCKET_URL, Key=file_path)
await boto_session.delete_object(Bucket=settings.S3_BUCKET_URL, Key=path)
await db_session.delete(video)
await db_session.commit()
return {'file_path': file_path}
return {'path': path}

0 comments on commit 27293c9

Please sign in to comment.