Merged in feature/textExtractionsPart3 (pull request #195)
enrich doc responses * enrich doc responses
This commit is contained in:
+51
-8
@@ -70,21 +70,64 @@ func (s *Controllers) RenameFolder(ctx echo.Context, folderId openapi_types.UUID
|
||||
return ctx.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// GetFolderDocuments retrieves all documents in a specific folder.
|
||||
// GetFolderDocuments retrieves all documents in a specific folder with enriched metadata.
|
||||
// GET /folders/{folderId}/documents
|
||||
// Returns a list of documents in the specified folder.
|
||||
func (s *Controllers) GetFolderDocuments(ctx echo.Context, folderId openapi_types.UUID) error {
|
||||
documents, err := s.svc.Folder.GetDocumentsByFolder(ctx.Request().Context(), uuid.UUID(folderId))
|
||||
// Parameters:
|
||||
// - folderId: UUID of the folder
|
||||
// - params: Query parameters including optional textRecord flag
|
||||
//
|
||||
// When textRecord=true, includes the full field extraction response for each document.
|
||||
// Returns a list of DocumentInFolder objects (lighter format excluding client_id and computed fields).
|
||||
func (s *Controllers) GetFolderDocuments(ctx echo.Context, folderId openapi_types.UUID, params GetFolderDocumentsParams) error {
|
||||
includeTextRecord := params.TextRecord != nil && *params.TextRecord
|
||||
|
||||
documents, err := s.svc.Folder.GetDocumentsEnriched(ctx.Request().Context(), uuid.UUID(folderId), includeTextRecord)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
// Convert to API response format
|
||||
apiDocs := make([]DocumentSummary, len(documents))
|
||||
apiDocs := make([]DocumentInFolder, len(documents))
|
||||
for i, doc := range documents {
|
||||
apiDocs[i] = DocumentSummary{
|
||||
Hash: doc.Hash,
|
||||
Id: openapi_types.UUID(doc.ID),
|
||||
// Convert labels to API format
|
||||
labels := make([]LabelRecord, len(doc.Labels))
|
||||
for j, lbl := range doc.Labels {
|
||||
labels[j] = LabelRecord{
|
||||
Id: openapi_types.UUID(lbl.ID),
|
||||
DocumentId: DocumentID(lbl.DocumentID),
|
||||
Label: lbl.Label,
|
||||
AppliedBy: openapi_types.Email(lbl.AppliedBy),
|
||||
AppliedAt: lbl.AppliedAt,
|
||||
}
|
||||
}
|
||||
|
||||
apiDocs[i] = DocumentInFolder{
|
||||
Id: DocumentID(doc.ID),
|
||||
Hash: Hash(doc.Hash),
|
||||
HasTextRecord: doc.HasTextRecord,
|
||||
Labels: labels,
|
||||
}
|
||||
|
||||
if doc.FolderID != nil {
|
||||
apiDocs[i].FolderId = (*openapi_types.UUID)(doc.FolderID)
|
||||
}
|
||||
if doc.Filename != nil {
|
||||
apiDocs[i].Filename = doc.Filename
|
||||
}
|
||||
if doc.OriginalPath != nil {
|
||||
apiDocs[i].OriginalPath = doc.OriginalPath
|
||||
}
|
||||
|
||||
// Include text record if available
|
||||
if doc.TextRecord != nil {
|
||||
current, ok := doc.TextRecord.SingleFields.(*repository.Currentfieldextraction)
|
||||
if ok && current != nil {
|
||||
arrayFields, ok := doc.TextRecord.ArrayFields.([]*repository.Documentfieldextractionarrayfield)
|
||||
if ok {
|
||||
textRecord := buildFieldExtractionResponse(current, arrayFields)
|
||||
apiDocs[i].TextRecord = textRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user