aboutsummaryrefslogtreecommitdiff
path: root/app/routes/links_routes.py
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-11-07 22:44:31 -0600
committerParker <contact@pkrm.dev>2024-11-07 22:44:31 -0600
commita9fa55346c74981ff8d7c435cad123efb8a15c72 (patch)
tree99e69d72d4356d42c797e7b60a4a468161c5caf0 /app/routes/links_routes.py
parent62c034261d9dadadb4abe26c51c007b5423c14d8 (diff)
Dashboard functionality increase
Diffstat (limited to 'app/routes/links_routes.py')
-rw-r--r--app/routes/links_routes.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/app/routes/links_routes.py b/app/routes/links_routes.py
index 90ca1bd..984ccd8 100644
--- a/app/routes/links_routes.py
+++ b/app/routes/links_routes.py
@@ -61,7 +61,7 @@ async def create_link(
return {"link": link_path, "expire_date": new_link.expire_date}
-@router.delete("/{link}", summary="Delete a link")
+@router.delete("/{link}", summary="Delete a link and all associated logs")
async def delete_link(
link: Annotated[str, Path(title="Link to delete")],
current_user: Annotated[User, Depends(get_current_user)],
@@ -126,9 +126,13 @@ async def get_link_logs(
return logs
-@router.delete("/{link}/logs", summary="Delete logs associated with a link")
-async def delete_link_logs(
- link: Annotated[str, Path(title="Link to delete logs for")],
+@router.delete(
+ "/{link}/logs/{log_id}",
+ summary="Delete a specific log associated with a link",
+)
+async def delete_single_log(
+ link: Annotated[str, Path(title="Link associated with the log to delete")],
+ log_id: Annotated[int, Path(title="Log ID to delete")],
current_user: Annotated[User, Depends(get_current_user)],
db=Depends(get_db),
):
@@ -148,10 +152,13 @@ async def delete_link_logs(
detail="Link not associated with your account",
)
- # Get all of the logs
- logs = db.query(Log).filter(Log.link == link.link).all()
- for log in logs:
- db.delete(log)
+ # Get the log and delete it
+ log = db.query(Log).filter(Log.id == log_id).first()
+ if not log:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND, detail="Log not found"
+ )
+ db.delete(log)
db.commit()
return status.HTTP_204_NO_CONTENT