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