-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from lvchkn/paged-api-response
Change `/api/stories` return object to include the total number of pages
- Loading branch information
Showing
13 changed files
with
177 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
RMQ_USER= | ||
RMQ_PW= | ||
POSTGRES_DB= | ||
POSTGRES_USER= | ||
POSTGRES_PW= | ||
GH_APP_NAME= | ||
GH_CLIENT_ID= | ||
GH_CLIENT_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Application.Stories; | ||
|
||
namespace Application.Paging; | ||
|
||
public record PagedStoriesDto | ||
{ | ||
public List<StoryDto> Stories { get; init; } = new (); | ||
public int TotalPagesCount { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Application.Stories; | ||
|
||
namespace Application.Paging; | ||
|
||
public static class PagingExtension | ||
{ | ||
public static PagedStoriesDto Paginate(this IEnumerable<StoryDto> stories, int skip, int take) | ||
{ | ||
if (take <= 0) throw new ArgumentOutOfRangeException(); | ||
|
||
var pagedStories = stories.Skip(skip).Take(take).ToList(); | ||
var totalPagesCount = (int)Math.Ceiling((double)stories.Count() / take); | ||
|
||
return new () | ||
{ | ||
Stories = pagedStories, | ||
TotalPagesCount = totalPagesCount, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using Application.Paging; | ||
|
||
namespace Application.Stories; | ||
|
||
public interface IStoriesService | ||
{ | ||
Task AddAsync(StoryDto storyDto); | ||
Task<List<StoryDto>> GetAllAsync(); | ||
List<StoryDto> GetStories(string? orderBy, string? search, int pageNumber, int pageSize); | ||
PagedStoriesDto GetStories(string? orderBy, string? search, int pageNumber, int pageSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This is a respectful environment for everyone before everything else! | ||
|
||
I'd like to ensure that everyone can participate in this project in a friendly and constructive manner. | ||
|
||
So, the **standard guidelines** are: | ||
|
||
- Be respectful | ||
- Be collaborative | ||
|
||
The things I consider **inappropriate**: | ||
|
||
- Personal attacks, insults, or derogatory comments. | ||
- Posting or sharing explicit content. | ||
- Sharing personal information without consent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
[![.NET](https://github.com/lvchkn/Hackernews-Feed/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/lvchkn/Hackernews-Feed/actions/workflows/build-and-test.yml) | ||
|
||
# Hackernews-Feed | ||
|
||
This API acts as a kind of proxy backend for my custom [HN client](https://github.com/lvchkn/hn-client) and provides RESTful endpoints that allow for sorting, filtering and paging stories from Hackernews. | ||
|
||
This is only partially implemented and still is under development, but the idea is that users may authenticate to the custom client page via Github, specify their topics of interest, and get a personal stories feed based on their preferences. | ||
|
||
## How to run locally | ||
|
||
1. Create a `.env` file in the project's root directory and fill it in according to the `.env.example` file. | ||
1. Start the compose stack | ||
|
||
```bash | ||
docker compose -f docker-compose.local up | ||
``` | ||
|
||
1. Run the following command from the root's directory: | ||
```bash | ||
dotnet run --project HackerNewsCommentsFeed/HackerNewsCommentsFeed.csproj | ||
``` | ||
1. Navigate to `http://localhost/index.html` or `https://localhost:7245` to see the Swagger OpenAPI definition. | ||
## How to run the tests | ||
Just run the `dotnet test` command in the project's root directory. | ||
Note that the entries in the `.env` file related to the authentication must be prepopulated before running the tests to avoid errors during the test server's startup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.