From 6494cee2d0f96300958393eaa8564224721969e7 Mon Sep 17 00:00:00 2001 From: dextmorgn Date: Mon, 16 Feb 2026 09:16:05 +0100 Subject: [PATCH] feat(api): update key service --- flowsint-api/app/api/routes/keys.py | 38 +++++++++++++++++++++-------- flowsint-api/app/api/routes/scan.py | 21 +++++++++------- flowsint-api/app/api/schemas/key.py | 12 ++++++--- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/flowsint-api/app/api/routes/keys.py b/flowsint-api/app/api/routes/keys.py index 256a898..6c09085 100644 --- a/flowsint-api/app/api/routes/keys.py +++ b/flowsint-api/app/api/routes/keys.py @@ -1,17 +1,18 @@ -from uuid import UUID -from fastapi import APIRouter, HTTPException, Depends, status from typing import List +from uuid import UUID + +from fastapi import APIRouter, Depends, HTTPException, status +from flowsint_core.core.models import Profile +from flowsint_core.core.postgre_db import get_db +from flowsint_core.core.services import ( + DatabaseError, + NotFoundError, + create_key_service, +) from sqlalchemy.orm import Session -from flowsint_core.core.services import ( - create_key_service, - NotFoundError, - DatabaseError, -) -from flowsint_core.core.postgre_db import get_db -from flowsint_core.core.models import Profile from app.api.deps import get_current_user -from app.api.schemas.key import KeyRead, KeyCreate +from app.api.schemas.key import KeyCreate, KeyExists, KeyRead router = APIRouter() @@ -33,6 +34,23 @@ def get_keys( ] +@router.get("/chat-key-exists", response_model=KeyExists) +def chat_key_exists( + db: Session = Depends(get_db), + current_user: Profile = Depends(get_current_user), +): + """ + A simple util route to know if any ai chat key exists in the vault for this user + """ + service = create_key_service(db) + try: + key_exists = service.chat_key_exist(current_user.id) + return KeyExists(exists=key_exists) + except NotFoundError as e: + print(e) + return KeyExists(exists=False) + + @router.get("/{id}", response_model=KeyRead) def get_key_by_id( id: UUID, diff --git a/flowsint-api/app/api/routes/scan.py b/flowsint-api/app/api/routes/scan.py index 43df0d2..7323290 100644 --- a/flowsint-api/app/api/routes/scan.py +++ b/flowsint-api/app/api/routes/scan.py @@ -1,28 +1,31 @@ -from uuid import UUID -from fastapi import APIRouter, HTTPException, Depends, status from typing import List -from sqlalchemy.orm import Session +from uuid import UUID -from flowsint_core.core.postgre_db import get_db +from fastapi import APIRouter, Depends, HTTPException, status from flowsint_core.core.models import Profile +from flowsint_core.core.postgre_db import get_db from flowsint_core.core.services import ( - create_scan_service, NotFoundError, PermissionDeniedError, + create_scan_service, ) +from sqlalchemy.orm import Session + from app.api.deps import get_current_user from app.api.schemas.scan import ScanRead router = APIRouter() -@router.get("", response_model=List[ScanRead]) +@router.get("/sketch/{id}", response_model=List[ScanRead]) def get_scans( - db: Session = Depends(get_db), current_user: Profile = Depends(get_current_user) + id: UUID, + db: Session = Depends(get_db), + current_user: Profile = Depends(get_current_user), ): - """Get all scans accessible to the current user.""" + """Get all scans accessible to the current user, linked to a sketch.""" service = create_scan_service(db) - return service.get_accessible_scans(current_user.id) + return service.get_accessible_scans_by_sketch_id(current_user.id, id) @router.get("/{id}", response_model=ScanRead) diff --git a/flowsint-api/app/api/schemas/key.py b/flowsint-api/app/api/schemas/key.py index 3878501..23cd178 100644 --- a/flowsint-api/app/api/schemas/key.py +++ b/flowsint-api/app/api/schemas/key.py @@ -1,7 +1,9 @@ -from .base import ORMBase -from pydantic import UUID4, BaseModel from datetime import datetime +from pydantic import UUID4, BaseModel + +from .base import ORMBase + class KeyCreate(BaseModel): key: str @@ -12,4 +14,8 @@ class KeyRead(ORMBase): id: UUID4 owner_id: UUID4 name: str - created_at: datetime + created_at: datetime | str + + +class KeyExists(BaseModel): + exists: bool