mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 20:12:55 +01:00
Added apis for documents update and user checker mode
This commit is contained in:
parent
f011bb6a7a
commit
e2bad96854
13 changed files with 229 additions and 59 deletions
|
|
@ -1,6 +1,9 @@
|
|||
from sqlalchemy import or_, and_
|
||||
from sqlalchemy.orm import Session
|
||||
from private_gpt.users.schemas.documents import DocumentCreate, DocumentUpdate
|
||||
from private_gpt.users.models.document import Document
|
||||
from private_gpt.users.models.department import Department
|
||||
from private_gpt.users.models.document_department import document_department_association
|
||||
from private_gpt.users.crud.base import CRUDBase
|
||||
from typing import Optional, List
|
||||
|
||||
|
|
@ -23,4 +26,44 @@ class CRUDDocuments(CRUDBase[Document, DocumentCreate, DocumentUpdate]):
|
|||
.all()
|
||||
)
|
||||
|
||||
def get_documents_by_departments(
|
||||
self, db: Session, *, department_id: int, skip: int = 0, limit: int = 100
|
||||
) -> List[Document]:
|
||||
return (
|
||||
db.query(self.model)
|
||||
.join(document_department_association)
|
||||
.join(Department)
|
||||
.filter(document_department_association.c.department_id == department_id)
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
def get_enabled_documents_by_departments(
|
||||
self, db: Session, *, department_id: int, skip: int = 0, limit: int = 100
|
||||
) -> List[Document]:
|
||||
all_department_id = 4 # department ID for "ALL" is 4
|
||||
|
||||
return (
|
||||
db.query(self.model)
|
||||
.join(document_department_association)
|
||||
.join(Department)
|
||||
.filter(
|
||||
or_(
|
||||
and_(
|
||||
document_department_association.c.department_id == department_id,
|
||||
Document.is_enabled == True,
|
||||
),
|
||||
and_(
|
||||
document_department_association.c.department_id == all_department_id,
|
||||
Document.is_enabled == True,
|
||||
),
|
||||
)
|
||||
)
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
documents = CRUDDocuments(Document)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue