boolean-uk / team-dev-server

3 stars 12 forks source link

#33 As a teacher, so I can find students to add to my cohort, I want to search for students by name. #279

Closed mnmin closed 1 year ago

mnmin commented 1 year ago

User Story

[#33 As a teacher, so I can find students to add to my cohort, I want to search for students by name.

Tasks

Search Bar currently not working.

BACKEND TO-DO: Implement a request to DB to search every time a User input in the searchBar. Reference (https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#contains)


Example request:

const findUsersByName = await prisma.user.findMany({
      where: {
        name: {
                 contains:  ‘*input of the user*’
                }
  }
})
vherus commented 1 year ago

Nice. For your frontend, you'll want to think about how to minimise the number of API calls the client makes. If the search happens every time the user changes something in the input, you don't want to make an API call every time that happens.

You can either have a button so the search only happens when the user has finished typing their query and hits the button, or you can get a bunch of users at once and filter them on the frontend. With the second option, you don't want to have every single user in state, that could be a lot of data, so you might prefer a hybrid approach where you have 50 users in state and you can make an API call to check the database if the queried user doesn't exist in state.

That's if you want to go down that route (which is more complex) - otherwise, sticking with a search button and using this endpoint is fine

vherus commented 1 year ago

Approved if you choose to go with this implementation.

If you want to explore the other, I'll need more plan

mnmin commented 1 year ago

I'll discuss it with my team

mnmin commented 1 year ago

Hi Nathan, we discussed the issue and we decided to filter the users on the frontend