From 48a0bc66f7388af6ca3bd04a0dcf585edd4001a2 Mon Sep 17 00:00:00 2001 From: OG T Date: Thu, 2 Apr 2026 09:04:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20KB=20=E9=A6=96=E5=B8=AD=E6=9E=B6?= =?UTF-8?q?=E6=A7=8B=E5=B8=AB=E5=AF=A9=E6=9F=A5=E4=BF=AE=E5=BE=A9=20(I1=20?= =?UTF-8?q?tags=20filter=20+=20I2=20type=20annotation)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - I1: Repository list_entries 實作 tags JSONB @> 篩選 (之前聲明未實作) - I2: ORM tags 型別從 list[dict[str, Any]] 修正為 list[str] 首席架構師審查: 87/100 C1 時區(UTC→Taipei) 為既有系統性問題,另開 task 統一遷移 Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/api/src/db/models.py | 4 ++-- apps/api/src/repositories/knowledge_repository.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/api/src/db/models.py b/apps/api/src/db/models.py index 90a13230..cee42a04 100644 --- a/apps/api/src/db/models.py +++ b/apps/api/src/db/models.py @@ -494,11 +494,11 @@ class KnowledgeEntryRecord(Base): nullable=False, comment="分類樹節點 (基礎設施/應用層/AI系統/安全合規)", ) - tags: Mapped[list[dict[str, Any]]] = mapped_column( + tags: Mapped[list[str]] = mapped_column( JSON, default=list, nullable=False, - comment="標籤列表 (JSONB)", + comment="標籤列表 (JSONB string array)", ) # Source & Status diff --git a/apps/api/src/repositories/knowledge_repository.py b/apps/api/src/repositories/knowledge_repository.py index b6526406..3844ebbf 100644 --- a/apps/api/src/repositories/knowledge_repository.py +++ b/apps/api/src/repositories/knowledge_repository.py @@ -115,6 +115,11 @@ class KnowledgeDBRepository: if status: query = query.where(KnowledgeEntryRecord.status == status) count_query = count_query.where(KnowledgeEntryRecord.status == status) + if tags: + for tag in tags: + tag_filter = KnowledgeEntryRecord.tags.op('@>')(f'["{tag}"]') + query = query.where(tag_filter) + count_query = count_query.where(tag_filter) if q: like_q = f"%{q}%" filter_cond = or_(