Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 15 additions & 2 deletions backend/app/api/routes/concept.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from fastapi import APIRouter, Body, Depends
from fastapi import APIRouter, Body, Depends, HTTPException
from odmantic import AIOEngine

from app import schemas
Expand All @@ -16,7 +16,14 @@ async def create_concept(
engine: AIOEngine = Depends(deps.engine_generator),
concept_in: schemas.ConceptCreate,
) -> Any:
concept = await crud_concept.create(engine, obj_in=concept_in)
# Check for duplicate concept name
duplicate = await crud_concept.get_by_name(engine, concept_in.name)
if duplicate:
raise HTTPException(
status_code=400, detail="Concept with this name already exists"
)

concept = await crud_concept.concept.create(engine, obj_in=concept_in)
return concept


Expand All @@ -36,6 +43,12 @@ async def update_concept(
engine: AIOEngine = Depends(deps.engine_generator),
concept_in: schemas.ConceptUpdate,
) -> Any:
# Check for duplicate concept name
duplicate = await crud_concept.get_by_name(engine, concept_in.name)
if duplicate and duplicate.id != concept_in.id:
raise HTTPException(
status_code=400, detail="Another concept with this name already exists."
)
db_obj = await crud_concept.get(engine, concept_in.id)
concept = await crud_concept.update(engine, db_obj=db_obj, obj_in=concept_in)
return concept
Expand Down
20 changes: 16 additions & 4 deletions backend/app/api/routes/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ async def delete_document(
return {"msg": "File deleted successfully."}


@router.post("/update", response_model=schemas.DocumentBase)
async def update_document(
*,
engine: AIOEngine = Depends(deps.engine_generator),
document_in: schemas.DocumentUpdate,
) -> Any:
document = await crud_document.get(engine, document_in.id)
if not document:
raise HTTPException(status_code=404, detail="Document not found")
updated_document = await crud_document.update(
engine, db_obj=document, obj_in=document_in
)
return updated_document


@router.post("/process", response_model=schemas.Msg)
async def process_document(
*,
Expand Down Expand Up @@ -212,14 +227,11 @@ async def get_document_metadata(
engine: AIOEngine = Depends(deps.engine_generator),
) -> Any:
"""Get document metadata including annotations and concepts"""
document, annotations, concepts = await crud_document.get_with_related(
engine, document_id
)
document, annotations = await crud_document.get_with_related(engine, document_id)
if document is None:
raise HTTPException(status_code=404, detail="Document not found")

return {
"document": document,
"annotations": annotations,
"concepts": concepts,
}
4 changes: 4 additions & 0 deletions backend/app/crud/crud_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@


class CRUDConcept(CRUDBase[Concept, ConceptCreate, ConceptUpdate]):
async def get_by_name(self, engine: AIOEngine, name: str) -> Concept | None:
# Check if a concept with the given name already exists
return await engine.find_one(Concept, Concept.name == name)

async def delete(self, engine: AIOEngine, id: str) -> Concept:
concept = await super().delete(engine, id=id)

Expand Down
11 changes: 2 additions & 9 deletions backend/app/crud/crud_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def create(self, engine: AIOEngine, obj_in: DocumentCreate) -> Document:

async def get_with_related(
self, engine: AIOEngine, id: str
) -> tuple[Document | None, list[Annotation], list[Concept]]:
) -> tuple[Document | None, list[Annotation]]:
"""
Retrieves a document by its file_id along with its associated annotations and concepts.
"""
Expand All @@ -64,14 +64,7 @@ async def get_with_related(
# Retrieve annotations associated with this document using get_multi for consistency.
annotations = await crud_annotation.get_multi(engine, {"file_id": id})

# Extract annotation IDs.
annotation_ids = [annotation.id for annotation in annotations]

# Retrieve concepts linked to the annotations using get_multi.
concepts = await crud_concept.get_multi(
engine, {"annotation_ids": {"$in": annotation_ids}}
)
return document, annotations, concepts
return document, annotations

async def delete(self, engine: AIOEngine, id: str) -> Document:
document = await super().delete(engine, id=id)
Expand Down
1 change: 1 addition & 0 deletions backend/app/schemas/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DocumentCreate(BaseModel):


class DocumentUpdate(BaseModel):
id: str
name: str = None
metadata: dict[str, Any] | None = None
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
Expand Down
2 changes: 1 addition & 1 deletion frontend/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ app.on('activate', () => {
} else {
createWindow()
}
})
});

