1010
1111@router .get ("/prospects" )
1212def root () -> dict :
13- """Return a placeholder message for prospects endpoint."""
13+ """GET / prospects endpoint."""
1414 meta = make_meta ("success" , "Prospects placeholder" )
1515 data = {"init" : f"{ base_url } /prospects/init" }
1616 return {"meta" : meta , "data" : data }
1717
18-
19- # New endpoint: /prospects/init
20-
18+ # endpoint: /prospects/init
2119@router .get ("/prospects/init" )
2220def prospects_init () -> dict :
2321 """Initialize prospects and return real total count."""
24- meta = make_meta ("success" , "Initialized prospects" )
22+ meta = make_meta ("success" , "Init prospects" )
2523 conn_gen = get_db_connection ()
2624 conn = next (conn_gen )
2725 cur = conn .cursor ()
@@ -46,23 +44,29 @@ def slugify(text):
4644 return text .strip ('-' )
4745
4846 title = [
49- {"label" : f"{ t [0 ]} ({ t [1 ]} )" , "value" : slugify (t [0 ])} for t in title_rows if t [0 ] is not None
47+ {"label" : str (t [0 ]), "value" : slugify (t [0 ])}
48+ for t in title_rows
49+ if t [0 ] is not None and str (t [0 ]).strip () != "" and slugify (t [0 ]) != ""
5050 ]
5151 total_unique_title = len (title )
5252
5353 # Get unique seniority and their counts (column is 'seniority')
5454 cur .execute ('SELECT seniority, COUNT(*) FROM prospects WHERE seniority IS NOT NULL GROUP BY seniority ORDER BY COUNT(*) DESC;' )
5555 seniority_rows = cur .fetchall ()
5656 seniority = [
57- {"label" : f"{ s [0 ]} ({ s [1 ]} )" , "value" : slugify (s [0 ])} for s in seniority_rows if s [0 ] is not None
57+ {"label" : str (s [0 ]), "value" : slugify (s [0 ])}
58+ for s in seniority_rows
59+ if s [0 ] is not None and str (s [0 ]).strip () != "" and slugify (s [0 ]) != ""
5860 ]
5961 total_unique_seniority = len (seniority )
6062
6163 # Get unique sub_departments and their counts (column is 'sub_departments')
6264 cur .execute ('SELECT sub_departments, COUNT(*) FROM prospects WHERE sub_departments IS NOT NULL GROUP BY sub_departments ORDER BY COUNT(*) DESC;' )
6365 sub_department_rows = cur .fetchall ()
6466 sub_departments = [
65- {"label" : f"{ sd [0 ]} ({ sd [1 ]} )" , "value" : slugify (sd [0 ])} for sd in sub_department_rows if sd [0 ] is not None
67+ {"label" : str (sd [0 ]), "value" : slugify (sd [0 ])}
68+ for sd in sub_department_rows
69+ if sd [0 ] is not None and str (sd [0 ]).strip () != "" and slugify (sd [0 ]) != ""
6670 ]
6771 total_unique_sub_departments = len (sub_departments )
6872 except Exception :
@@ -77,18 +81,20 @@ def slugify(text):
7781 cur .close ()
7882 conn .close ()
7983 data = {
80- "total_prospects" : total ,
81- "title" : {
82- "total_unique" : total_unique_title ,
83- "values" : title [:3 ]
84- },
85- "seniority" : {
86- "total_unique" : total_unique_seniority ,
87- "values" : seniority [:3 ]
84+ "total" : total ,
85+ "groups" : {
86+ "level" : {
87+ "total" : total_unique_seniority ,
88+ "list" : seniority
89+ },
90+ "job" : {
91+ "total" : total_unique_title ,
92+ "list" : title
93+ },
94+ "lane" : {
95+ "total" : total_unique_sub_departments ,
96+ "list" : sub_departments
97+ }
8898 },
89- "departments" : {
90- "total_unique" : total_unique_sub_departments ,
91- "values" : sub_departments [:3 ]
92- }
9399 }
94100 return {"meta" : meta , "data" : data }
0 commit comments