66import officers .crud
77from dependencies import LoggedInUser , SessionUser , perm_admin
88from officers .models import (
9+ Officer ,
910 OfficerCreate ,
1011 OfficerInfo ,
11- OfficerPrivate ,
12- OfficerPublic ,
1312 OfficerTerm ,
1413 OfficerTermUpdate ,
1514 OfficerUpdate ,
@@ -54,7 +53,7 @@ async def _has_officer_private_info_access(
5453@router .get (
5554 "/current" ,
5655 description = "Get information about the current officers. With no authorization, only get basic info." ,
57- response_model = list [OfficerPrivate ] | list [ OfficerPublic ],
56+ response_model = list [Officer ],
5857 operation_id = "get_current_officers" ,
5958)
6059async def current_officers (
@@ -65,15 +64,13 @@ async def current_officers(
6564
6665 curr_officers = await officers .crud .current_officers (db_session , has_private_access )
6766
68- res = [o .model_dump (mode = "json" ) for o in curr_officers ]
69-
70- return JSONResponse (res )
67+ return JSONResponse ([o .model_dump (mode = "json" , exclude_unset = True ) for o in curr_officers ])
7168
7269
7370@router .get (
7471 "/all" ,
7572 description = "Information for all execs from all exec terms" ,
76- response_model = list [OfficerPrivate ] | list [ OfficerPublic ],
73+ response_model = list [Officer ],
7774 responses = {403 : {"description" : "not authorized" , "model" : DetailModel }},
7875 operation_id = "get_all_officers" ,
7976)
@@ -90,7 +87,7 @@ async def all_officers(
9087
9188 all_officers = await officers .crud .get_all_officers (db_session , include_future_terms , has_private_access )
9289
93- return JSONResponse ([officer_data .model_dump (mode = "json" ) for officer_data in all_officers ])
90+ return JSONResponse ([officer_data .model_dump (mode = "json" , exclude_unset = True ) for officer_data in all_officers ])
9491
9592
9693@router .get (
@@ -114,7 +111,9 @@ async def get_officer_terms(
114111
115112 # all term info is public, so anyone can get any of it
116113 officer_terms = await officers .crud .get_officer_terms (db_session , computing_id , include_future_terms )
117- return JSONResponse ([OfficerTerm .model_validate (term ).model_dump (mode = "json" ) for term in officer_terms ])
114+ return JSONResponse (
115+ [OfficerTerm .model_validate (term ).model_dump (mode = "json" , exclude_unset = True ) for term in officer_terms ]
116+ )
118117
119118
120119@router .get (
@@ -133,7 +132,7 @@ async def get_officer_info(
133132 raise HTTPException (status_code = status .HTTP_403_FORBIDDEN , detail = "not authorized" )
134133
135134 officer_info = await officers .crud .get_officer_info_or_raise (db_session , computing_id )
136- return JSONResponse (officer_info . serializable_dict ( ))
135+ return JSONResponse (OfficerInfo . model_validate ( officer_info ). model_dump ( mode = "json" , exclude_unset = True ))
137136
138137
139138@router .post (
@@ -155,7 +154,7 @@ async def create_officer_term(
155154 officer_list : list [OfficerCreate ],
156155):
157156 new_terms = await officers .crud .create_multiple_officers (db_session , officer_list )
158- content = [term . serializable_dict ( ) for term in new_terms ]
157+ content = [OfficerTerm . model_validate ( term ). model_dump ( mode = "json" , exclude_unset = True ) for term in new_terms ]
159158
160159 await db_session .commit ()
161160 return JSONResponse (content )
@@ -184,15 +183,17 @@ async def update_officer_info(
184183 await verify_update (user_id , db_session , computing_id )
185184
186185 old_officer_info = await officers .crud .get_officer_info_or_raise (db_session , computing_id )
187- old_officer_info .update_from_params (officer_info_upload )
186+ update_data = officer_info_upload .model_dump (exclude_unset = True )
187+ for k , v in update_data .items ():
188+ setattr (old_officer_info , k , v )
188189 await officers .crud .update_officer_info (db_session , old_officer_info )
189190
190191 # TODO (#27): log all important changes just to a .log file & persist them for a few years
191192
192193 await db_session .commit ()
193194
194195 updated_officer_info = await officers .crud .get_new_officer_info_or_raise (db_session , computing_id )
195- return JSONResponse (updated_officer_info . serializable_dict ( ))
196+ return JSONResponse (OfficerInfo . model_validate ( updated_officer_info ). model_dump ( mode = "json" , exclude_unset = True ))
196197
197198
198199@router .patch (
@@ -229,7 +230,7 @@ async def update_officer_term(db_session: database.DBSession, term_id: int, body
229230 await db_session .commit ()
230231 await db_session .refresh (old_officer_term )
231232
232- return JSONResponse (OfficerTerm .model_validate (old_officer_term ).model_dump (mode = "json" ))
233+ return JSONResponse (OfficerTerm .model_validate (old_officer_term ).model_dump (mode = "json" , exclude_unset = True ))
233234
234235
235236@router .delete (
0 commit comments