diff --git a/app/mapping.py b/app/mapping.py index 4d57445..f709d2d 100644 --- a/app/mapping.py +++ b/app/mapping.py @@ -28,7 +28,16 @@ GROUP_USER_QUERY_PARAMS = ["id", "group_id", "user_id"] -SCHOOL_QUERY_PARAMS = ["id", "name", "school_name", "code", "board_medium", "region"] +SCHOOL_QUERY_PARAMS = [ + "id", + "name", + "school_name", + "code", + "board_medium", + "region", + "district", + "state", +] SESSION_QUERY_PARAMS = ["id", "name", "session_id"] @@ -94,3 +103,14 @@ "date_of_birth", "country", ] + +authgroup_state_mapping = { + "HaryanaStudents": "Haryana", + "DelhiStudents": "Delhi", + "UttarakhandStudents": "Uttarakhand", + "GujaratStudents": "Gujarat", + "HimachalStudents": "Himachal Pradesh", + "PunjabStudents": "Punjab", + "MaharashtraStudents": "Maharashtra", + "TNStudents": "Tamil Nadu", +} diff --git a/app/router/student.py b/app/router/student.py index fb0fdaa..1793fc6 100644 --- a/app/router/student.py +++ b/app/router/student.py @@ -19,6 +19,7 @@ STUDENT_QUERY_PARAMS, ENROLLMENT_RECORD_PARAMS, SCHOOL_QUERY_PARAMS, + authgroup_state_mapping, ) router = APIRouter(prefix="/student", tags=["Student"]) @@ -46,10 +47,26 @@ def build_student_and_user_data(student_data): return data -async def create_school_user_record(data, school_name): - school_data = school.get_school( - build_request(query_params={"name": str(school_name)}) - ) +async def create_school_user_record(data, school_name, district, auth_group_name): + state = authgroup_state_mapping.get(auth_group_name, "") + + if state: + school_data = school.get_school( + build_request( + query_params={ + "name": str(school_name), + "district": str(district), + "state": state, + } + ) + ) + else: + school_data = school.get_school( + build_request( + query_params={"name": str(school_name), "district": str(district)} + ) + ) + group_data = group.get_group( build_request(query_params={"child_id": school_data["id"], "type": "school"}) ) @@ -283,9 +300,12 @@ async def create_student(request: Request): await create_auth_group_user_record(new_student_data, data["auth_group"]) if "school_name" in query_params: - - await create_school_user_record(new_student_data, query_params["school_name"]) - + await create_school_user_record( + new_student_data, + query_params["school_name"], + query_params["district"], + data["auth_group"], + ) return student_id