Skip to content

Commit

Permalink
Merge pull request #425 from avinyafoundation/main
Browse files Browse the repository at this point in the history
student enrollment module completed
  • Loading branch information
YujithIsura authored Oct 7, 2024
2 parents 09fcc8b + 6661357 commit 5e42505
Show file tree
Hide file tree
Showing 16 changed files with 1,713 additions and 294 deletions.
15 changes: 10 additions & 5 deletions campus/bffs/enrollment/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public isolated client class GraphqlClient {
}

remote isolated function getPersons(int organization_id, int avinya_type_id) returns GetPersonsResponse|graphql:ClientError {
string query = string `query getPersons($organization_id:Int!,$avinya_type_id:Int!) {persons(organization_id:$organization_id,avinya_type_id:$avinya_type_id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type {id name} notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch}}`;
string query = string `query getPersons($organization_id:Int!,$avinya_type_id:Int!) {persons(organization_id:$organization_id,avinya_type_id:$avinya_type_id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
map<anydata> variables = {"organization_id": organization_id, "avinya_type_id": avinya_type_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetPersonsResponse>check performDataBinding(graphqlResponse, GetPersonsResponse);
}
remote isolated function getPersonById(int id) returns GetPersonByIdResponse|graphql:ClientError {
string query = string `query getPersonById($id:Int!) {person_by_id(id:$id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type {id name} notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch}}`;
string query = string `query getPersonById($id:Int!) {person_by_id(id:$id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
map<anydata> variables = {"id": id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetPersonByIdResponse>check performDataBinding(graphqlResponse, GetPersonByIdResponse);
}
remote isolated function updatePerson(City permanent_address_city, Address mailing_address, Person person, Address permanent_address, City mailing_address_city) returns UpdatePersonResponse|graphql:ClientError {
string query = string `mutation updatePerson($person:Person!,$permanent_address:Address!,$permanent_address_city:City!,$mailing_address:Address!,$mailing_address_city:City!) {update_person(person:$person,permanent_address:$permanent_address,permanent_address_city:$permanent_address_city,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type {id name} notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch}}`;
remote isolated function updatePerson(Person person, City? permanent_address_city = (), Address? mailing_address = (), Address? permanent_address = (), City? mailing_address_city = ()) returns UpdatePersonResponse|graphql:ClientError {
string query = string `mutation updatePerson($person:Person!,$permanent_address:Address,$permanent_address_city:City,$mailing_address:Address,$mailing_address_city:City) {update_person(person:$person,permanent_address:$permanent_address,permanent_address_city:$permanent_address_city,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
map<anydata> variables = {"permanent_address_city": permanent_address_city, "mailing_address": mailing_address, "person": person, "permanent_address": permanent_address, "mailing_address_city": mailing_address_city};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <UpdatePersonResponse>check performDataBinding(graphqlResponse, UpdatePersonResponse);
Expand All @@ -58,5 +58,10 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetAllOrganizationsResponse>check performDataBinding(graphqlResponse, GetAllOrganizationsResponse);
}

remote isolated function insertPerson(Person person, Address? mailing_address = (), City? mailing_address_city = ()) returns InsertPersonResponse|graphql:ClientError {
string query = string `mutation insertPerson($person:Person!,$mailing_address:Address,$mailing_address_city:City) {insert_person(person:$person,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
map<anydata> variables = {"mailing_address": mailing_address, "person": person, "mailing_address_city": mailing_address_city};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <InsertPersonResponse>check performDataBinding(graphqlResponse, InsertPersonResponse);
}
}
79 changes: 54 additions & 25 deletions campus/bffs/enrollment/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -78,69 +78,71 @@ service / on new http:Listener(9095) {

resource function get districts() returns District[]|error {
GetDistrictsResponse|graphql:ClientError getDistrictsResponse = globalDataClient->getDistricts();
if(getDistrictsResponse is GetDistrictsResponse) {
if (getDistrictsResponse is GetDistrictsResponse) {
District[] districtsData = [];
foreach var district in getDistrictsResponse.districts {
District|error districtData = district.cloneWithType(District);
if(districtData is District) {
if (districtData is District) {
districtsData.push(districtData);
} else {
log:printError("Error while processing Application record received", districtData);
return error("Error while processing Application record received: " + districtData.message() +
return error("Error while processing Application record received: " + districtData.message() +
":: Detail: " + districtData.detail().toString());
}
}

return districtsData;

} else {
log:printError("Error while getting application", getDistrictsResponse);
return error("Error while getting application: " + getDistrictsResponse.message() +
return error("Error while getting application: " + getDistrictsResponse.message() +
":: Detail: " + getDistrictsResponse.detail().toString());
}
}

resource function get all_organizations() returns Organization[]|error {
GetAllOrganizationsResponse|graphql:ClientError getAllOrganizationsResponse = globalDataClient->getAllOrganizations();
if(getAllOrganizationsResponse is GetAllOrganizationsResponse) {
if (getAllOrganizationsResponse is GetAllOrganizationsResponse) {
Organization[] organizationsData = [];
foreach var organization in getAllOrganizationsResponse.all_organizations {
Organization|error organizationData = organization.cloneWithType(Organization);
if(organizationData is Organization) {
if (organizationData is Organization) {
organizationsData.push(organizationData);
} else {
log:printError("Error while processing Application record received", organizationData);
return error("Error while processing Application record received: " + organizationData.message() +
return error("Error while processing Application record received: " + organizationData.message() +
":: Detail: " + organizationData.detail().toString());
}
}

return organizationsData;

} else {
log:printError("Error while getting application", getAllOrganizationsResponse);
return error("Error while getting application: " + getAllOrganizationsResponse.message() +
return error("Error while getting application: " + getAllOrganizationsResponse.message() +
":: Detail: " + getAllOrganizationsResponse.detail().toString());
}
}

resource function put update_person(@http:Payload Person person) returns Person|error {

Address permanent_address = <Address>person?.permanent_address;
Address mailing_address = <Address>person?.mailing_address;
City permanent_address_city = <City>permanent_address?.city;
City mailing_address_city = <City>mailing_address?.city;
anydata remove_permanent_address_city = permanent_address.remove("city");
anydata remove_mailing_address_city = mailing_address.remove("city");
anydata remove_permanent_address = person.remove("permanent_address");
anydata remove_mailing_address = person.remove("mailing_address");
log:printDebug(remove_permanent_address.toString());
log:printDebug(remove_mailing_address.toString());
log:printDebug(remove_permanent_address_city.toString());
log:printDebug(remove_mailing_address_city.toString());


UpdatePersonResponse|graphql:ClientError updatePersonResponse = globalDataClient->updatePerson(permanent_address_city,mailing_address,person,permanent_address,mailing_address_city);
Address? permanent_address = person?.permanent_address;
Address? mailing_address = person?.mailing_address;
City? permanent_address_city = permanent_address?.city;
City? mailing_address_city = mailing_address?.city;

if(permanent_address is Address){
permanent_address.city = ();
}

if(mailing_address is Address){
mailing_address.city = ();
}

person.permanent_address = ();
person.mailing_address = ();

UpdatePersonResponse|graphql:ClientError updatePersonResponse = globalDataClient->updatePerson(person, permanent_address_city, mailing_address, permanent_address, mailing_address_city);
if (updatePersonResponse is UpdatePersonResponse) {
Person|error person_record = updatePersonResponse.update_person.cloneWithType(Person);
if (person_record is Person) {
Expand All @@ -157,4 +159,31 @@ service / on new http:Listener(9095) {
}
}

resource function post add_person(@http:Payload Person person) returns Person|error {

Address? mailing_address = person?.mailing_address;
City? mailing_address_city = mailing_address?.city;

if(mailing_address is Address){
mailing_address.city = ();
}

person.mailing_address = ();

InsertPersonResponse|graphql:ClientError addPersonResponse = globalDataClient->insertPerson(person,mailing_address,mailing_address_city);
if (addPersonResponse is InsertPersonResponse) {
Person|error person_record = addPersonResponse.insert_person.cloneWithType(Person);
if (person_record is Person) {
return person_record;
} else {
log:printError("Error while processing Application record received", person_record);
return error("Error while processing Application record received: " + person_record.message() +
":: Detail: " + person_record.detail().toString());
}
} else {
log:printError("Error while creating application", addPersonResponse);
return error("Error while creating application: " + addPersonResponse.message() +
":: Detail: " + addPersonResponse.detail().toString());
}
}
}
112 changes: 98 additions & 14 deletions campus/bffs/enrollment/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,25 @@ public type Person record {
string? digital_id?;
string? sex?;
string? passport_no?;
string? current_job?;
int? created_by?;
string? record_type?;
Address? mailing_address?;
string? branch_code?;
int[]? child_student?;
string? bank_account_name?;
int? avinya_phone?;
string? full_name?;
string? nic_no?;
int? phone?;
int? organization_id?;
int? updated_by?;
string? academy_org_name?;
string? asgardeo_id?;
string? updated?;
string? preferred_name?;
string? jwt_sub_id?;
int? academy_org_id?;
int? created_by?;
int? updated_by?;
};

public type GetPersonsResponse record {|
Expand Down Expand Up @@ -173,10 +176,7 @@ public type GetPersonsResponse record {|
|} name;
|}[]? parent_organizations;
|}? organization;
record {|
int? id;
string? name;
|}? avinya_type;
int? avinya_type_id;
string? notes;
string? nic_no;
string? passport_no;
Expand All @@ -190,6 +190,9 @@ public type GetPersonsResponse record {|
string? bank_account_name;
int? academy_org_id;
string? bank_branch;
int? created_by;
int? updated_by;
string? current_job;
|}[] persons;
|};

Expand Down Expand Up @@ -254,10 +257,7 @@ public type GetPersonByIdResponse record {|
|} name;
|}[]? parent_organizations;
|}? organization;
record {|
int? id;
string? name;
|}? avinya_type;
int? avinya_type_id;
string? notes;
string? nic_no;
string? passport_no;
Expand All @@ -271,6 +271,9 @@ public type GetPersonByIdResponse record {|
string? bank_account_name;
int? academy_org_id;
string? bank_branch;
int? created_by;
int? updated_by;
string? current_job;
|}? person_by_id;
|};

Expand Down Expand Up @@ -335,10 +338,7 @@ public type UpdatePersonResponse record {|
|} name;
|}[]? parent_organizations;
|}? organization;
record {|
int? id;
string? name;
|}? avinya_type;
int? avinya_type_id;
string? notes;
string? nic_no;
string? passport_no;
Expand All @@ -352,6 +352,9 @@ public type UpdatePersonResponse record {|
string? bank_account_name;
int? academy_org_id;
string? bank_branch;
int? created_by;
int? updated_by;
string? current_job;
|}? update_person;
|};

Expand Down Expand Up @@ -410,3 +413,84 @@ public type GetAllOrganizationsResponse record {|
string? notes;
|}[] all_organizations;
|};

public type InsertPersonResponse record {|
map<json?> __extensions?;
record {|
int? id;
string? preferred_name;
string? full_name;
string? date_of_birth;
string? sex;
string? asgardeo_id;
string? jwt_sub_id;
string? created;
string? updated;
string? jwt_email;
record {|
record {|
int? id;
record {|
string? name_en;
string? name_si;
string? name_ta;
|} name;
|} city;
string? street_address;
int? phone;
int? id;
|}? permanent_address;
record {|
record {|
int? id;
record {|
string? name_en;
string? name_si;
string? name_ta;
|} name;
|} city;
string? street_address;
int? phone;
int? id;
|}? mailing_address;
int? phone;
record {|
int? id;
string? description;
string? notes;
record {|
int? id;
|}? address;
record {|
int? id;
string? name;
|}? avinya_type;
record {|
string? name_en;
|} name;
record {|
int? id;
record {|
string? name_en;
|} name;
|}[]? parent_organizations;
|}? organization;
int? avinya_type_id;
string? notes;
string? nic_no;
string? passport_no;
string? id_no;
string? email;
string? street_address;
string? digital_id;
int? avinya_phone;
string? bank_name;
string? bank_account_number;
string? bank_account_name;
int? academy_org_id;
string? bank_branch;
int? created_by;
int? updated_by;
string? current_job;
|}? insert_person;
|};
Loading

0 comments on commit 5e42505

Please sign in to comment.