fix: classification results empty and res.data access issues
Backend: - Add GET /classifications/results endpoint with project/level/keyword filters - Add column relationship to ClassificationResult model - Fix test data generator to fetch column IDs from DB after bulk insert Frontend: - Fix request.ts interceptor to return full response body (keep total/pagination) - Fix all pages to use res.data instead of res - Add getClassificationResults API in classification.ts - Implement fetchData in Classification.vue with proper filtering and pagination - Fix same res.data issue in Category.vue, Metadata.vue, Project.vue, DataSource.vue, Dashboard.vue, Task.vue
This commit is contained in:
@@ -151,6 +151,54 @@ def list_templates(
|
||||
return ResponseModel(data=[TemplateOut.model_validate(i) for i in items])
|
||||
|
||||
|
||||
@router.get("/results", response_model=ListResponse)
|
||||
def list_results(
|
||||
project_id: Optional[int] = Query(None),
|
||||
level_id: Optional[int] = Query(None),
|
||||
keyword: Optional[str] = Query(None),
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=500),
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
from app.services.project_service import list_results as _list_results
|
||||
items, total = _list_results(db, project_id=project_id, keyword=keyword, page=page, page_size=page_size)
|
||||
|
||||
data = []
|
||||
for r in items:
|
||||
col = r.column
|
||||
table = col.table if col else None
|
||||
database = table.database if table else None
|
||||
source = database.source if database else None
|
||||
|
||||
# Filter by level_id if specified
|
||||
if level_id and r.level_id != level_id:
|
||||
continue
|
||||
|
||||
data.append({
|
||||
"id": r.id,
|
||||
"project_id": r.project_id,
|
||||
"column_id": col.id if col else None,
|
||||
"column_name": col.name if col else None,
|
||||
"data_type": col.data_type if col else None,
|
||||
"comment": col.comment if col else None,
|
||||
"table_name": table.name if table else None,
|
||||
"database_name": database.name if database else None,
|
||||
"source_name": source.name if source else None,
|
||||
"category_id": r.category_id,
|
||||
"category_name": r.category.name if r.category else None,
|
||||
"level_id": r.level_id,
|
||||
"level_name": r.level.name if r.level else None,
|
||||
"level_color": r.level.color if r.level else None,
|
||||
"source": r.source,
|
||||
"confidence": r.confidence,
|
||||
"status": r.status,
|
||||
"created_at": r.created_at.isoformat() if r.created_at else None,
|
||||
})
|
||||
|
||||
return ListResponse(data=data, total=total, page=page, page_size=page_size)
|
||||
|
||||
|
||||
@router.post("/auto-classify/{project_id}")
|
||||
def auto_classify(
|
||||
project_id: int,
|
||||
|
||||
@@ -92,6 +92,7 @@ class ClassificationResult(Base):
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
project = relationship("ClassificationProject", back_populates="results")
|
||||
column = relationship("DataColumn")
|
||||
category = relationship("Category")
|
||||
level = relationship("DataLevel")
|
||||
|
||||
|
||||
@@ -417,7 +417,9 @@ print(f" Created {len(projects)} projects")
|
||||
# ============================================================
|
||||
print("Generating classification results...")
|
||||
|
||||
all_col_ids = [c.id for c in all_columns]
|
||||
# Re-fetch column IDs from DB since bulk_save_objects doesn't populate object IDs
|
||||
col_rows = db.query(DataColumn.id).all()
|
||||
all_col_ids = [c[0] for c in col_rows]
|
||||
random.shuffle(all_col_ids)
|
||||
|
||||
result_batch = []
|
||||
|
||||
Reference in New Issue
Block a user