Commit 58d63a89 authored by kusang96's avatar kusang96
Browse files

Merge remote-tracking branch 'origin/jaeyeon' into ourMaster

parents c932e6d2 1dca5038
...@@ -12,6 +12,8 @@ function ListCard({ id, name, price, main_img }) { ...@@ -12,6 +12,8 @@ function ListCard({ id, name, price, main_img }) {
</Card.Body> </Card.Body>
</Card> </Card>
) )
} }
export default ListCard export default ListCard
\ No newline at end of file
...@@ -43,42 +43,42 @@ function Home() { ...@@ -43,42 +43,42 @@ function Home() {
<h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem", marginTop: "2rem" }}><u>New Arrival</u></h2> <h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem", marginTop: "2rem" }}><u>New Arrival</u></h2>
<Row className="justify-content-center mx-0"> <Row className="justify-content-center mx-0">
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
</Card.Body> </Card.Body>
</Card> </Card>
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
</Card.Body> </Card.Body>
</Card> </Card>
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
</Card.Body> </Card.Body>
</Card> </Card>
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
</Card.Body> </Card.Body>
</Card> </Card>
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
</Card.Body> </Card.Body>
</Card> </Card>
<Card className="mx-1 my-2" style={{ width: '18rem' }}> <Card className="mx-1 my-2" style={{ width: '18rem' }}>
<Card.Img className="img-fluid" variant="top" src="icon/asd.jpg" /> <Card.Img className="img-fluid" variant="top" src="/icon/asd.jpg" />
<Card.Body> <Card.Body>
<Card.Title className="font-weight-bold">제품명</Card.Title> <Card.Title className="font-weight-bold">제품명</Card.Title>
<Card.Text>가격</Card.Text> <Card.Text>가격</Card.Text>
......
...@@ -33,7 +33,7 @@ function ProductsRegist() { ...@@ -33,7 +33,7 @@ function ProductsRegist() {
useEffect(async () => { useEffect(async () => {
try { try {
const response = await axios.get('/api/categories') const response = await axios.get('/api/categories/main')
const data = response.data[0] const data = response.data[0]
setCategories([Object.keys(data), Object.values(data)]) setCategories([Object.keys(data), Object.values(data)])
} catch (error) { } catch (error) {
...@@ -122,7 +122,7 @@ function ProductsRegist() { ...@@ -122,7 +122,7 @@ function ProductsRegist() {
product["sizes"] = sizes product["sizes"] = sizes
const formData = new FormData(); const formData = new FormData();
for (let key in product) { for (let key in product) {
if (key === "main_image" || key === "detail_image") { if (key === "main_image" ||key === "detail_image") {
console.log(product[key][0]) console.log(product[key][0])
formData.append(key, product[key][0]) formData.append(key, product[key][0])
} else { } else {
......
...@@ -6,40 +6,57 @@ import axios from 'axios'; ...@@ -6,40 +6,57 @@ import axios from 'axios';
import catchError from '../utils/catchErrors'; import catchError from '../utils/catchErrors';
import { isAuthenticated } from '../utils/auth'; import { isAuthenticated } from '../utils/auth';
import { Container, Row, Col, Form, FormControl, Button, Dropdown } from 'react-bootstrap'; import { Container, Row, Col, Form, FormControl, Button, Dropdown } from 'react-bootstrap';
import catchErrors from '../utils/catchErrors';
function ProductsList({ match }) { function ProductsList({ match }) {
const [mainCategory, setMainCategory] = useState(match.params.main) const [mainCategory, setMainCategory] = useState(match.params.main.toUpperCase())
const [sub, setSub] = useState(['PADDED JACKET', 'JACKET', 'JUMPER', 'COAT', 'FLEECE', 'CARDIGAN / VEST']) const [subcategory, setSubcategory] = useState([])
const [productlist, setProductlist] = useState([]) const [productlist, setProductlist] = useState([])
const [sub, setSub] = useState([])
const [error, setError] = useState('') const [error, setError] = useState('')
// const user=isAuthenticated() // const user=isAuthenticated()
useEffect(() => {
getSubsCategories()
getProductlist()
}, [mainCategory])
useEffect(() => { useEffect(() => {
setMainCategory(match.params.main.toUpperCase()) setMainCategory(match.params.main.toUpperCase())
}, [match.params.main]) }, [match.params.main])
useEffect(() => { function handleSearch() {
getProductlist()
}, [mainCategory])
// async function getProfile(user){ }
// console.log(user)
// async function handleClick(subCategory) {
// try { // try {
// const response = await axios.get(`/api/users/profile/${user}`) // const response = await axios.get(`/api/product/getproduct/${subCategory}`)
// setProfile(response.data) // console.log("response.data=", response.data)
// setProductlist(response.data)
// } catch (error) { // } catch (error) {
// catchErrors(error, setError) // catchErrors(error, setError)
// } // }
// } // }
function handleSearch() { // function handleSubmit(e) {
// e.preventDefault()
// }
async function getSubsCategories() {
try {
const response = await axios.get(`/api/categories/sub/${mainCategory}`)
console.log("sub", response.data)
setSubcategory(response.data)
} catch (error) {
catchError(error, setError)
}
} }
async function handleClick(subCategory) { async function getProductlist() {
try { try {
const response = await axios.get(`/api/product/getproduct/${subCategory}`) const response = await axios.get(`/api/product/getproduct/${mainCategory}`)
console.log("response.data=", response.data) console.log("response.data=", response.data)
setProductlist(response.data) setProductlist(response.data)
} catch (error) { } catch (error) {
...@@ -47,22 +64,24 @@ function ProductsList({ match }) { ...@@ -47,22 +64,24 @@ function ProductsList({ match }) {
} }
} }
function handleSubmit(e) { function handleClick(e){
e.preventDefault() e.preventDefault()
return getsubproductlist()
} }
async function getProductlist() { async function getsubproductlist(){
try { try {
const response = await axios.get(`/api/product/getproduct/${mainCategory}`) const response = await axios.get(`/api/product/getproduct/${subcategory}`)
console.log("response.data=", response.data) console.log("response.data sub=",response.data)
setProductlist(response.data) setProductlist(response.data)
} catch (error) { } catch (error) {
catchError(error, setError) catchErrors(error,setError)
} }
} }
return ( return (
<div> <div>
{console.log("main=",mainCategory)}
<style type="text/css"> <style type="text/css">
{` {`
a, a:hover, a:active { a, a:hover, a:active {
...@@ -85,7 +104,7 @@ function ProductsList({ match }) { ...@@ -85,7 +104,7 @@ function ProductsList({ match }) {
<Row className="justify-content-center" > <Row className="justify-content-center" >
<Col sm={10} xs={12} > <Col sm={10} xs={12} >
<h1 style={{ fontSize: "3rem" }} className="text-center">{mainCategory}</h1> <h1 style={{ fontSize: "3rem" }} className="text-center">{mainCategory}</h1>
<div className="text-center">{sub.map((ele) => ( <div className="text-center">{subcategory.map((ele) => (
<Button className="m-1" onClick={(ele) => handleClick(ele)}>{ele}</Button> <Button className="m-1" onClick={(ele) => handleClick(ele)}>{ele}</Button>
))}</div> ))}</div>
</Col> </Col>
......
...@@ -44,8 +44,6 @@ function Signup() { ...@@ -44,8 +44,6 @@ function Signup() {
} }
} }
function checkPassword(event) { function checkPassword(event) {
const p1 = user.password const p1 = user.password
const p2 = user.password2 const p2 = user.password2
......
...@@ -49,16 +49,40 @@ const getlist=(req,res)=>{ ...@@ -49,16 +49,40 @@ const getlist=(req,res)=>{
} }
} }
const categoryId = async (req, res, next, category) => { const categoryId = async (req, res, next, category) => {
try { try {
const productslist = await Product.find({main_category:category}) console.log(category)
const productslist = await Product.find({"main_category": `${category}`})
if (!productslist) { if (!productslist) {
res.status(404).send('상품을 찾을 수 없습니다.') res.status(404).send('상품을 찾을 수 없습니다.')
} }
console.log("list=",productslist)
req.productslist = productslist req.productslist = productslist
next() next()
} catch (error) { } catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.') res.status(500).send('상품을 불러오지 못했습니다.')
} }
} }
export default { imageUpload, regist, categoryId, getlist, getToHome }
\ No newline at end of file const subgetlist=(req,res)=>{
try{
res.json(req.subproductslist)
}catch(error){
res.status(500).send('상품을 불러오지 못했습니다.')
}
}
const subcategoryId = async (req, res, next, subcategory) => {
try {
const subproductslist = await Product.find({"sub_category":`${subcategory}`})
if (!subproductslist) {
res.status(404).send('상품을 찾을 수 없습니다.')
}
req.subproductslist = subproductslist
next()
} catch (error) {
res.status(500).send('상품을 불러오지 못했습니다.')
}
}
export default { imageUpload, regist, categoryId, getlist, subcategoryId, subgetlist }
...@@ -13,6 +13,11 @@ router.route('/getproduct') ...@@ -13,6 +13,11 @@ router.route('/getproduct')
router.route('/getproduct/:category') router.route('/getproduct/:category')
.get(productCtrl.getlist) .get(productCtrl.getlist)
router.route('/getproduct/:subcategory')
.get(productCtrl.subgetlist)
router.param('category', productCtrl.categoryId) router.param('category', productCtrl.categoryId)
router.param('subcategory',productCtrl.subcategoryId)
export default router export default router
\ 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