Skip to content

Commit 89aefb7

Browse files
author
Victor
committed
feat: add products route and its model and controller
1 parent 5847d21 commit 89aefb7

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class ProductController {
2+
async index(request, response) {
3+
4+
}
5+
6+
async find(request, response) {
7+
const { id } = request.params;
8+
}
9+
10+
async create(request, response) {
11+
const { description } = req.body;
12+
}
13+
14+
async update(request, response) {
15+
const { id } = request.params;
16+
const { description } = req.body;
17+
}
18+
19+
async delete(request, response) {
20+
const { id } = request.params;
21+
}
22+
}
23+
24+
export default new ProductController();

src/models/Product.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { connection as database } from '../config/database';
2+
3+
class Product {
4+
async find(filters) {
5+
6+
}
7+
8+
async create(data) {
9+
10+
}
11+
12+
async update(data, filters) {
13+
14+
}
15+
16+
async delete(filters) {
17+
18+
}
19+
}
20+
21+
export default new Product();

src/routes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Router } from 'express';
22
import { router as usersRouter } from './usersRoutes';
3+
import { router as productsRouter } from './productsRoutes';
34

45
const router = Router();
56

67
router.use('/users', usersRouter);
8+
router.use('/products', productsRouter);
79

810
export { router };

src/routes/productsRoutes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Router } from 'express';
2+
import ProductController from '../controllers/ProductController';
3+
4+
const router = Router();
5+
6+
router.get('/', ProductController.index);
7+
router.post('/', ProductController.create);
8+
router.get('/:id', ProductController.find);
9+
router.put('/:id', ProductController.update);
10+
router.delete('/:id', ProductController.delete);
11+
12+
export { router };

0 commit comments

Comments
 (0)