Skip to content

Commit

Permalink
Merge pull request #79 from Hayotbahrom/dev
Browse files Browse the repository at this point in the history
pagination logic optimized and UserChannelController renamed to UserChannelsController #78
  • Loading branch information
dotnetgoo authored Oct 25, 2023
2 parents f547e27 + df32920 commit 9e14258
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Shamsheer.Messenger.Api.Controllers.UserChannels;

public class UserChannelController : BaseController
public class UserChannelsController : BaseController
{
private readonly IUserChannelService _userChannelService;

public UserChannelController(IUserChannelService userChannelService)
public UserChannelsController(IUserChannelService userChannelService)
{
_userChannelService = userChannelService;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Shamsheer.Messenger.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=localhost; Port=5432; Database=ShamsheerDb; User Id=postgres; Password=Dilafruz10;"
"DefaultConnection": "Server=localhost; Port=5432; Database=ShamsheerDb; User Id=postgres; Password=2002;"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 2 additions & 14 deletions src/Shamsheer.Service/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ public static IQueryable<TEntity> ToPagedList<TEntity>(this IQueryable<TEntity>
throw new ArgumentOutOfRangeException(nameof(@params.PageSize), "The page size must be greater than or equal to 1.");
}

// Skip the specified number of pages.
source = source.Skip((@params.PageIndex - 1) * @params.PageSize);

// Take the specified number of items from the sequence.
source = source.Take(@params.PageSize);

return source;
return source.Take((@params.PageSize * (@params.PageIndex - 1))..(@params.PageSize * (@params.PageIndex - 1) + @params.PageSize));
}

public static IEnumerable<TEntity> ToPagedList<TEntity>(this IEnumerable<TEntity> source, PaginationParams @params)
Expand All @@ -42,13 +36,7 @@ public static IEnumerable<TEntity> ToPagedList<TEntity>(this IEnumerable<TEntity
throw new ArgumentOutOfRangeException(nameof(@params.PageSize), "The page size must be greater than or equal to 1.");
}

// Skip the specified number of pages.
source = source.Skip((@params.PageIndex - 1) * @params.PageSize);

// Take the specified number of items from the sequence.
source = source.Take(@params.PageSize);

return source;
return source.Take((@params.PageSize * (@params.PageIndex - 1))..(@params.PageSize * (@params.PageIndex - 1) + @params.PageSize));
}

}
Expand Down

0 comments on commit 9e14258

Please sign in to comment.