diff --git a/backend/app/api/sources.py b/backend/app/api/sources.py index a9c314b..8e5eb99 100644 --- a/backend/app/api/sources.py +++ b/backend/app/api/sources.py @@ -4,11 +4,11 @@ from quart import Blueprint, jsonify, request from ..extensions import get_session from ..services.source_service import ( + KNOWN_PLATFORMS, ArtistNotFoundError, DuplicateSourceError, EmptyUrlError, InvalidConfigError, - KNOWN_PLATFORMS, SourceService, UnknownPlatformError, ) diff --git a/backend/app/services/artist_service.py b/backend/app/services/artist_service.py index eea7afb..271778e 100644 --- a/backend/app/services/artist_service.py +++ b/backend/app/services/artist_service.py @@ -8,7 +8,7 @@ Dates come from Post.post_date via ImageProvenance.post_id. from dataclasses import dataclass -from sqlalchemy import and_, func, or_, select +from sqlalchemy import and_, case, func, or_, select from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.asyncio import AsyncSession @@ -228,7 +228,7 @@ class ArtistService: like = f"%{cleaned.lower()}%" prefix_like = f"{cleaned.lower()}%" # Rank: exact (0) < prefix (1) < substring (2). - rank = func.case( + rank = case( (func.lower(Artist.name) == cleaned.lower(), 0), (func.lower(Artist.name).like(prefix_like), 1), else_=2, diff --git a/backend/app/services/source_service.py b/backend/app/services/source_service.py index 62d88ac..90ce41d 100644 --- a/backend/app/services/source_service.py +++ b/backend/app/services/source_service.py @@ -10,7 +10,6 @@ from sqlalchemy.ext.asyncio import AsyncSession from ..models import Artist, Source - # App-level allowlist (frozenset to make accidental mutation loud). KNOWN_PLATFORMS: frozenset[str] = frozenset({ "patreon", "fanbox", "subscribestar", "pixiv", "deviantart", diff --git a/tests/test_source_service.py b/tests/test_source_service.py index 72e070f..65e8336 100644 --- a/tests/test_source_service.py +++ b/tests/test_source_service.py @@ -3,11 +3,11 @@ from sqlalchemy import select from backend.app.models import Artist from backend.app.services.source_service import ( + KNOWN_PLATFORMS, ArtistNotFoundError, DuplicateSourceError, EmptyUrlError, InvalidConfigError, - KNOWN_PLATFORMS, SourceService, UnknownPlatformError, )