Skip to content

Commit

Permalink
Merge pull request #421 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
update person  api changes added
  • Loading branch information
YujithIsura authored Oct 4, 2024
2 parents 4d4e2d1 + fabd687 commit 962e9a5
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 33 deletions.
4 changes: 2 additions & 2 deletions campus/bffs/enrollment/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public isolated client class GraphqlClient {
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 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 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 Down
52 changes: 27 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 Down
10 changes: 8 additions & 2 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 @@ -352,6 +355,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
8 changes: 6 additions & 2 deletions campus/bffs/enrollment/graphql_client/enrollment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ query getPersonById($id: Int!) {
}
}

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,
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
Expand Down Expand Up @@ -236,6 +237,9 @@ mutation updatePerson($person: Person!,$permanent_address: Address!,$permanent_a
bank_account_name
academy_org_id
bank_branch
created_by
updated_by
current_job
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public isolated client class GraphqlClient {
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 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 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public type Person record {
string? digital_id?;
string? sex?;
string? passport_no?;
string? current_job?;
int? created_by?;
string? record_type?;
Address? mailing_address?;
Expand Down Expand Up @@ -666,6 +667,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
3 changes: 3 additions & 0 deletions campus/bffs/enrollment/graphql_client/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ type Mutation {
update_consumable_replenishment(inventories: [Inventory!]!): [InventoryData!]
update_consumable_depletion(inventories: [Inventory!]!): [InventoryData!]
update_person(person: Person!, permanent_address: Address, permanent_address_city: City, mailing_address: Address, mailing_address_city: City): PersonData
insert_person(person: Person!, mailing_address: Address, mailing_address_city: City): PersonData
}

input Organization {
Expand Down Expand Up @@ -747,6 +748,7 @@ input Person {
academy_org_id: Int
academy_org_name: String
branch_code: String
current_job: String
created_by: Int
updated_by: Int
}
Expand Down Expand Up @@ -785,6 +787,7 @@ type PersonData {
academy_org_id: Int
organization_id: Int
branch_code: String
current_job: String
created_by: Int
updated_by: Int
}
Expand Down
63 changes: 63 additions & 0 deletions campus/bffs/enrollment/graphql_client/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,17 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "current_job",
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "created_by",
"args": [],
Expand Down Expand Up @@ -8670,6 +8681,49 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "insert_person",
"args": [
{
"name": "person",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "Person",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "mailing_address",
"type": {
"kind": "INPUT_OBJECT",
"name": "Address",
"ofType": null
},
"defaultValue": null
},
{
"name": "mailing_address_city",
"type": {
"kind": "INPUT_OBJECT",
"name": "City",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "PersonData",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -9180,6 +9234,15 @@
},
"defaultValue": null
},
{
"name": "current_job",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "created_by",
"type": {
Expand Down

0 comments on commit 962e9a5

Please sign in to comment.