Skip to content

Commit

Permalink
Merge pull request #41 from ubeydeozdmr:40-add-iscoastal-functionality
Browse files Browse the repository at this point in the history
Add isCoastal feature for province filtering and representation
  • Loading branch information
ubeydeozdmr authored Mar 4, 2025
2 parents 0ce9c5c + 3f695db commit d19ab91
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 9 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ The API uses [turkiyeapi.dev](https://turkiyeapi.dev) as the main domain. But yo

## What's new?

> _Latest update: November 9, 2024_
> _Latest update: March 4, 2025_
- Postal codes have been added to the provinces & districts. (Experimental feature)
- Improvement about the filtering system.
- New query parameters like `minArea` and `maxArea` added to the get-all-type routes.
- You can now filter by province name or ID in the Get All Districts route.
- You can now filter by province/district name or ID in Get All Neighborhoods, Get All Villages, Get All Towns routes.
- isCoastal property added to provinces.
- isCoastal query parameter added to provinces.

## Sources

Expand Down Expand Up @@ -65,6 +62,7 @@ You can use this route to get data for all provinces. The available query parame
- `maxArea` (number): It shows all the provinces with an area less than or equal to the value you entered.
- `minAltitude` (number): It shows all the provinces with an altitude greater than or equal to the value you entered.
- `maxAltitude` (number): It shows all the provinces with an altitude less than or equal to the value you entered.
- `isCoastal` (boolean): It shows all the provinces that are coastal or not.
- `isMetropolitan` (boolean): It shows all the provinces that are metropolitan or not.
- `offset` (number): Used for pagination. Use this to set a starting point in search results.
- `limit` (number): Used for pagination. Use this to set the maximum number of results to show you.
Expand Down
2 changes: 2 additions & 0 deletions src/v1/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports.getProvinces = (req, res) => {
maxAltitude,
activatePostalCodes,
postalCode,
isCoastal,
isMetropolitan,
offset,
limit,
Expand All @@ -33,6 +34,7 @@ exports.getProvinces = (req, res) => {
maxAltitude,
activatePostalCodes,
postalCode,
isCoastal,
isMetropolitan,
offset,
limit,
Expand Down
14 changes: 14 additions & 0 deletions src/v1/data/Provinces.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports.getProvinces = function (
maxAltitude = 10000,
activatePostalCodes,
postalCode,
isCoastal,
isMetropolitan,
offset = 0,
limit = 81,
Expand Down Expand Up @@ -121,6 +122,19 @@ exports.getProvinces = function (
provinces = provinces.filter((item) => item.postalCode === postalCode);
}

if (isCoastal) {
if (isCoastal === 'true') {
provinces = provinces.filter((item) => item.isCoastal === true);
} else if (isCoastal === 'false') {
provinces = provinces.filter((item) => item.isCoastal === false);
} else {
throw {
status: 404,
message: 'The isCoastal parameter must be either true or false.',
};
}
}

if (isMetropolitan) {
if (isMetropolitan === 'true') {
provinces = provinces.filter((item) => item.isMetropolitan === true);
Expand Down
Loading

0 comments on commit d19ab91

Please sign in to comment.