์ฌํํจํค์ง ์ผํ๋ชฐ
- 2021๋ 3์ ~ 2021๋ 5์
- ๊ฐ์ธ ํ๋ก์ ํธ
- React / Hooks
- Redux
- Styled-components
- Javascript ES6+
- Third-party-library (axios, react-hook-form ๋ฑ)
- Node.js
- Express
- MongoDB
- Mongoose
- Heroku
- Third-party-library (jwt, bcrypt ๋ฑ)
์บ๋ฌ์
์ฌ๋ผ์ด๋, ํ์ด์ง๋ค์ด์
, ๊ฒ์๊ธฐ๋ฅ, ๋ฐ์ํ ์น ๋์์ธ์ ํ์์ผ๋ฉฐ
์ต์
์ ๋ฐ๋ฅธ ์ํ์ถ๋ ฅ, ์ํ ์ฅ๋ฐ๊ตฌ๋์ ๋ด๊ธฐ, ์ฃผ๋ฌธ ๋ฐ ๊ตฌ๋งคํ์ , ํ์ ๋ฐ ๋ฆฌ๋ทฐ์์ฑ, Q&A, ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์ํ ์์ฑ์
๋๋ค.
๐์ฃผ์ ๊ธฐ๋ฅ ์์ ํผ์น๊ธฐ
-
historyPage, CartPage ์ปดํฌ๋ํธ์์ useEffect hooks๋ฅผ ์ฌ์ฉํด ์ปดํฌ๋ํธ๊ฐ ๋ ๋๋ง ๋ ๋ ๋น๋๊ธฐ ์ฒ๋ฆฌ๋ฅผ ํ๊ณ ์์ต๋๋ค.
-
์ด ๋, post ์์ฒญ ๋ฐ์ดํฐ๋ก ๋ฆฌ๋์ค store์ user state๋ฅผ ์ด์ฉํด ์ด์ฉ์์ ์ฃผ๋ฌธ์ ๋ณด์, ์ฅ๋ฐ๊ตฌ๋ ์ํ์ ๊ฐ์ ธ์ค๊ณ ์๊ณ
์ฑ๊ณต์ ์ผ๋ก ๋น๋๊ธฐ ์ฒ๋ฆฌ๊ฐ ๋๊ณ ์์ต๋๋ค. -
ํ์ง๋ง ํ์ด์ง ์๋ก๊ณ ์นจ์ ํ ๊ฒฝ์ฐ ๋ฆฌ๋์ค store์ state๊ฐ ์ด๊ธฐํ ๋์ด๋ฒ๋ฆฌ๊ธฐ ๋๋ฌธ์,
user state๋ฅผ ์ด์ฉํ DB ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ ์ฌ ์ ์์์ต๋๋ค. -
๋๋ฌธ์ redux state ์ด๊ธฐํ์ ๋ํด ๊ตฌ๊ธ๋ง ํ์์ผ๋ฉฐ, ํด๊ฒฐ๋ฐฉ๋ฒ์ผ๋ก redux-persist ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
-
redux-persist๋ฅผ ์ฌ์ฉํ์ฌ redux state๋ฅผ ์น ์คํ ๋ฆฌ์ง์ ์ ์ฅํ๊ณ , ์๋ก๊ณ ์นจ ์์๋ ์ ์ฅ๊ณต๊ฐ์ ์๋ ๋ฐ์ดํฐ๋ฅผ redux์ ๋ถ๋ฌ์
state๋ฅผ ์ ์์ ์ผ๋ก ์ ์งํ๊ฒ ๋์ต๋๋ค.
-
์ํ ์ฃผ๋ฌธ ํ์ด์ง๋ฅผ ๋ณด๋ฉด ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฅ ์ต๊ทผ์ ์ฃผ๋ฌธ์ด ๋ฆฌ์คํธ ๋งจ ์์ ์ฌ๋ผ์ ์์ต๋๋ค.
-
MongoDB์์ select ํ ๋ฐ์ดํฐ๋ฅผ ์ค๋ฆ์ฐจ์์ด๋ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌ ํ ๊ฒฝ์ฐ sort() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋๊ธฐ ๋๋ฌธ์
๋ฐฐ์ด ํ๋์๋ ๋๊ฐ์ด ์ ์ฉํ๋ฉด ๋ ๊ฒ์ด๋ผ ์๊ฐํ์ต๋๋ค. -
ํ์ง๋ง sort()๋ document๋ฅผ ์ ๋ ฌํ๋ ๋ฉ์๋์ด๊ธฐ ๋๋ฌธ์ ๋ฐฐ์ด ํ์ ํ๋์์์ ์ฌ์ฉ์ด ๋ถ๊ฐ๋ฅ ํ์ต๋๋ค.
-
๋ค๋ฅธ ํด๊ฒฐ๋ฐฉ๋ฒ์ ์ฐพ๊ธฐ์ํด ๊ตฌ๊ธ๋ง์ ํ์๊ณ , aggregate() ๋ฉ์๋๋ฅผ ํตํด ๋ฐฐ์ด ํ๋๋ฅผ ๊ฐ๊ณตํ ์ ์๋ค๋ ๊ฒ์ ์์๋์ต๋๋ค.
ํด๊ฒฐํ ์ฝ๋
const history = await Payment.aggregate([ { $match: { user: ObjectId(userId) }, } { $unwind: "$products" }, { $sort: { "products.createdAt": -1 } }, { $lookup: { from: "products", localField: "products.productDetail", foreignField: "_id", as: "products.productDetail", }, }, { $unwind: "$products.productDetail" }, { $group: { products: { $push: "$products" }, _id: "$_id", user: { $first: "$user" }, createdMonth: { $first: "$createdMonth" }, }, }, ]).sort({ createdMonth: -1 });
-
$sort๋ฅผ ์ฌ์ฉํ์ฌ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ, aggregate() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด Mongoose์ populate() ๋ฉ์๋๋ก
products ์ปฌ๋ ์ document๋ฅผ ์ฐธ์กฐํ ์ ์์ด $lookup์ ์ฌ์ฉํด payments ์ปฌ๋ ์ ํ๋์ products ์ปฌ๋ ์ ํ๋๋ฅผ ์กฐ์ธ,
$group์ผ๋ก ํน์ ํ๋ ๊ทธ๋ฃนํ์ ์ํํ์ต๋๋ค.
์ด๋ฒ ํ๋ก์ ํธ๋ ์ฒ์์ผ๋ก ๋ฆฌ์กํธ๋ฅผ ๋์ ํด๋ณด์์ต๋๋ค. ์ฒ์์๋ ์์ํ ๊ฐ๋ ๋ค์ธ state, props, DOM ์ด๋ฒคํธ ํธ๋ค๋ง, ๊ทธ๋ฆฌ๊ณ Redux๋ฅผ ์ด์ฉํ ์ ์ญ ์ํ ๊ด๋ฆฌ ๋ฑ์ ์ดํดํ๋ ๋ฐ ๋ง์ ๋ ธ๋ ฅ์ด ํ์ํ์ต๋๋ค.
ํ์ง๋ง, ๊ตฌ๊ธ๋ง, ์ฑ , ๊ทธ๋ฆฌ๊ณ ์จ๋ผ์ธ ๊ฐ์๋ฅผ ์ฐธ๊ณ ํ๋ฉฐ ๊พธ์คํ ๋ ธ๋ ฅ ๋์ ๋ฆฌ์กํธ๋ฅผ ์ ์ ์ต์ํ๊ฒ ๋ค๋ฃฐ ์ ์๊ฒ ๋์์ต๋๋ค. ์ด์ ๋ ๋ฆฌ์กํธ์ ๋ํ ์ดํด์ ์๋ จ๋๊ฐ ๋์์ ธ, ์์ ์๋ฐ์คํฌ๋ฆฝํธ ์์ ์ด ์กฐ๊ธ ์ด์ํ๊ฒ ๋๊ปด์ง๊ธฐ๋ ํฉ๋๋ค.
์ด๋ฒ ํ๋ก์ ํธ์์๋ 1์ฐจ ํ๋ก์ ํธ์๋ ๋ฌ๋ฆฌ ๋ค์ํ ๊ธฐ๋ฅ์ ์ถ๊ฐํ์๋๋ฐ, ์บ๋ฌ์ ์ฌ๋ผ์ด๋, ํ์ด์ง๋ค์ด์ , ๊ทธ๋ฆฌ๊ณ ๋ฐ์ํ ํ์ด์ง ๋ฑ์ ๊ตฌํํ์ต๋๋ค. ๋ง์ ๊ธฐ๋ฅ์ ์ ์ฉํ๊ณ ์ ํ์ผ๋ ํผ์ ์งํํ๋ ํ๋ก์ ํธ๋ผ ์๊ฐ ๊ด๋ฆฌ๊ฐ ์ค์ํ๊ธฐ์, ๋๋ฉ ํ์ด์ง๋ฅผ ์ค์ ์ผ๋ก ์ฃผ์ ๊ธฐ๋ฅ๋ค์ ๊ฐ๋ฐํ์ต๋๋ค.
์ด๋ฐ ๋ ธ๋ ฅ๊ณผ ๊ฒฝํ์ ํตํด ๋ฆฌ์กํธ์ ๊ด๋ จ ๊ธฐ์ ์ ์๋ฌํ๊ณ , ๋ค์ํ ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์๋ ๋ฅ๋ ฅ์ ํค์๋๊ฐ๊ณ ์์ต๋๋ค. ์ด๋ฌํ ๊ฒฝํ์ ์์ผ๋ก์ ํ๋ก์ ํธ์์๋ ํฐ ๋์์ด ๋ ๊ฒ์ผ๋ก ๊ธฐ๋๋ฉ๋๋ค.





