Commit bd2641e9 authored by Arthur.Pautrel's avatar Arthur.Pautrel
Browse files

Advances on frontend

parent a227deeb
......@@ -6,7 +6,7 @@ var itemSchema = new mongoose.Schema({
required: true
},
category: {
type: Schema.Types.ObjectId,
type: mongoose.Schema.Types.ObjectId,
ref: "Categories"
},
desc: String
......
......@@ -5,16 +5,12 @@ var productSchema = new mongoose.Schema({
type: String,
required: true
},
category: {
type: Schema.Types.ObjectId,
ref: "Categories"
},
item: {
type: Schema.Types.ObjectId,
type: mongoose.Schema.Types.ObjectId,
ref: "Items"
},
user: {
type: Schema.Types.ObjectId,
type: mongoose.Schema.Types.ObjectId,
ref: "Users"
},
desc: String,
......
......@@ -10,7 +10,6 @@ router.post('/create', auth.ensureSignedIn, async (req, res) => {
})
router.get('/all', async (req, res) => {
console.log("category/all")
const categories = await categoryService.findAll();
res.json(categories);
})
......
......@@ -4,5 +4,7 @@ var router = express.Router();
router.use('/auth', require('./auth'));
router.use('/user', require('./user'));
router.use('/category', require('./category'));
router.use('/item', require('./item'));
router.use('/product', require('./product'));
module.exports = router;
\ No newline at end of file
......@@ -30,3 +30,5 @@ router.get('/:id', auth.ensureSignedIn, async (req, res) => {
const result = await itemService.findById(id);
res.json(result);
})
module.exports = router;
......@@ -4,8 +4,8 @@ const productService = require("../services/product");
var router = express.Router();
router.post('/create', auth.ensureSignedIn, async (req, res) => {
const { title, category, item, user, imageUrl, desc } = req.body;
const result = await productService.create(title, category, item, user, imageUrl, desc);
const { title, item, user, imageUrl, desc } = req.body;
const result = await productService.create(title, item, user, imageUrl, desc);
res.json(result);
})
......@@ -29,4 +29,6 @@ router.get('/:id', auth.ensureSignedIn, async (req, res) => {
const { id } = req.params;
const result = await productService.findById(id);
res.json(result);
})
\ No newline at end of file
})
module.exports = router;
\ No newline at end of file
......@@ -10,12 +10,6 @@ router.get('/me', auth.ensureSignedIn, auth.currentUser, async (req, res) => {
res.json(result);
})
router.get('/:id', auth.ensureSignedIn, auth.currentUser, async (req, res) => {
const { id } = req.params;
const result = await userService.findById(id);
res.json(result);
})
router.get('/users', auth.ensureSignedIn, async (req, res) => {
const users = await userService.getUsers();
res.json(users);
......@@ -42,4 +36,10 @@ router.post('/delete-user', auth.ensureSignedIn, auth.currentUser, async (req, r
res.json(deletedUser);
})
router.get('/:id', auth.ensureSignedIn, auth.currentUser, async (req, res) => {
const { id } = req.params;
const result = await userService.findById(id);
res.json(result);
})
module.exports = router;
\ No newline at end of file
......@@ -26,11 +26,10 @@ const findAll = async () => {
}
}
const create = async (title, category, item, user, imageUrl, desc) => {
const create = async (title, item, user, imageUrl, desc) => {
try {
const newProduct = {
title,
category,
title,
item,
user,
imageUrl,
......
<script>
import Product from "./Product.vue"
export default {
data() {
return {
users: [],
}
return {
categories: [],
items: [],
products: [],
categoryClickedId: "",
itemClickedId: "",
};
},
methods: {
categoryClicked: function (idCategory) {
this.categoryClickedId = idCategory;
this.itemClickedId = "";
},
itemClicked: function (idItem) {
this.itemClickedId = idItem;
}
},
async created() {
try {
const res = await this.$http.get(`http://localhost:3001/user/users`);
this.users = res.data;
console.log(res.data)
} catch (error) {
console.log(error);
}
}
try {
const resCategories = await this.$http.get(`http://localhost:3001/category/all`);
this.categories = resCategories.data.data;
}
catch (error) {
console.log(error);
}
try {
const resItems = await this.$http.get(`http://localhost:3001/item/all`);
this.items = resItems.data.data;
}
catch (error) {
console.log(error);
}
try {
const resProducts = await this.$http.get(`http://localhost:3001/product/all`);
this.products = resProducts.data.data;
}
catch (error) {
console.log(error);
}
},
components: { Product }
}
</script>
<template>
<div id="app">
<h1>Shopping List</h1>
<h1>MarketPlace</h1>
</div>
<ul>
<li v-for="user of users" :key="user._id">
{{ user.firstName }}
<!-- Categories -->
<h2>Categories</h2>
<ul id="categories" v-for="category of categories" :key="category._id">
<li v-on:click="categoryClicked(category._id)">
{{ category.name }}
</li>
</ul>
<!-- Items -->
<h2>Items</h2>
<ul id="items" v-for="item of items" :key="item._id">
<li v-if="item.category == this.categoryClickedId" v-on:click="itemClicked(item._id)">
{{ item.name }}
</li>
</ul>
<!-- Products -->
<h2>Products</h2>
<ul v-for="product of products" :key="product._id">
<li v-if="product.item == this.itemClickedId">
<Product :product="product"/>
</li>
</ul>
</template>
<style scoped>
</style>
\ No newline at end of file
<template>
<div class="borderProduct">
<span class="colorIdentifierFields">Name : </span><span>{{product.title}}</span>
<p></p>
<span class="colorIdentifierFields">Description : </span><span>{{product.desc}}</span>
<p></p>
<span class="colorIdentifierFields">Url image : </span><span>{{product.imageUrl}}</span>
</div>
</template>
<script>
export default {
props: {
product: "",
}
}
</script>
<style scoped>
.borderProduct {
border-width:1px;
border-style:solid;
border-color:black;
border-radius: 15px;
padding: 10px;
margin: 1%;
}
</style>
\ No newline at end of file
......@@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import RegisterView from '../views/RegisterView.vue'
import MarketView from '../views/MarketView.vue'
import ProductView from '../views/ProductView.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
......@@ -20,7 +21,12 @@ const router = createRouter({
path: '/market',
name: 'market',
component: MarketView
}
},
{
path: '/product',
name: 'product',
component: ProductView
},
]
})
......
<script setup>
import Product from '@/components/Product.vue'
</script>
<template>
<main>
<Product/>
</main>
</template>
Supports Markdown
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