-
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.
๐ [#3] Search Feature Retrospective ์ํฐํด์ ์ถ๊ฐํ๋ค
- Loading branch information
1 parent
1dcaa59
commit 2c7a9fb
Showing
1 changed file
with
119 additions
and
0 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,119 @@ | ||
--- | ||
title: ๊ฒ์ ๊ธฐ๋ฅ ๊ฐ๋ฐ ํ๋ก์ ํธ ํ๊ณ | ||
description: ๊ฒ์์ด ์ถ์ฒ, ํค๋ณด๋ ์ธํฐ๋ ์ ์ ํฌํจํ ๊ฒ์ ๊ธฐ๋ฅ ๊ตฌํ ๊ธฐ์ ๊ณผ์ | ||
createdAt: 2022-09-30 | ||
category: React | ||
tags: | ||
- React | ||
- TypeScript | ||
- Team Project | ||
- Retrospective | ||
- Wanted PreOnBoarding Frontend Course | ||
--- | ||
|
||
## ์์ | ||
|
||
https://github.com/wanted-pre-onboarding-fe-6th-team2/pre-onboarding-assignment-week-5-1-team-2 | ||
|
||
๋ง์ง๋ง ๊ณผ์ ๋ ๊ฒ์ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๊ณผ์ ๋ค. ๋ง์ ๊ธฐ๋ฅ์ด ํฌํจ๋ ๊ฒ์ ์๋๊ธฐ ๋๋ฌธ์ 2๋ช ์ฉ ํ์ด ํ๋ก๊ทธ๋๋ฐ์ ํ๊ธฐ๋ก ํ๋ค. ์ด๋ฒ ์ฝ์ค์์ ํ๋ฒ๋ ๋ด๋นํ์ง ์์ API ๋ก์ง ๊ด๋ จ ํํธ๋ฅผ ๋ด๋นํ๊ฒ ๋์ด API ๋ก์ง์ ์ด๋ป๊ฒ ํ๋ฉด ์ฌ์ฌ์ฉ์ฑ๊ณผ ํ์ฅ์ฑ์ ๊ฐ์ง๋ฉด์ ๋ถ๋ฆฌํ ์ง์ ๋ํด ๊ณ ๋ฏผ์ ๋ง์ด ํ๋ค. | ||
|
||
## ์๊ตฌ์ฌํญ ๋ถ์ | ||
|
||
API ๋ก์ง ๊ด๋ จ ์๊ตฌ์ฌํญ์ ๋ค์๊ณผ ๊ฐ๋ค. | ||
|
||
- API ํธ์ถ๋ณ๋ก ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํ์ง ์๊ณ ๋ก์ปฌ ์บ์ฑ์ ๊ตฌํ | ||
- ์ ๋ ฅ๋ง๋ค API๋ฅผ ํธ์ถํ์ง ์๋๋ก API ํธ์ถ์ ์ค์ด๋ ์ ๋ต ์๋ฆฝ | ||
- API ํธ์ถ ํ์๋ฅผ ํ์ ํ ์ ์๋๋ก ํธ์ถ๋ง๋ค `console.info` ์ฒ๋ฆฌ | ||
|
||
์ด ์ค API ๋ก์ง์ ๊ตฌํํ๋ ๊ฒ ์์ฒด์ ํธ์ถ ํ์ ํ์ ๊ด๋ จ ์๊ตฌ์ฌํญ์ ๋ด๋นํ๊ณ , ์ต์ ํ์ ๋ก์ปฌ ์บ์ฑ์ ๋ค๋ฅธ ํ์๋ค์ด ๋ด๋นํ๋ค. | ||
|
||
## Axios API ๋ก์ง ๊ตฌํํ๊ธฐ | ||
|
||
ํ์ฅ์ฑ๊ณผ ์ฌ์ฌ์ฉ์ฑ์ ๊ณ ๋ คํด Axios API ๋ก์ง์ ๋ถ๋ฆฌํ ๊ฒ์ด๊ณ , Axios ๋ก์ง ๋ด์์๋ ํ์ฅ์ฑ์ ๊ณ ๋ คํด Axios ์ธ์คํด์ค๋ฅผ ์์ฑํด ์ฌ์ฌ์ฉ๋๋ `config`๋ฅผ ์ฒ๋ฆฌํ๋ค. | ||
|
||
```jsx | ||
import axios from 'axios'; | ||
|
||
const BASE_URL = 'http://localhost:4000'; | ||
|
||
const http = axios.create({ | ||
baseURL: BASE_URL, | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
export default http; | ||
``` | ||
|
||
์ด๋ ๊ฒ ์ฒ๋ฆฌํ๋ฉด | ||
|
||
- API ๋ก์ง ์ ์ฒด์ ํ์ฉ๋๋ config๋ฅผ ์ถ๊ฐํ๊ธฐ ์ฝ๋ค. | ||
- http๋ก ์ฝ๊ฒ API ๋ก์ง์ ์ถ๊ฐํ ์ ์๋ค. | ||
|
||
๋ฑ์ ์ฅ์ ์ด ์๋ค. | ||
|
||
์ดํ Axios์ request interceptor๋ฅผ ํ์ฉํด ๋ชจ๋ API ์์ฒญ์ ์๊ตฌ์ฌํญย `console.info("calling api")`๋ฅผ ์ฝ์ ํ๋ค. | ||
|
||
```jsx | ||
import axios from 'axios'; | ||
|
||
const BASE_URL = 'http://localhost:4000'; | ||
|
||
const http = axios.create({ | ||
baseURL: BASE_URL, | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
http.interceptors.request.use( | ||
(config) => { | ||
console.info('calling api'); | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
export default http; | ||
``` | ||
|
||
๋ง๋ค์ด๋ Axios ์ธ์คํด์ค์ `json-server`์ Full Text Search๋ฅผ ํ์ฉํด ๊ฒ์ API๋ฅผ ์ถ๊ฐํ๋ค. ์ด๋ ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ API์ ๊ฒฝ์ฐ ํด๋น ๊ณผ์ ์์ ๋ถํ์ํ๋ค๊ณ ์๊ฐํด ์ ๊ฑฐํ๋ค. | ||
|
||
```jsx | ||
import http from '@/api'; | ||
|
||
export const searchBySickName = async (keyword) => { | ||
try { | ||
const response = await http.get(`/sick?q=${keyword}`); | ||
|
||
return response.data; | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
}; | ||
``` | ||
|
||
## ํผ๋๋ฐฑ์ ํตํ ์ฝ๋ ๊ฐ์ | ||
|
||
Axios์ request interceptor๋ฅผ ejectํ๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ์ฌ ํจ์๋ก ๋ถ๋ฆฌํ๋ ๋ฐฉ์์ ๊ณ ๋ฏผํ์ผ๋, ์ด๋ฒ ๊ณผ์ ์์๋ ๋ถํ์ํ ์ฝ๋๋ผ๊ณ ์๊ฐ๋์ด ์์ฑํ์ง ์์๋ค. ํ์ง๋ง ํ๋นํ ํผ๋๋ฐฑ์ด์๊ธฐ ๋๋ฌธ์ ๋ค์์ ๋น์ทํ ์ ํ์ ์ฝ๋๋ฅผ ์์ฑํ ๋๋ ejectํ๋ ๊ฒฝ์ฐ์ ์ฝ๋๋ ํ ๋ฒ ์์ฑํด๋ณด๋๊ฒ ์ข์ ๊ฒ ๊ฐ๋ค. | ||
|
||
๋ํ ๋จ์ keyword๋ฅผ ์ธ์๋ก ๋ฐ์ API ํธ์ถ์ ํ๋๋ก ์ฒ๋ฆฌํ์ผ๋, ์ฝ๋ ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ ํ์ฅ์ฑ์ ๊ณ ๋ คํด ๊ฐ์ฒด ํํ๋ก ์ธ์์ ๋ฐ์ดํฐ ํ์ ์ ๋ณ๊ฒฝํ์ผ๋ฉฐ, Full Text Search ํน์ฑ์ `๋ณ ์ฝ๋` ๋ํ ๊ฒ์์ด ๋์ด, JSON-Server์ like๋ฅผ ํ์ฉํด `๋ณ๋ช `๋ง ๊ฒ์๋๊ฒ๋ ์ถ๊ฐ์ ์ผ๋ก ์์ ํ๋ค. | ||
|
||
```jsx | ||
import http from '@/api'; | ||
|
||
export const searchBySickName = async ({ keyword }) => { | ||
try { | ||
const response = await http.get(`/sick?sickNm_like=${keyword}`); | ||
|
||
return response.data; | ||
} catch (error) { | ||
throw new Error(error); | ||
} | ||
}; | ||
``` | ||
|
||
## ๋ง๋ฌด๋ฆฌ | ||
|
||
ํ๋ฒ๋ ํด๋ณด์ง ์์๋ API ํธ์ถ ๋ก์ง ๊ฐ์ ์ ํด๋ณด๋ฉด์, ์์ ๊ฐ์ ์ป๊ฒ ๋๋ค. ์ฌ์ง์ด ์ข์ ํผ๋๋ฐฑ์ ๋ฐํ์ผ๋ก ์ฝ๋๋ฅผ ํ๋ํ๋ ๊ฐ์ ํด๋๊ฐ๋ฉด์ ์ ๋ง ์ฑ์ทจ๊ฐ์ ๋๊ผ๋ค. ์ข์ ํ์๋ค์ ๋ง๋ ์ฌ๋ฐ๊ฒ ๊ณผ์ ๋ฅผ ์ํํ๊ณ ์ค๋ ฅ์๋ ํ์๋ค์ ์ฝ๋๋ฅผ ๋ฆฌ๋ทฐํ๋ฉด์ ์ ๋ง ์ฌ๋ฐ์๋คโฆ! | ||
|
||
๋! ๐๐ปโโ๏ธ |