aboutsummaryrefslogtreecommitdiff
path: root/api/routes
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-11-15 00:30:43 -0600
committerParker <contact@pkrm.dev>2024-11-15 00:30:43 -0600
commit04cc3869c2844bb82ac6975ee218141104385c35 (patch)
tree1a4c9622606ea4e562a00f6fc022d7c802e3742d /api/routes
parentdbc53a555e64fdd0b848bf33b4208820b8701509 (diff)
Extra route + Much more UI
Diffstat (limited to 'api/routes')
-rw-r--r--api/routes/auth_routes.py2
-rw-r--r--api/routes/log_routes.py41
2 files changed, 42 insertions, 1 deletions
diff --git a/api/routes/auth_routes.py b/api/routes/auth_routes.py
index 24e1391..823feff 100644
--- a/api/routes/auth_routes.py
+++ b/api/routes/auth_routes.py
@@ -33,7 +33,7 @@ async def login_for_access_token(
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
- access_token_expires = timedelta(minutes=1)
+ access_token_expires = timedelta(minutes=180)
access_token = create_access_token(
data={"sub": user.id, "username": user.username},
expires_delta=access_token_expires,
diff --git a/api/routes/log_routes.py b/api/routes/log_routes.py
index 84b8c51..5875e3b 100644
--- a/api/routes/log_routes.py
+++ b/api/routes/log_routes.py
@@ -21,6 +21,9 @@ async def get_logs(
current_user: Annotated[User, Depends(get_current_user)],
db=Depends(get_db),
):
+ """
+ Get all of the logs associated with the current user
+ """
logs = (
db.query(Log)
.filter(Log.owner == current_user.id)
@@ -34,12 +37,47 @@ async def get_logs(
return logs
+@router.get("/{link}", summary="Get all logs for a specific link")
+async def get_logs_for_link(
+ 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 logs associated with a specific link
+ - check to make sure the requester is the owner
+ """
+ link = (
+ db.query(Link)
+ .filter(Link.owner == current_user.id, Link.short == link)
+ .first()
+ )
+ if not link:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND, detail="Link not found"
+ )
+ logs = (
+ db.query(Log)
+ .filter(Log.link_id == link.id)
+ .order_by(Log.timestamp.desc())
+ .all()
+ )
+ if not logs:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND, detail="No logs found"
+ )
+ return logs
+
+
@router.get("/{log_id}", summary="Get a specific log")
async def get_log(
log_id: Annotated[int, Path(title="ID of log to delete")],
current_user: Annotated[User, Depends(get_current_user)],
db=Depends(get_db),
):
+ """
+ Get a specific log (given the log ID)
+ """
log = (
db.query(Log)
.filter(Log.id == log_id, Log.owner == current_user.id)
@@ -58,6 +96,9 @@ async def delete_log(
current_user: Annotated[User, Depends(get_current_user)],
db=Depends(get_db),
):
+ """
+ Delete a specific log (given the log ID)
+ """
log = (
db.query(Log)
.filter(Log.id == log_id, Log.owner == current_user.id)