diff --git a/api/Dependencies.toml b/api/Dependencies.toml index 9584a93..588f7a5 100644 --- a/api/Dependencies.toml +++ b/api/Dependencies.toml @@ -316,7 +316,7 @@ dependencies = [ [[package]] org = "ballerina" name = "sql" -version = "1.12.2" +version = "1.12.3" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, diff --git a/api/geo_data.bal b/api/geo_data.bal index 49a4e4b..bece5b9 100644 --- a/api/geo_data.bal +++ b/api/geo_data.bal @@ -160,7 +160,13 @@ public isolated service class DistrictData { public isolated service class CityData { private City city; - isolated function init(string? name, int? city_id) returns error? { + isolated function init(string? name, int? city_id,City? city = null) returns error? { + + if (city != null) { + self.city = city.cloneReadOnly(); + return; + } + City city_raw = check db_client->queryRow( `SELECT * FROM city diff --git a/api/main.bal b/api/main.bal index c2c30a2..ff6a227 100644 --- a/api/main.bal +++ b/api/main.bal @@ -5876,6 +5876,35 @@ AND p.organization_id IN ( return districtDatas; } + isolated resource function get cities(int? district_id) returns CityData[]|error? { + stream cities_data; + + if(district_id !=null && district_id != 0 && district_id > 0){ + + lock { + cities_data = db_client->query( + `SELECT * + from city + where district_id=${district_id};`); + } + + CityData[] cityDatas = []; + + check from City city_data_record in cities_data + do { + CityData|error cityData = new CityData(null, 0,city_data_record); + if !(cityData is error) { + cityDatas.push(cityData); + } + }; + + check cities_data.close(); + return cityDatas; + }else{ + return error("Provide valid value for district_id."); + } + } + isolated resource function get all_organizations() returns OrganizationData[]|error? { stream organizations_data;