강의

멘토링

커뮤니티

Inflearn Community Q&A

tkrhkdmsdud2019's profile image
tkrhkdmsdud2019

asked

Node and React series that you can learn by following - Creating a Reddit site (NextJS) (Pages Router)

Creating a Community Page (Navagation Bar)

서치 기능은 어떻게주나요?

Written on

·

450

0

강의에 서치 ui는 있는데 기능이 없어서요

어떻게 줄수있을까요?

nodejstypescriptpostgresqldockerreactNext.js클론코딩

Answer 1

2

John Ahn님의 프로필 이미지
John Ahn
Instructor

안녕하세요!

만약에 search 기능을 구현하려면

1. search에 맞는 state를 생성해줍니다.

그리고 엔터를 눌렀을 때 서버에 요청을 보내줍니다.

2. 백엔드 서버는 해당 searchTerm에 해당하는 Posts들을 데이터베이스에서 가져옵니다.

 await AppDataSource
            .createQueryBuilder()
            .select()
            .from(Post)
            .where('title ILIKE :searchTerm', {searchTerm: `%${searchTerm}%`})
            .orWhere('body ILIKE :searchTerm', {searchTerm: `%${searchTerm}%`})
            .getMany();

 

이런 식으로 쿼리를 날리면 searchTerm에 관련된 Post를 가져오게 됩니다.

3. 이렇게 데이터를 전달받으면 전달받은 데이터를 화면에 제공해주시면 됩니다.

만약 구현하시려면 이러한 순서로 로직을 처리해주시면 되겠습니다!
감사합니다.



tkrhkdmsdud2019's profile image
tkrhkdmsdud2019

asked

Ask a question