Commit bbd71444 authored by 박상호's avatar 박상호 🎼
Browse files

hello it's me NICE TO MEET YOU

parent 32e08aba
import axios from 'axios'; import axios from 'axios';
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Row, Col, Form, Card, Button } from 'react-bootstrap'; import { Row, Col, Form, Card, Button, Image } from 'react-bootstrap';
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import catchErrors from '../utils/catchErrors'; import catchErrors from '../utils/catchErrors';
...@@ -29,7 +29,7 @@ function Product({ match, location }) { ...@@ -29,7 +29,7 @@ function Product({ match, location }) {
} }
function pushOptions() { function pushOptions() {
setCart([...cart, { color, size, productId: product.id, count:1 }]) setCart([...cart, { color, size, productId: product.id, count: 1 }])
selected.sizes = false selected.sizes = false
selected.colors = false selected.colors = false
console.log(product) console.log(product)
...@@ -53,8 +53,8 @@ function Product({ match, location }) { ...@@ -53,8 +53,8 @@ function Product({ match, location }) {
e.preventDefault() e.preventDefault()
let preprice = 0 let preprice = 0
const asd = cart.filter((el) => el.color !== e.target.id || el.size !== e.target.name) const asd = cart.filter((el) => el.color !== e.target.id || el.size !== e.target.name)
asd.map((el)=>{ asd.map((el) => {
preprice = preprice + el.count *product.price preprice = preprice + el.count * product.price
}) })
setCart(asd) setCart(asd)
setPrice(Number(preprice)) setPrice(Number(preprice))
...@@ -69,8 +69,8 @@ function Product({ match, location }) { ...@@ -69,8 +69,8 @@ function Product({ match, location }) {
} }
}) })
let preprice = 0 let preprice = 0
addCount.map((el)=>{ addCount.map((el) => {
preprice = preprice + el.count *product.price preprice = preprice + el.count * product.price
}) })
setPrice(Number(preprice)) setPrice(Number(preprice))
setCart(addCount) setCart(addCount)
...@@ -163,8 +163,24 @@ function Product({ match, location }) { ...@@ -163,8 +163,24 @@ function Product({ match, location }) {
</Row> </Row>
<Row className="justify-content-center mt-5 mx-0"> <Row className="justify-content-center mt-5 mx-0">
<Col sm={11} md={8}> <Col sm={11} md={8}>
<h3 style={{ borderBottom: "1px solid #91877F", paddingBottom: "5px", marginBottom: "1em" }}>설명</h3> <h3 style={{ borderBottom: "1px solid #91877F", paddingBottom: "5px", marginBottom: "1em" }} className="p-3">
<div></div> 설명
</h3>
<Col className='m-3 text-center d-flex justify-content-center'>
<div style={{ wordBreak: 'break-all', wordWrap: 'break-word', fontFamily: "맑은 고딕" }} className="p-3">
<h1 className='m-3'>{product.name} </h1>
<>
<Image src={`/images/${product.main_img}`} style={{ objectFit: "contain", width: '100%'}} />
</>
<Card className='m-3 d-flex justify-content-center'>
<Card.Body>
{product.description}
</Card.Body>
</Card>
<h3 className='mt-5'>[ Detail Images ]</h3>
<Image src={`/images/${product.detail_imgs}`} style={{ objectFit: "contain"}} className='m-3' />
</div>
</Col>
</Col> </Col>
</Row> </Row>
<Row className="justify-content-center mx-0 pt-3 px-2" style={{ position: "fixed", bottom: "0", width: "100%", backgroundColor: "#fff" }}> <Row className="justify-content-center mx-0 pt-3 px-2" style={{ position: "fixed", bottom: "0", width: "100%", backgroundColor: "#fff" }}>
......
...@@ -136,7 +136,7 @@ function ProductsRegist() { ...@@ -136,7 +136,7 @@ function ProductsRegist() {
for (let key in product) { for (let key in product) {
if (key === "main_image" || key === "detail_image") { if (key === "main_image" || key === "detail_image") {
formData.append(key, product[key][0]) formData.append(key, product[key][0])
} else if(key === "sizes" || key === "colors"){ } else if(key === "sizes" || key === "colors" || key === 'sub_category'){
for (let i = 0; i < product[key].length ; i++){ for (let i = 0; i < product[key].length ; i++){
formData.append([key], product[key][i]) formData.append([key], product[key][i])
} }
......
...@@ -30,8 +30,9 @@ function ProductsList({ match }) { ...@@ -30,8 +30,9 @@ function ProductsList({ match }) {
const response = await axios.get(`/api/categories/sub/${mainCategory}`) const response = await axios.get(`/api/categories/sub/${mainCategory}`)
setSubcategory(Object.values(response.data)[0]) setSubcategory(Object.values(response.data)[0])
console.log("response data=", response.data) // console.log("response data=", response.data)
console.log("object value=", Object.values(response.data)); // console.log("object value=", Object.values(response.data));
// console.log("object value=2", Object.values(response.data)[0]);
} catch (error) { } catch (error) {
catchError(error, setError) catchError(error, setError)
...@@ -39,9 +40,10 @@ function ProductsList({ match }) { ...@@ -39,9 +40,10 @@ function ProductsList({ match }) {
} }
async function getProductlist() { async function getProductlist() {
console.log("tlfgpd")
try { try {
const response = await axios.get(`/api/product/getproduct/${mainCategory}`) const response = await axios.get(`/api/product/getproduct/main/${mainCategory}`)
console.log("response.data=", response.data) console.log("response.data=main", response.data)
setProductlist(response.data) setProductlist(response.data)
} catch (error) { } catch (error) {
...@@ -49,6 +51,46 @@ function ProductsList({ match }) { ...@@ -49,6 +51,46 @@ function ProductsList({ match }) {
} }
} }
async function handleSubname(e) {
const subname = e.target.name
console.log("subname=", subname)
try {
console.log("first test!!!!!!!!")
const response = await axios.get(`/api/product/getproduct/sub/${subname}`)
console.log("subname response data=", response.data)
setProductlist([response.data])
} catch (error) {
console.log("error22")
}
// const listvalue = Object.values(productlist)
// for (let i = 0; i < listvalue.length; i++) {
// const list = listvalue[i].sub_category[0]
// console.log("list=", list)
// console.log("include=", subcategory.includes("LONG DRESS"))
// if (listvalue[i].sub_category[0] === subcategory[0]) {
// console.log("yes")
// }
// else {
// console.log("no")
// }
}
// if (productlist.sub_category) {
// }
// console.log("list", list)
// for (let i = 0; i < list.length; i++) {
// if (response.data[i] === "subcategory") {
// console.log("handlesub=", response.data[i].sub_category)
// }
// else {
// console.log("handlesub=2 ", response.data[i].sub_category)
// }
// }
// }
return ( return (
<div> <div>
<style type="text/css"> <style type="text/css">
...@@ -75,7 +117,7 @@ function ProductsList({ match }) { ...@@ -75,7 +117,7 @@ function ProductsList({ match }) {
<h1 style={{ fontSize: "3rem" }} className="text-center">{mainCategory}</h1> <h1 style={{ fontSize: "3rem" }} className="text-center">{mainCategory}</h1>
<div className="text-center"> <div className="text-center">
<ButtonGroup className="m-3" variant="outline-light secondary" style={{ display: "inline-block" }}> <ButtonGroup className="m-3" variant="outline-light secondary" style={{ display: "inline-block" }}>
{subcategory.map(el => (<Button className="m-1" variant="secondary">{el}</Button>))} {subcategory.map(el => (<Button className="m-1" variant="secondary" name={el} onClick={handleSubname}>{el}</Button>))}
</ButtonGroup> </ButtonGroup>
</div> </div>
</Col> </Col>
......
...@@ -12,12 +12,12 @@ const getCategory = async (req, res) => { ...@@ -12,12 +12,12 @@ const getCategory = async (req, res) => {
} }
const getSubCategory = async (req, res) => { const getSubCategory = async (req, res) => {
console.log("req.params=", req.params); console.log("req.params=?(getsubcategory)", req.params);
const { sub } = req.params const { sub } = req.params
try { try {
const subcategory = await Category.findOne({}, { _id: 0}).select(`${sub}`) const subcategory = await Category.findOne({}, { _id: 0}).select(`${sub}`)
// console.log("sub= ",subcategory);
res.json(subcategory); res.json(subcategory);
console.log("sub= ",subcategory);
} catch (error) { } catch (error) {
res.status(500).send('카테고리를 불러오지 못했습니다.') res.status(500).send('카테고리를 불러오지 못했습니다.')
} }
......
...@@ -58,6 +58,15 @@ const getlist = (req, res) => { ...@@ -58,6 +58,15 @@ const getlist = (req, res) => {
} }
} }
const subname = async (req, res) => {
try {
console.log("last subname::: LET ME SEE")
res.json(req.findsubname)
} catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.')
}
}
const categoryId = async (req, res, next, category) => { const categoryId = async (req, res, next, category) => {
try { try {
const productslist = await Product.find({ main_category: category }) const productslist = await Product.find({ main_category: category })
...@@ -65,32 +74,41 @@ const categoryId = async (req, res, next, category) => { ...@@ -65,32 +74,41 @@ const categoryId = async (req, res, next, category) => {
res.status(404).send('상품을 찾을 수 없습니다.') res.status(404).send('상품을 찾을 수 없습니다.')
} }
req.productslist = productslist req.productslist = productslist
console.log("nononono", req.productslist)
next() next()
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
} }
const subgetlist = (req, res) => { const subcategoryId = async (req, res, next, subname) => {
try { try {
res.json(req.subproductslist) console.log("Please===>>>", subname)
} catch (error) { const findSubname = await Product.findOne({ sub_category: subname })
res.status(500).send('상품을 불러오지 못했습니다.') // const findSubname = await Product.find({ sub_category: { $elemMatch: { subname: req.subname }}})
} console.log("findSubname111=", findSubname)
} // const onlySub = findSubname.sub_category
// console.log(";;", onlySub)
// console.log(".", Object.values(onlySub))
const subcategoryId = async (req, res, next, subcategory) => { if (!findSubname) {
try { console.log("ㅏㅁㄴ우하ㅣㅜㅁㄴ어ㅏㅣ훔ㄴ어ㅏㅣ휴")
const subproductslist = await Product.find({ sub_category: subcategory }) const findSubname = {
if (!subproductslist) { _id: 'nothing',
res.status(404).send('상품을 찾을 수 없습니다.') pro_name: '상품준비중',
price: 0,
main_imgUrl:''
}
console.log("findSubname2222=", findSubname)
res.send(findSubname)
} }
req.subproductslist = subproductslist res.send(findSubname)
next() // next()
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.send('상품을 불러오지 못했습니다.')
} }
} }
//https://docs.mongodb.com/manual/reference/operator/projection/elemMatch/index.html
const plusPurchase = async (req, res) => { const plusPurchase = async (req, res) => {
const { products } = req.body const { products } = req.body
...@@ -99,7 +117,7 @@ const plusPurchase = async (req, res) => { ...@@ -99,7 +117,7 @@ const plusPurchase = async (req, res) => {
for (let i = 0; i < products.length; i++) { for (let i = 0; i < products.length; i++) {
const count = products[i].count const count = products[i].count
const product = await Product.findOne( const product = await Product.findOne(
{_id: products[i].productId._id } { _id: products[i].productId._id }
) )
const purchase = product.purchase const purchase = product.purchase
await Product.updateOne( await Product.updateOne(
...@@ -114,4 +132,4 @@ const plusPurchase = async (req, res) => { ...@@ -114,4 +132,4 @@ const plusPurchase = async (req, res) => {
} }
} }
export default { imageUpload, regist, getToHome, getAll, categoryId, getlist, subcategoryId, subgetlist, plusPurchase } export default { imageUpload, regist, getToHome, getAll, categoryId, getlist, subcategoryId, subname, plusPurchase }
\ No newline at end of file \ No newline at end of file
...@@ -32,7 +32,7 @@ const userById = async (req, res, next, id) => { ...@@ -32,7 +32,7 @@ const userById = async (req, res, next, id) => {
const signup = async (req, res) => { const signup = async (req, res) => {
const { name, number1, number2, id, password, tel, email } = req.body const { name, number1, number2, id, password, tel, email } = req.body
console.log("whatup",req.body) console.log("whatup", req.body)
try { try {
if (!isLength(password, { min: 8, max: 15 })) { if (!isLength(password, { min: 8, max: 15 })) {
return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.') return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.')
......
...@@ -13,16 +13,16 @@ router.route('/getproduct') ...@@ -13,16 +13,16 @@ router.route('/getproduct')
router.route('/getproduct/all') router.route('/getproduct/all')
.get(productCtrl.getAll) .get(productCtrl.getAll)
router.route('/getproduct/:category') router.route('/getproduct/main/:category')
.get(productCtrl.getlist) .get(productCtrl.getlist)
router.route('/getproduct/:subcategory') router.route('/getproduct/sub/:subname')
.get(productCtrl.subgetlist) .get(productCtrl.subname)
router.route('/pluspurchase') router.route('/pluspurchase')
.post(productCtrl.plusPurchase) .post(productCtrl.plusPurchase)
router.param('category', productCtrl.categoryId) router.param('category', productCtrl.categoryId)
router.param('subcategory',productCtrl.subcategoryId) router.param('subname',productCtrl.subcategoryId)
export default router export default router
\ No newline at end of file
const inventory = {
sibal: [
{ name: 'apples', quantity: 2 },
{ name: 'bananas', quantity: 4 },
{ name: 'cherries', quantity: 9 }
]
}
const result = inventory.find(fruit => fruit.name === 'cherries');
const what = inventory.find({},{ sibal: { $elemMatch: { quantity: 2 } } })
// db.schools.find( { zipcode: "63109" },
// { students: { $elemMatch: { school: 102, age: { $gt: 10} } } } )
console.log(result);
console.log(what);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment