Skip to content

Commit

Permalink
fixed pagination default
Browse files Browse the repository at this point in the history
  • Loading branch information
md-redwan-hossain committed Nov 22, 2023
1 parent b80a02e commit 1914fe8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
11 changes: 7 additions & 4 deletions Api/District/DistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ public DistrictService(BdGeographicalDataDbContext dbContext) =>
var data = _dbSet.AsQueryable();
data = IncludeRelationalData(data, addDivision, addSubDistricts);

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

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
else if (sortOrder == ApiResponseSortOrder.Asc)
data = data.OrderBy(x => x.EnglishName);
else
data = data.OrderBy(x => x.Id);


if (apiPagination.Page > 0 && apiPagination.Limit > 0)
data = data.Skip((apiPagination.Page - 1) * apiPagination.Limit).Take(apiPagination.Limit);


return await data.ToListAsync();
}
Expand Down
11 changes: 7 additions & 4 deletions Api/Division/DivisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public DivisionService(BdGeographicalDataDbContext dbContext) =>
var data = _dbSet.AsQueryable();
data = IncludeRelationalData(data, addDistricts, addSubDistricts);

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

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
else if (sortOrder == ApiResponseSortOrder.Asc)
data = data.OrderBy(x => x.EnglishName);
else
data = data.OrderBy(x => x.Id);


if (apiPagination.Page > 0 && apiPagination.Limit > 0)
data = data.Skip((apiPagination.Page - 1) * apiPagination.Limit).Take(apiPagination.Limit);


return await data.ToListAsync();
}
Expand Down
11 changes: 7 additions & 4 deletions Api/SubDistrict/SubDistrictService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public SubDistrictService(BdGeographicalDataDbContext dbContext) =>
.Include(x => x.District)
.ThenInclude(x => x.Division);

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

if (sortOrder == ApiResponseSortOrder.Desc)
data = data.OrderByDescending(x => x.EnglishName);
else if (sortOrder == ApiResponseSortOrder.Asc)
data = data.OrderBy(x => x.EnglishName);
else
data = data.OrderBy(x => x.Id);


if (apiPagination.Page > 0 && apiPagination.Limit > 0)
data = data.Skip((apiPagination.Page - 1) * apiPagination.Limit).Take(apiPagination.Limit);


return await data.ToListAsync();
}
Expand Down
1 change: 0 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

var builder = WebApplication.CreateBuilder(args);


var envVars = new EnvVariable()
{
DatabaseUrl = builder.Configuration.GetConnectionString("DATABASE_URL"),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This API will provide Division, District, Sub-District related data of Banglades
## How to run

- The preferred way to use the API is docker. However, you need dotnet 7 to run the source code.
- For API documentation, go to `/swagger` endpoint.
- For API documentation, go to `/swagger` endpoint. Example url: `http://localhost:5000/swagger`
- If any package is missing, simply run:

```bash
Expand Down
4 changes: 2 additions & 2 deletions Shared/ApiPagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace BdGeographicalData.Shared;

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

0 comments on commit 1914fe8

Please sign in to comment.