Skip to content

Commit

Permalink
code cleanup and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
md-redwan-hossain committed Nov 22, 2023
1 parent 1dd3948 commit b80a02e
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Api/District/DistrictController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<IActionResult> GetAll(
bool addSubDistricts = false)
{
var result = await _districtService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDivision, addSubDistricts);
apiPagination, sortOrder, addDivision, addSubDistricts);

return Ok(result.Select(x => x.ToDto(addDivision, addSubDistricts)));
}
Expand Down
8 changes: 4 additions & 4 deletions Api/District/DistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public DistrictService(BdGeographicalDataDbContext dbContext) =>
}

public async Task<IEnumerable<Entity.District>> FindAll(
ushort page, ushort limit, ApiResponseSortOrder sortOrder,
ApiPagination apiPagination, ApiResponseSortOrder sortOrder,
bool addDivision, bool addSubDistricts)
{
var data = _dbSet.AsQueryable();
data = IncludeRelationalData(data, addDivision, addSubDistricts);

data = data
.Skip((page - 1) * (limit))
.Take(limit);
.Skip((apiPagination.Page - 1) * apiPagination.Limit)
.Take(apiPagination.Limit);

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
Expand All @@ -48,7 +48,7 @@ public DistrictService(BdGeographicalDataDbContext dbContext) =>
return await data.ToListAsync();
}

private IQueryable<Entity.District> IncludeRelationalData(
private static IQueryable<Entity.District> IncludeRelationalData(
IQueryable<Entity.District> data, bool addDivision, bool addSubDistricts)
{
if (addDivision && addSubDistricts)
Expand Down
2 changes: 1 addition & 1 deletion Api/District/IDistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface IDistrictService
string districtName, string divisionName, bool addDivision, bool addSubDistricts);

Task<IEnumerable<Entity.District>> FindAll(
ushort page, ushort limit, ApiResponseSortOrder sortOrder,
ApiPagination apiPagination, ApiResponseSortOrder sortOrder,
bool addDivision, bool addSubDistricts);
}
2 changes: 1 addition & 1 deletion Api/Division/DivisionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<IActionResult> GetAll(
)
{
var result = await _divisionService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDistricts, addSubDistricts);
apiPagination, sortOrder, addDistricts, addSubDistricts);

return Ok(result.Select(x => x.ToDto(addDistricts, addSubDistricts)));
}
Expand Down
8 changes: 4 additions & 4 deletions Api/Division/DivisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public DivisionService(BdGeographicalDataDbContext dbContext) =>
}

public async Task<IEnumerable<Entity.Division>> FindAll(
ushort page, ushort limit, ApiResponseSortOrder sortOrder,
ApiPagination apiPagination, ApiResponseSortOrder sortOrder,
bool addDistricts, bool addSubDistricts)
{
var data = _dbSet.AsQueryable();
data = IncludeRelationalData(data, addDistricts, addSubDistricts);

data = data
.Skip((page - 1) * (limit))
.Take(limit);
.Skip((apiPagination.Page - 1) * apiPagination.Limit)
.Take(apiPagination.Limit);

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
Expand All @@ -47,7 +47,7 @@ public DivisionService(BdGeographicalDataDbContext dbContext) =>
}


private IQueryable<Entity.Division> IncludeRelationalData(
private static IQueryable<Entity.Division> IncludeRelationalData(
IQueryable<Entity.Division> data, bool addDistricts, bool addSubDistricts)
{
if (addDistricts && addSubDistricts)
Expand Down
2 changes: 1 addition & 1 deletion Api/Division/IDivisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface IDivisionService

Task<Entity.Division?> FindOneByEnglishName(string divisionName, bool addDistricts, bool addSubDistricts);

Task<IEnumerable<Entity.Division>> FindAll(ushort page, ushort limit, ApiResponseSortOrder sortOrder,
Task<IEnumerable<Entity.Division>> FindAll(ApiPagination apiPagination, ApiResponseSortOrder sortOrder,
bool addDistricts, bool addSubDistricts);
}
2 changes: 1 addition & 1 deletion Api/SubDistrict/ISubDistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface ISubDistrictService
Task<Entity.SubDistrict?> FindOneByEnglishName(string subDistrictName, string districtName, string divisionName,
bool addDistrict, bool addDivision);

Task<IEnumerable<Entity.SubDistrict>> FindAll(ushort page, ushort limit, ApiResponseSortOrder sortOrder,
Task<IEnumerable<Entity.SubDistrict>> FindAll(ApiPagination apiPagination, ApiResponseSortOrder sortOrder,
bool addDistrict, bool addDivision);
}
3 changes: 1 addition & 2 deletions Api/SubDistrict/SubDistrictController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public async Task<IActionResult> GetAll(
[FromQuery(Name = "add_district")] bool addDistrict = false
)
{
var result = await _subDistrictService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDistrict, addDivision);
var result = await _subDistrictService.FindAll(apiPagination, sortOrder, addDistrict, addDivision);
return Ok(result.Select(x => x.ToDto(true, true)));
}
}
8 changes: 4 additions & 4 deletions Api/SubDistrict/SubDistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SubDistrictService(BdGeographicalDataDbContext dbContext) =>
}

public async Task<IEnumerable<Entity.SubDistrict>> FindAll(
ushort page, ushort limit, ApiResponseSortOrder sortOrder, bool addDistrict, bool addDivision)
ApiPagination apiPagination, ApiResponseSortOrder sortOrder, bool addDistrict, bool addDivision)
{
var data = _dbSet.AsQueryable();
data = IncludeRelationalData(data, addDistrict, addDivision);
Expand All @@ -41,8 +41,8 @@ public SubDistrictService(BdGeographicalDataDbContext dbContext) =>
.ThenInclude(x => x.Division);

data = data
.Skip((page - 1) * (limit))
.Take(limit);
.Skip((apiPagination.Page - 1) * apiPagination.Limit)
.Take(apiPagination.Limit);

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
Expand All @@ -53,7 +53,7 @@ public SubDistrictService(BdGeographicalDataDbContext dbContext) =>
}


private IQueryable<Entity.SubDistrict> IncludeRelationalData(
private static IQueryable<Entity.SubDistrict> IncludeRelationalData(
IQueryable<Entity.SubDistrict> data, bool addDistrict, bool addDivision)
{
if (addDistrict && addDivision)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This API will provide Division, District, Sub-District related data of Banglades
- A Districts and its Division and Sub-Districts.
- A Sub-District and its Division and District.

![Screenshot of swagger doc](api.png)

## Where to use

- Data provided by this API are frequently used in web applications where Geographical data is utilized.
Expand Down
Binary file added api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b80a02e

Please sign in to comment.