@@ -111,10 +111,21 @@ async def submit_username(
111111 except Exception as e :
112112 return JSONResponse (status_code = 500 , content = f"Internal Server Error: { str (e )} " )
113113
114+ SUBDOMAIN_MAPPING = {
115+ "WEB" : "Technical" ,
116+ "APP" : "Technical" ,
117+ "AI/ML" : "Technical" ,
118+ "IOT" : "Technical" ,
119+ "PNM" : "Management" ,
120+ "EVENTS" : "Management" ,
121+ "UI/UX" : "Design" ,
122+ "GRAPHIC DESIGN" : "Design" ,
123+ "VIDEO EDITING" : "Design"
124+ }
114125@user .get ("/dashboard" )
115126async def get_dashboard (
116- round : int = Query (..., description = "Round number" ),
117- authorization : str = Depends (get_access_token ),
127+ round : int = Query (..., description = "Round number" ),
128+ authorization : str = Depends (get_access_token ),
118129 resources : dict = Depends (get_resources )
119130):
120131 try :
@@ -126,38 +137,38 @@ async def get_dashboard(
126137 except Exception as token_error :
127138 raise HTTPException (status_code = 401 , detail = f"Invalid token: { str (token_error )} " )
128139
129- email = decoded_token .get (' email' )
140+ email = decoded_token .get (" email" )
130141 if not email :
131142 raise HTTPException (status_code = 400 , detail = "Email not found in ID token" )
132143
133144 try :
134145 user_table = resources .get ("user_table" )
135- response = user_table .get_item (Key = {'uid' : email })
136- user = response .get ('Item' )
137- if not user :
138- raise HTTPException (status_code = 404 , detail = "User not found" )
146+ response = user_table .get_item (Key = {"uid" : email })
147+ user = response .get ("Item" , {})
148+
139149 except Exception as db_error :
140150 raise HTTPException (status_code = 500 , detail = f"Database lookup failed: { str (db_error )} " )
141151
142- all_domains = user .get ('domain' , None )
143- completed_domains = user .get (f'round{ round } ' , None )
144-
145- if all_domains is None :
146- raise HTTPException (status_code = 400 , detail = "Domains not found in user data" )
147- if completed_domains is None :
148- completed_domains = {}
152+ domain_data = user .get ("domain" , {}) # Dictionary of domains and their subdomains
153+ completed_subdomains = set (user .get (f"round{ round } " , [])) # Subdomains completed in the round
149154
155+ pending_list = []
156+ completed_list = []
150157
151- pending = defaultdict (list )
152- for domain , subdomains in all_domains .items ():
153- completed_subs = set (completed_domains .get (domain , []))
158+ for domain , subdomains in domain_data .items ():
154159 for sub in subdomains :
155- if sub not in completed_subs :
156- pending [domain ].append (sub )
157-
158- pending = dict (pending )
159-
160- return JSONResponse (status_code = 200 , content = pending )
161-
160+ category = SUBDOMAIN_MAPPING .get (sub .upper (), "Other" )
161+ formatted_entry = f"{ category } :{ sub .upper ()} "
162+
163+ if sub .upper () in completed_subdomains :
164+ completed_list .append (formatted_entry )
165+ else :
166+ pending_list .append (formatted_entry )
167+
168+ return JSONResponse (status_code = 200 , content = {
169+ "pending" : pending_list ,
170+ "completed" : completed_list
171+ })
172+
162173 except Exception as unexpected_error :
163- raise HTTPException (status_code = 500 , detail = f"Unexpected server error: { str (unexpected_error )} " )
174+ raise HTTPException (status_code = 500 , detail = f"Unexpected server error: { str (unexpected_error )} " )
0 commit comments