eyecandy and delete
This commit is contained in:
@@ -5,7 +5,7 @@ from fastapi import APIRouter, Header, HTTPException, status
|
||||
import logging
|
||||
from pydantic import BaseModel
|
||||
|
||||
from backend.app.services.link_service import create_link, list_public_links, list_tags, update_link
|
||||
from backend.app.services.link_service import create_link, delete_link, list_public_links, list_tags, update_link
|
||||
from backend.app.services.plugin_manager import plugin_manager
|
||||
from backend.app.services.token_service import validate_token
|
||||
|
||||
@@ -73,6 +73,21 @@ def update_link_endpoint(
|
||||
return record
|
||||
|
||||
|
||||
@router.delete('/links/{link_id}')
|
||||
def delete_link_endpoint(
|
||||
link_id: str,
|
||||
authorization: str | None = Header(default=None),
|
||||
):
|
||||
if not authorization or not authorization.startswith('Bearer '):
|
||||
raise HTTPException(status_code=401, detail='Missing or invalid Authorization header')
|
||||
info = validate_token(authorization.replace('Bearer ', '', 1))
|
||||
if info is None:
|
||||
raise HTTPException(status_code=401, detail='Token expired or invalid')
|
||||
if not delete_link(link_id, info['user_id']):
|
||||
raise HTTPException(status_code=404, detail='Link not found or not owned by user')
|
||||
return {'status': 'deleted', 'id': link_id}
|
||||
|
||||
|
||||
@router.get('/links')
|
||||
def list_links():
|
||||
return list_public_links()
|
||||
|
||||
@@ -157,6 +157,16 @@ def update_link(
|
||||
return record
|
||||
|
||||
|
||||
def delete_link(link_id: str, user_id: str) -> bool:
|
||||
with get_connection() as conn:
|
||||
cursor = conn.execute(
|
||||
'DELETE FROM links WHERE id = ? AND user_id = ?',
|
||||
(link_id, user_id),
|
||||
)
|
||||
conn.commit()
|
||||
return cursor.rowcount > 0
|
||||
|
||||
|
||||
def list_public_users():
|
||||
with get_connection() as conn:
|
||||
rows = conn.execute(
|
||||
|
||||
Reference in New Issue
Block a user