Closed DevinCLane closed 1 year ago
For the random implementation (line below) what guarantees on page 2 that a user from page 1 isn't selected again when randomly selecting from the DB?
const res = await client.query('SELECT * FROM users ORDER BY random() LIMIT 8');
GET /api/users/:id
should not return the discord_name if the caller is not authed
Good question. This logic should only apply to initial page loads. I don't want the same 8 profiles being shown to everyone the first time the page is loaded.
There will need to be more complex logic for the infinity scroll such that profiles are not randomly selected again in the scrolling process.
@DevinCLane can you repost this to Discussions? Realizing we should be using that for discussions and once finalized, move to here for referencing.
https://github.com/timmyichen/dev-directory/discussions/new?category=technical-specification-review
@DevinCLane I want to walk back the randomness. I think this will add complexity and solve a problem we won't even have with MVP due to limited users.
I'd recommend lowering the complexity and setting pagination to just a sort of some default criteria.
Okay moving this over to Discussions.
Closed via #17
Summary: This tech spec outlines the technical requirements for implementing pagination on Dev Directory
Scope: Define the scope of the project, including what it will and will not include. List the features, functions, and requirements of the project.
Data model: Define the data model of the project, including the database schema and relationships between data entities. Describe how the data will be stored, accessed, and updated.
No changes needed to the data model. This tech spec is only responsible for reading from the DB.
User Stories: List the ways the user will interact with the project. e.g. "User will be able to edit their profile."
User has the option to load more, and can either click "load more" and scroll, or infinite scroll is triggered by scrolling down.
Implementation: Describe how the features are implememented
Loading of user data into view
import { Client } from 'pg';
const client = new Client({ user: 'your_database_user', host: 'your_database_host', database: 'your_database_name', password: 'your_database_password', port: 5432, });
async function getRandomUsers(): Promise<User[]> { await client.connect(); const res = await client.query('SELECT * FROM users ORDER BY random() LIMIT 8'); const randomUsers = res.rows; await client.end(); return randomUsers; }
interface User { id: number; name: string; email: string; // add other properties as needed }
Infinite scroll
IntersectionObserver
to detect when the user has scrolled to the bottom of the pageconst observer = new IntersectionObserver(([entry]) => { if (isLast && entry.isIntersecting) { newLimit(); observer.unobserve(entry.target); } });
observer.observe(cardRef.current); }, [isLast]);
"Load more" button
More information on pagination approaches
We will paginate based on Keyset API Pagination. For example:
APIs: Define the APIs of the project, including the endpoints, methods, and request/response formats. Describe how the APIs will be documented, tested, and secured.
The directory API will be used to retrieve the dataset to be paginated and to load each page of items when a user navigates to a new page. The API will also be used to calculate the total number of pages based on the number of items per page and the total number of items in the dataset. (adapted from chatGPT)
allUsers
route will be implemented that will display the first 8 users.GET /api/allUsers/:id
- gets all user's profile details and socialssearchUsers
route will be implemented that will display users that match certain filtered criteriaGET /api/searchUser/:id
- returns users that match the filtered criteriaSecurity: Describe the security features and requirements of the project, including authentication, authorization, encryption, and data protection.
GET /api/users/:id
should not return the discord_name if the caller is not authedTesting: Describe the testing approach and strategy for the project, including unit tests, integration tests, and end-to-end tests. Describe how the tests will be automated and integrated into the development process.
Open Questions: Use this space to ask any questions of which you're not sure of the answer, whether it be a technical question or an implementation detail.
Deployment: Describe any special considerations needed when deploying the project. For example, if there are breaking schema changes, how do we migrate existing data?