Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination & Filters #154

Merged
merged 30 commits into from
Mar 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
656e0b6
Update friend suggestions endpoint to use paginator
Piterson25 Mar 15, 2024
c70bee1
Update friend suggestions endpoint to use query params
Piterson25 Mar 15, 2024
bc7efec
Add tests for friend suggestions
Piterson25 Mar 15, 2024
6726bce
Merge branch 'dev' into pagination
Piterson25 Mar 16, 2024
e681ee7
Fix search test
Piterson25 Mar 16, 2024
f69cf1e
Add search filter by country name
Piterson25 Mar 23, 2024
337dd9d
Update search to use search term with country
Piterson25 Mar 23, 2024
dd1dc4a
Update friend suggestions endpoint to use pagination as optional
Piterson25 Mar 24, 2024
06f344d
Update friend suggestions tests
Piterson25 Mar 24, 2024
0cd5393
Add search tests
Piterson25 Mar 24, 2024
d21f343
Add pagination and tests to friends endpoint
Piterson25 Mar 24, 2024
ee6b36d
Add filter option to search
Karol-2 Mar 24, 2024
300c80b
Change styling of filters
Karol-2 Mar 24, 2024
b1f8c25
Fix errors with filters
Karol-2 Mar 24, 2024
6e9112c
Add PaginatorV2
Karol-2 Mar 24, 2024
177ff75
Add error handling
Karol-2 Mar 24, 2024
39bff9b
Add allUsersSize to search endpoint
Piterson25 Mar 25, 2024
9475148
Update friends and friend suggestions endpoint
Piterson25 Mar 25, 2024
6bba980
Fix page totalPage numbers
Piterson25 Mar 25, 2024
b233372
Fix totalPage
Piterson25 Mar 25, 2024
0b1a977
Add PagintorV2 to friends
Karol-2 Mar 25, 2024
90ff6d2
Add PagnatorV2 to suggestions and search
Karol-2 Mar 25, 2024
140374c
Fix endpoints on search
Karol-2 Mar 25, 2024
05ebd11
Fix suggestions
Karol-2 Mar 25, 2024
0ee9488
Fix search error
Karol-2 Mar 25, 2024
066d721
Fix searchPage error
Karol-2 Mar 25, 2024
c8642bf
Fix tests
Piterson25 Mar 25, 2024
0fef38b
Apply formatting
Piterson25 Mar 25, 2024
10fcad0
Fix casting params for page and maxUsersOnPage
Piterson25 Mar 25, 2024
e510812
Merge branch 'pagination' of github.com:Karol-2/Mercury-Project into …
Piterson25 Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions backend/src/routes/usersFriendsRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ friendshipRouter.get(
);

friendshipRouter.get(
"/:userId/friend-suggestions/:page",
"/:userId/friend-suggestions",
async (req: Request, res: Response) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response isn't typed so type checking doesn't work

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember if it was already in code or I added, but changing the Response to custom would cause to change it everywhere where friends are mentioned, like friend-suggestions or friends endpoints, each to corresponing endpoint. I didn't come to any other conslusion, so if you have any, let me know! 😊

try {
const session: Session = driver.session();
const userId: string = req.params.userId;
const page: number = parseInt(req.params.page);
const maxUsersOnPage = 3;
const page: number = parseInt(req.query.page as string);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting should be done if you are absolutely sure that the type can be safely cast.
In this case req.query.page can be undefined and parseInt() returns NaN.
The code still works because NaN is falsy but I found it unintuitive.
It could be changed to parseInt(req.query.page || "")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed by now

const maxUsersOnPage: number = parseInt(req.query.maxUsers as string);

const user = await userExists(session, res, userId);
if ("json" in user) {
Expand All @@ -122,6 +122,13 @@ friendshipRouter.get(

await session.close();

if (users.length === 0) {
return res.status(404).json({
status: "not found",
message: "No users found with given queries",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other responses have a different format: { status: "error", errors: { "users": "not found" } }.
In this case the page having no users isn't an error, the page is just empty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right 😅
I tried to use different response codes, like 400 for bad requests and 404 for not found

});
}

return res.json({
status: "ok",
size: allUsers.length,
Expand Down