Skip to content

Commit

Permalink
Separate class for Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
md-redwan-hossain committed Nov 21, 2023
1 parent 6d5c814 commit 646b146
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Api/District/DistrictController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ [BindRequired] [FromQuery(Name = "division_name")]
[HttpGet]
public async Task<IActionResult> GetAll(
ApiResponseSortOrder sortOrder,
[FromQuery] ApiPagination apiPagination,
[FromQuery(Name = "add_division")] bool addDivision = false,
[FromQuery(Name = "add_sub_districts")]
bool addSubDistricts = false,
[FromQuery(Name = "page")] ushort page = 1,
[FromQuery(Name = "limit")] ushort limit = 1)
bool addSubDistricts = false)
{
var result = await _districtService.FindAll(page, limit, sortOrder, addDivision, addSubDistricts);
var result = await _districtService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDivision, addSubDistricts);

return Ok(result.Select(x => x.ToDto(addDivision, addSubDistricts)));
}
}
7 changes: 4 additions & 3 deletions Api/Division/DivisionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ [BindRequired] [FromRoute(Name = "division_name")]
[HttpGet]
public async Task<IActionResult> GetAll(
ApiResponseSortOrder sortOrder,
[FromQuery(Name = "page")] ushort page = 1,
[FromQuery(Name = "limit")] ushort limit = 1,
[FromQuery] ApiPagination apiPagination,
[FromQuery(Name = "add_districts")] bool addDistricts = false,
[FromQuery(Name = "add_sub_districts")]
bool addSubDistricts = false
)
{
var result = await _divisionService.FindAll(page, limit, sortOrder, addDistricts, addSubDistricts);
var result = await _divisionService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDistricts, addSubDistricts);

return Ok(result.Select(x => x.ToDto(addDistricts, addSubDistricts)));
}
}
6 changes: 3 additions & 3 deletions Api/SubDistrict/SubDistrictController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ [BindRequired] [FromQuery(Name = "division_name")]
[HttpGet]
public async Task<IActionResult> GetAll(
ApiResponseSortOrder sortOrder,
[FromQuery(Name = "page")] ushort page = 1,
[FromQuery(Name = "limit")] ushort limit = 1,
[FromQuery] ApiPagination apiPagination,
[FromQuery(Name = "add_division")] bool addDivision = false,
[FromQuery(Name = "add_district")] bool addDistrict = false
)
{
var result = await _subDistrictService.FindAll(page, limit, sortOrder, addDistrict, addDivision);
var result = await _subDistrictService.FindAll(
apiPagination.Page, apiPagination.Limit, sortOrder, addDistrict, addDivision);
return Ok(result.Select(x => x.ToDto(true, true)));
}
}
7 changes: 7 additions & 0 deletions Shared/ApiPagination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BdGeographicalData.Shared;

public class ApiPagination
{
public ushort Page { get; set; } = 1;
public ushort Limit { get; set; } = 1;
}

0 comments on commit 646b146

Please sign in to comment.