|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -"""Chat-collection management service moved to the conversation domain |
16 | | -in Phase 5 step 5-S4f. |
17 | | -
|
18 | | -Phase 4 ``#1633`` + Phase 3 ``#1629`` are merged on main, so the |
19 | | -cross-domain ORM imports take the β canonical path from |
20 | | -``msg=4ed698d8`` — direct domain-to-domain imports of ``User`` / |
21 | | -``Collection`` + sibling domain services, no stopgap Protocol + DI |
22 | | -wrapper: |
23 | | -
|
24 | | -* ``aperag.db.models.User`` → ``aperag.domains.identity.db.models.User`` |
25 | | -* ``aperag.db.models.Collection`` → |
26 | | - ``aperag.domains.knowledge_base.db.models.Collection`` |
27 | | -* ``aperag.schema.view_models.CollectionConfig / ModelSpec / |
28 | | - TagFilterCondition / TagFilterRequest`` → ``aperag.schema.common`` |
29 | | - for the first two and |
30 | | - ``aperag.domains.model_platform.schemas`` for the tag filters. |
31 | | -* ``aperag.service.collection_service`` → |
32 | | - ``aperag.domains.knowledge_base.service.collection_service`` |
33 | | -* ``aperag.service.llm_available_model_service`` → |
34 | | - ``aperag.domains.model_platform.service.llm_available_model_service`` |
35 | | -
|
36 | | -The pre-move ``KnowledgeBaseCollectionView`` return type (from |
37 | | -``aperag.domains.conversation.ports``) is kept — the Protocol was |
38 | | -established in Phase 3 Step 5c for exactly this module, and there is |
39 | | -no benefit in swapping it for the concrete ``Collection`` class here. |
40 | | -
|
41 | | -The ``_mark_as_chat_collection`` transaction closure uses |
42 | | -``session.get(Collection, ...)`` — Collection is now imported from the |
43 | | -knowledge_base domain, which G1 permits. The ``User.chat_collection_id`` |
44 | | -update is issued via ``sqlalchemy.text`` rather than ``session.get(User, |
45 | | -...)`` + attribute assignment so the conversation domain does not have |
46 | | -to import the identity-owned ``User`` ORM class (G16 canonical per |
47 | | -``msg=6d2ae86a`` forbids ``User`` imports outside the identity domain). |
48 | | -The raw UPDATE hits the same ``users`` table that the ORM mapper binds |
49 | | -to, so the transaction semantics are identical. |
| 15 | +"""Chat-collection management service in the conversation domain. |
| 16 | +
|
| 17 | +Cross-domain dependencies are direct imports: |
| 18 | +
|
| 19 | +* ``aperag.domains.identity.db.models.User`` is **not** imported here — |
| 20 | + ``User.chat_collection_id`` writes travel through the identity-owned |
| 21 | + ``set_chat_collection`` facade (lesson 9a-sexdec hierarchy-1) so G16 |
| 22 | + stays green without the conversation domain leaking the ``User`` ORM. |
| 23 | +* ``aperag.domains.knowledge_base.db.models.Collection`` is imported |
| 24 | + directly (domain→domain is legal under G1). |
| 25 | +* ``aperag.domains.knowledge_base.service.collection_service`` + the |
| 26 | + ``model_platform`` availability service similarly sibling-import. |
| 27 | +
|
| 28 | +The pre-move ``KnowledgeBaseCollectionView`` return type is kept — |
| 29 | +the Protocol was established in Phase 3 Step 5c for exactly this |
| 30 | +module, and there is no benefit in swapping it for the concrete |
| 31 | +``Collection`` class here. |
50 | 32 | """ |
51 | 33 |
|
52 | 34 | from __future__ import annotations |
53 | 35 |
|
54 | 36 | import logging |
55 | 37 | from typing import Optional |
56 | 38 |
|
57 | | -from sqlalchemy import text |
58 | | - |
59 | 39 | from aperag.db.ops import async_db_ops |
60 | 40 | from aperag.domains.conversation.ports import KnowledgeBaseCollectionView |
| 41 | +from aperag.domains.identity.service.identity_user_ops import set_chat_collection as identity_set_chat_collection |
61 | 42 | from aperag.domains.knowledge_base.db.models import Collection |
62 | 43 | from aperag.domains.knowledge_base.schemas import CollectionCreate |
63 | 44 | from aperag.domains.knowledge_base.service.collection_service import collection_service |
@@ -172,13 +153,7 @@ async def _mark_as_chat_collection(session): |
172 | 153 | session.add(collection_obj) |
173 | 154 | await session.flush() |
174 | 155 |
|
175 | | - # Update User.chat_collection_id via raw SQL so this module |
176 | | - # does not have to import the identity-owned ``User`` ORM |
177 | | - # class (G16 canonical). |
178 | | - await session.execute( |
179 | | - text("UPDATE users SET chat_collection_id = :cid WHERE id = :uid"), |
180 | | - {"cid": collection_response.id, "uid": user_id}, |
181 | | - ) |
| 156 | + await identity_set_chat_collection(session, user_id, collection_response.id) |
182 | 157 | await session.flush() |
183 | 158 |
|
184 | 159 | await self.db_ops.execute_with_transaction(_mark_as_chat_collection) |
|
0 commit comments