Skip to content

Commit

Permalink
Get cities api changes added
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirulakruwan committed Oct 15, 2024
1 parent afaf2e8 commit d493960
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 65 deletions.
8 changes: 7 additions & 1 deletion campus/bffs/enrollment/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ public isolated client class GraphqlClient {
return <UpdatePersonResponse>check performDataBinding(graphqlResponse, UpdatePersonResponse);
}
remote isolated function getDistricts() returns GetDistrictsResponse|graphql:ClientError {
string query = string `query getDistricts {districts {id province {id name {name_en}} name {name_en} cities {id name {name_en}}}}`;
string query = string `query getDistricts {districts {id province {id name {name_en}} name {name_en}}}`;
map<anydata> variables = {};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetDistrictsResponse>check performDataBinding(graphqlResponse, GetDistrictsResponse);
}
remote isolated function getCities(int district_id) returns GetCitiesResponse|graphql:ClientError {
string query = string `query getCities($district_id:Int!) {cities(district_id:$district_id) {id name {name_en}}}`;
map<anydata> variables = {"district_id": district_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetCitiesResponse>check performDataBinding(graphqlResponse, GetCitiesResponse);
}
remote isolated function getAllOrganizations() returns GetAllOrganizationsResponse|graphql:ClientError {
string query = string `query getAllOrganizations {all_organizations {id name {name_en} address {id street_address} avinya_type {id name} description phone notes}}`;
map<anydata> variables = {};
Expand Down
24 changes: 24 additions & 0 deletions campus/bffs/enrollment/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ service / on new http:Listener(9095) {
}
}

resource function get cities/[int district_id]() returns City[]|error {
GetCitiesResponse|graphql:ClientError getCitiesResponse = globalDataClient->getCities(district_id);
if (getCitiesResponse is GetCitiesResponse) {
City[] citiesData = [];
foreach var city in getCitiesResponse.cities {
City|error cityData = city.cloneWithType(City);
if (cityData is City) {
citiesData.push(cityData);
} else {
log:printError("Error while processing Application record received", cityData);
return error("Error while processing Application record received: " + cityData.message() +
":: Detail: " + cityData.detail().toString());
}
}

return citiesData;

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

resource function get all_organizations() returns Organization[]|error {
GetAllOrganizationsResponse|graphql:ClientError getAllOrganizationsResponse = globalDataClient->getAllOrganizations();
if (getAllOrganizationsResponse is GetAllOrganizationsResponse) {
Expand Down
17 changes: 11 additions & 6 deletions campus/bffs/enrollment/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,20 @@ public type GetDistrictsResponse record {|
record {|
string? name_en;
|} name;
record {|
int? id;
record {|
string? name_en;
|} name;
|}[] cities;
|}[] districts;
|};

public type GetCitiesResponse record {|
map<json?> __extensions?;
record {|
int? id;
record {|
string? name_en;
|} name;
|}[] cities;
|};


public type GetAvinyaTypesResponse record {|
map<json?> __extensions?;
record {|
Expand Down
120 changes: 69 additions & 51 deletions campus/bffs/enrollment/graphql_client/enrollment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,20 @@ 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,mailing_address: $mailing_address,
mailing_address_city: $mailing_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
full_name
Expand Down Expand Up @@ -241,62 +250,72 @@ mutation updatePerson($person: Person!,$permanent_address: Address,$permanent_ad
}
}


query getDistricts {
districts {
id
province{
id
name{
name_en
}
}
name{
name_en
}
cities{
id
name{
name_en
}
}
districts {
id
province {
id
name {
name_en
}
}
name {
name_en
}
}
}

query getCities($district_id: Int!) {
cities(district_id: $district_id) {
id
name {
name_en
}
}
}

query getAvinyaTypes {
avinya_types {
id
active
name
global_type
foundation_type
focus
level
}
avinya_types {
id
active
name
global_type
foundation_type
focus
level
}
}

query getAllOrganizations {
all_organizations {
id
name{
name_en
}
address{
id
street_address
}
avinya_type{
id
name
}
description
phone
notes
all_organizations {
id
name {
name_en
}
address {
id
street_address
}
avinya_type {
id
name
}
description
phone
notes
}
}

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) {
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
Expand Down Expand Up @@ -374,4 +393,3 @@ mutation insertPerson($person: Person!,$mailing_address: Address,$mailing_addres
current_job
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ public isolated client class GraphqlClient {
return <UpdatePersonResponse> check performDataBinding(graphqlResponse, UpdatePersonResponse);
}
remote isolated function getDistricts() returns GetDistrictsResponse|graphql:ClientError {
string query = string `query getDistricts {districts {id province {id name {name_en}} name {name_en} cities {id name {name_en}}}}`;
string query = string `query getDistricts {districts {id province {id name {name_en}} name {name_en}}}`;
map<anydata> variables = {};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetDistrictsResponse> check performDataBinding(graphqlResponse, GetDistrictsResponse);
}
remote isolated function getCities(int district_id) returns GetCitiesResponse|graphql:ClientError {
string query = string `query getCities($district_id:Int!) {cities(district_id:$district_id) {id name {name_en}}}`;
map<anydata> variables = {"district_id": district_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetCitiesResponse> check performDataBinding(graphqlResponse, GetCitiesResponse);
}
remote isolated function getAvinyaTypes() returns GetAvinyaTypesResponse|graphql:ClientError {
string query = string `query getAvinyaTypes {avinya_types {id active name global_type foundation_type focus level}}`;
map<anydata> variables = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,19 @@ public type GetDistrictsResponse record {|
record {|
string? name_en;
|} name;
record {|
int? id;
record {|
string? name_en;
|} name;
|}[] cities;
|}[]? districts;
|};

public type GetCitiesResponse record {|
map<json?> __extensions?;
record {|
int? id;
record {|
string? name_en;
|} name;
|}[]? cities;
|};

public type GetAvinyaTypesResponse record {|
map<json?> __extensions?;
record {|
Expand Down
1 change: 1 addition & 0 deletions campus/bffs/enrollment/graphql_client/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ type Query {
persons(organization_id: Int, avinya_type_id: Int): [PersonData!]
person_by_id(id: Int): PersonData
districts: [DistrictData!]
cities(district_id: Int): [CityData!]
all_organizations: [OrganizationData!]
}

Expand Down
29 changes: 29 additions & 0 deletions campus/bffs/enrollment/graphql_client/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,35 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "cities",
"args": [
{
"name": "district_id",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "CityData",
"ofType": null
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "all_organizations",
"args": [],
Expand Down

0 comments on commit d493960

Please sign in to comment.