Skip to content

Commit

Permalink
Add routes for neighborhoods and villages (#22)
Browse files Browse the repository at this point in the history
* Remove outdated information and update documentation

* Add routes for neighborhoods and villages
  • Loading branch information
ubeydeozdmr authored Feb 28, 2024
1 parent faa3308 commit e7f99a8
Show file tree
Hide file tree
Showing 16 changed files with 464,855 additions and 21,958 deletions.
99 changes: 85 additions & 14 deletions src/v1/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Provinces = require('./data/Provinces');
const Districts = require('./data/Districts');
const Neighborhoods = require('./data/Neighborhoods');
const Villages = require('./data/Villages');

exports.getProvinces = (req, res) => {
try {
Expand All @@ -12,7 +14,6 @@ exports.getProvinces = (req, res) => {
limit,
fields,
sort,
dev,
} = req.query;

const provinces = Provinces.getProvinces(
Expand All @@ -24,7 +25,6 @@ exports.getProvinces = (req, res) => {
limit,
fields,
sort,
dev,
);

return res.send({ status: 'OK', data: provinces });
Expand All @@ -39,9 +39,9 @@ exports.getProvinces = (req, res) => {
exports.getExactProvince = (req, res) => {
try {
const { id } = req.params;
const { fields, dev } = req.query;
const { fields, extend } = req.query;

const province = Provinces.getExactProvince(id, fields, dev);
const province = Provinces.getExactProvince(id, fields, extend);

return res.send({ status: 'OK', data: province });
} catch (error) {
Expand All @@ -54,29 +54,60 @@ exports.getExactProvince = (req, res) => {

exports.getDistricts = (req, res) => {
try {
const {
const { name, minPopulation, maxPopulation, offset, limit, fields, sort } =
req.query;

const districts = Districts.getDistricts(
name,
minPopulation,
maxPopulation,
offset,
limit,
fields,
sort,
dev,
} = req.query;
);

const districts = Districts.getDistricts(
return res.send({ status: 'OK', data: districts });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
error: error?.message || 'Internal Server Error',
});
}
};

exports.getExactDistrict = (req, res) => {
try {
const { id } = req.params;
const { fields } = req.query;

const district = Districts.getExactDistrict(id, fields);

return res.send({ status: 'OK', data: district });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
error: error?.message || 'Internal Server Error',
});
}
};

exports.getNeighborhoods = (req, res) => {
try {
const { name, minPopulation, maxPopulation, offset, limit, fields, sort } =
req.query;

const neighborhood = Neighborhoods.getNeighborhoods(
name,
minPopulation,
maxPopulation,
offset,
limit,
fields,
sort,
dev,
);

return res.send({ status: 'OK', data: districts });
return res.send({ status: 'OK', data: neighborhood });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
Expand All @@ -85,14 +116,54 @@ exports.getDistricts = (req, res) => {
}
};

exports.getExactDistrict = (req, res) => {
exports.getExactNeighborhood = (req, res) => {
try {
const { id } = req.params;
const { fields, dev } = req.query;
const { fields } = req.query;

const district = Districts.getExactDistrict(id, fields, dev);
const neighborhood = Neighborhoods.getExactNeighborhood(id, fields);

return res.send({ status: 'OK', data: district });
return res.send({ status: 'OK', data: neighborhood });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
error: error?.message || 'Internal Server Error',
});
}
};

exports.getVillages = (req, res) => {
try {
const { name, minPopulation, maxPopulation, offset, limit, fields, sort } =
req.query;

const village = Villages.getVillages(
name,
minPopulation,
maxPopulation,
offset,
limit,
fields,
sort,
);

return res.send({ status: 'OK', data: village });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
error: error?.message || 'Internal Server Error',
});
}
};

exports.getExactVillage = (req, res) => {
try {
const { id } = req.params;
const { fields } = req.query;

const village = Villages.getExactVillage(id, fields);

return res.send({ status: 'OK', data: village });
} catch (error) {
res.status(error?.status || 500).send({
status: 'ERROR',
Expand Down
Loading

0 comments on commit e7f99a8

Please sign in to comment.