Skip to content

Commit cff88c5

Browse files
committed
fix: deserialize JSON fields in list_applications endpoint
The GET /api/applications endpoint was returning raw database objects without deserializing the generated_cv and skills_gap_report fields, causing "JSON.parse: unexpected character" errors on the frontend when viewing existing applications. Now properly deserializes these fields before returning to match the behavior of the POST endpoint.
1 parent 8fb3779 commit cff88c5

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

main.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,38 @@ def list_applications(
687687
status: Optional[str] = None,
688688
db: Session = Depends(get_db)
689689
):
690-
"""List applications with optional status filter"""
691690
query = db.query(JobApplication)
692-
691+
693692
if status:
694693
try:
695694
query = query.filter(JobApplication.status == ApplicationStatus(status))
696695
except ValueError:
697-
pass # Invalid status, ignore filter
698-
699-
return query.order_by(desc(JobApplication.created_at)).all()
696+
pass
697+
698+
apps = query.order_by(desc(JobApplication.created_at)).all()
699+
700+
# Deserialize generated_cv for each application
701+
result = []
702+
for app in apps:
703+
cv_for_response = json.loads(app.generated_cv) if isinstance(app.generated_cv, str) else app.generated_cv
704+
skills_gap_for_response = json.loads(app.skills_gap_report) if isinstance(app.skills_gap_report, str) else app.skills_gap_report
705+
706+
result.append(JobApplicationResponse(
707+
id=app.id,
708+
company_name=app.company_name,
709+
job_title=app.job_title,
710+
generated_cv=cv_for_response,
711+
generated_cover_letter=app.generated_cover_letter,
712+
skills_gap_report=skills_gap_for_response,
713+
status=app.status,
714+
notes=app.notes,
715+
applied_date=app.applied_date,
716+
created_at=app.created_at,
717+
cv_docx_path=None,
718+
cover_letter_docx_path=None
719+
))
720+
721+
return result
700722

701723
# Download endpoints for Word documents
702724
@app.get("/api/download/cv/{application_id}",

0 commit comments

Comments
 (0)