Remove extra (old) log routes
This commit is contained in:
parent
8985eecfea
commit
cd23780414
@ -100,73 +100,3 @@ async def delete_link(
|
||||
db.commit()
|
||||
|
||||
return status.HTTP_204_NO_CONTENT
|
||||
|
||||
|
||||
@router.get("/{link}/logs", summary="Get all logs associated with a link")
|
||||
async def get_link_logs(
|
||||
link: Annotated[str, Path(title="Link to get logs for")],
|
||||
current_user: Annotated[User, Depends(get_current_user)],
|
||||
db=Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Get all of the IP logs associated with a link
|
||||
"""
|
||||
link = link.upper()
|
||||
# Get the link and check the owner
|
||||
link = db.query(Link).filter(Link.link == link).first()
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Link not found"
|
||||
)
|
||||
if link.owner != current_user.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Link not associated with your account",
|
||||
)
|
||||
|
||||
# Get and return all of the logs - ordered by timestamp
|
||||
logs = (
|
||||
db.query(Log)
|
||||
.filter(Log.link == link.link)
|
||||
.order_by(Log.timestamp.desc())
|
||||
.all()
|
||||
)
|
||||
return logs
|
||||
|
||||
|
||||
@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),
|
||||
):
|
||||
"""
|
||||
Delete the specified log associated with a link
|
||||
"""
|
||||
link = link.upper()
|
||||
# Get the link and check the owner
|
||||
link = db.query(Link).filter(Link.link == link).first()
|
||||
if not link:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Link not found"
|
||||
)
|
||||
if link.owner != current_user.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Link not associated with your account",
|
||||
)
|
||||
|
||||
# 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user