mirror of
https://github.com/reconurge/flowsint.git
synced 2026-07-17 09:33:16 -05:00
feat(api): update key service
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user