// New window example arg: new windows url
ipcMain.handle('open-win', (_, arg) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/public/pdf.js/external/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmaps/
1 change: 1 addition & 0 deletions frontend/public/pdf.js/external/bcmaps/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* binary
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/78-H.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/78-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/Add-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/B5-H.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/B5-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/B5pc-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/CNS1-H.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/CNS1-V.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/CNS2-H.bcmap
Binary file not shown.
3 changes: 3 additions & 0 deletions frontend/public/pdf.js/external/bcmaps/CNS2-V.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE�CNS2-H
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions frontend/public/pdf.js/external/bcmaps/ETenms-B5-H.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE� ETen-B5-H` ^
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/EUC-H.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/EUC-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/Ext-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions frontend/public/pdf.js/external/bcmaps/GB-H.bcmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
�RCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE!!��]aX!!]`�21�> �p �z�$]��"R�d�-U�7�*�4�%�+ �Z �{�/�%�<�9K�b�1]�.�"� �`]�,�"]�
�"]�h�"]�F�"]�$�"]��"]�`�"]�>�"]��"]�z�"]�X�"]�6�"]��"]�r�"]�P�"]�.�"]� �"]�j�"]�H�"]�&�"]��"]�b�"]�@�"]��"]�|�"]�Z�"]�8�"]��"]�t�"]�R�"]�0�"]��"]�l�"]�J�"]�(�"]��"]�d�"]�B�"]� �"X�~�']�W�"]�5�"]��"]�q�"]�O�"]�-�"]� �"]�i�"]�G�"]�%�"]��"]�a�"]�?�"]��"]�{�"]�Y�"]�7�"]��"]�s�"]�Q�"]�/�"]��"]�k�"]�I�"]�'�"]��"]�c�"]�A�"]��"]�}�"]�[�"]�9
Expand Down
Binary file added frontend/public/pdf.js/external/bcmaps/GB-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/GBK2K-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/GBT-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/H.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/Hankaku.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/KSC-V.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions frontend/public/pdf.js/external/bcmaps/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%%Copyright: -----------------------------------------------------------
%%Copyright: Copyright 1990-2009 Adobe Systems Incorporated.
%%Copyright: All rights reserved.
%%Copyright:
%%Copyright: Redistribution and use in source and binary forms, with or
%%Copyright: without modification, are permitted provided that the
%%Copyright: following conditions are met:
%%Copyright:
%%Copyright: Redistributions of source code must retain the above
%%Copyright: copyright notice, this list of conditions and the following
%%Copyright: disclaimer.
%%Copyright:
%%Copyright: Redistributions in binary form must reproduce the above
%%Copyright: copyright notice, this list of conditions and the following
%%Copyright: disclaimer in the documentation and/or other materials
%%Copyright: provided with the distribution.
%%Copyright:
%%Copyright: Neither the name of Adobe Systems Incorporated nor the names
%%Copyright: of its contributors may be used to endorse or promote
%%Copyright: products derived from this software without specific prior
%%Copyright: written permission.
%%Copyright:
%%Copyright: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
%%Copyright: CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
%%Copyright: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
%%Copyright: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
%%Copyright: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
%%Copyright: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
%%Copyright: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
%%Copyright: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
%%Copyright: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
%%Copyright: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%%Copyright: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
%%Copyright: OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
%%Copyright: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%%Copyright: -----------------------------------------------------------
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/NWP-V.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/RKSJ-H.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/RKSJ-V.bcmap
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/Roman.bcmap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added frontend/public/pdf.js/external/bcmaps/V.bcmap
Binary file not shown.
Binary file not shown.
Loading