1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 23:05:10 +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: if system_key != settings.system_key:
raise HTTPException(status_code=404) 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 return users
@@ -159,7 +160,7 @@ async def list_bookmarks(
offset: int = 0, offset: int = 0,
limit: Annotated[int, Query(le=10000)] = 100, limit: Annotated[int, Query(le=10000)] = 100,
) -> list[Bookmark]: ) -> 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( result = await session.exec(
select(Bookmark) select(Bookmark)
.where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED) .where(Bookmark.user_key == user_key, Bookmark.status != Visibility.DELETED)
@@ -183,7 +184,6 @@ async def get_bookmark(
) )
) )
bookmark = result.first() bookmark = result.first()
# bookmark = session.get(Bookmark, {'url_hash': url_hash, 'userkey': user_key})
return bookmark return bookmark
@@ -279,13 +279,13 @@ async def delete_bookmark(
url_hash: str, url_hash: str,
): ):
"""(Soft)Delete bookmark `bookmark_key` for user `user_key`.""" """(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 bookmark = result
if not bookmark: if not bookmark:
raise HTTPException(status_code=404, detail='Bookmark not found') raise HTTPException(status_code=404, detail='Bookmark not found')
bookmark.deleted_date = datetime.now(UTC) bookmark.deleted_date = datetime.now(UTC)
bookmark.status = Visibility.DELETED bookmark.status = Visibility.DELETED
await session.add(bookmark) session.add(bookmark)
await session.commit() await session.commit()
return {'ok': True} return {'ok': True}
@@ -332,11 +332,11 @@ async def list_tags_for_user(
tags = [] tags = []
for bookmark in bookmarks: for bookmark in bookmarks:
tags += bookmark.tag_list tags += bookmark.tag_list
return tags.clean_tags(tags) return tags_helpers.clean_tags(tags)
@app.get('/api/v1/{user_key}/tags/{tag_key}') @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, session: SessionDep,
user_key: str, user_key: str,
) -> list[str]: ) -> list[str]:

View File

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