1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 22:05:09 +01:00
This commit is contained in:
2025-09-12 23:01:35 +02:00
parent 3cf322ac29
commit a887d93c8f
2 changed files with 11 additions and 9 deletions

View File

@@ -148,7 +148,8 @@ async def list_users(
if system_key != settings.system_key:
raise HTTPException(status_code=404)
users = session.exec(select(User).offset(offset).limit(limit)).all()
result = await session.exec(select(User).offset(offset).limit(limit))
users = result.all()
return users
@@ -159,7 +160,7 @@ async def list_bookmarks(
offset: int = 0,
limit: Annotated[int, Query(le=10000)] = 100,
) -> list[Bookmark]:
"""List all bookmarks in the database. By default 100 items are returned."""
"""List all bookmarks in the database. By default, 100 items are returned."""
result = await session.exec(
select(Bookmark)
.where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
@@ -183,7 +184,6 @@ async def get_bookmark(
)
)
bookmark = result.first()
# bookmark = session.get(Bookmark, {'url_hash': url_hash, 'userkey': user_key})
return bookmark
@@ -279,13 +279,13 @@ async def delete_bookmark(
url_hash: str,
):
"""(Soft)Delete bookmark `bookmark_key` for user `user_key`."""
result = await session.get(Bookmark, {'url_hash': url_hash, 'userkey': user_key})
result = await session.get(Bookmark, {'url_hash': url_hash, 'user_key': user_key})
bookmark = result
if not bookmark:
raise HTTPException(status_code=404, detail='Bookmark not found')
bookmark.deleted_date = datetime.now(UTC)
bookmark.status = Visibility.DELETED
await session.add(bookmark)
session.add(bookmark)
await session.commit()
return {'ok': True}
@@ -332,11 +332,11 @@ async def list_tags_for_user(
tags = []
for bookmark in bookmarks:
tags += bookmark.tag_list
return tags.clean_tags(tags)
return tags_helpers.clean_tags(tags)
@app.get('/api/v1/{user_key}/tags/{tag_key}')
async def list_tags_for_user(
async def list_bookmarks_for_tag_for_user(
session: SessionDep,
user_key: str,
) -> list[str]:

View File

@@ -1,5 +1,7 @@
"""Helper functions for tags used with Bookmark models."""
from sqlalchemy import Sequence
from src.digimarks.models import Bookmark
@@ -35,7 +37,7 @@ def unique_ever_seen(iterable, key=None):
yield element
def clean_tags(tags_list: list) -> list:
def clean_tags(tags_list: list) -> list[str]:
"""Generate a unique list of the tags.
:param list tags_list: List with all tags
@@ -50,7 +52,7 @@ def clean_tags(tags_list: list) -> list:
return tags_res
def list_tags_for_bookmarks(bookmarks: list) -> list:
def list_tags_for_bookmarks(bookmarks: Sequence[Bookmark]) -> list[str]:
"""Generate a unique list of the tags from the list of bookmarks."""
tags = []
for bookmark in bookmarks: