Compare commits
2 Commits
4ea2d039ff
...
afc8530b43
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afc8530b43 | ||
|
|
6bb2114d33 |
@@ -1,14 +1,18 @@
|
||||
import express from 'express';
|
||||
import ProductsRoutes from './routes/products/index'
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello World! 123')
|
||||
})
|
||||
res.send('Hello World! 123');
|
||||
});
|
||||
|
||||
|
||||
app.use ('/products', ProductsRoutes);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
})
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
||||
|
||||
// comment test
|
||||
18
api/src/routes/products/index.ts
Normal file
18
api/src/routes/products/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Router } from "express";
|
||||
import { listProducts,
|
||||
getProductById,
|
||||
createProduct,
|
||||
updateProduct,
|
||||
deleteProduct
|
||||
} from "./productsController";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// products endpoints
|
||||
router.get('/', listProducts);
|
||||
router.get('/:id', getProductById);
|
||||
router.post('/', createProduct);
|
||||
router.put('/:id', updateProduct);
|
||||
router.delete('/:id', deleteProduct);
|
||||
|
||||
export default router;
|
||||
21
api/src/routes/products/productsController.ts
Normal file
21
api/src/routes/products/productsController.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {Request, Response} from 'express';
|
||||
|
||||
export function listProducts(req: Request, res: Response) {
|
||||
res.send ('listProducts');
|
||||
}
|
||||
|
||||
export function getProductById(req: Request, res: Response) {
|
||||
res.send ('getProductById');
|
||||
}
|
||||
|
||||
export function createProduct(req: Request, res: Response) {
|
||||
res.send ('createProduct');
|
||||
}
|
||||
|
||||
export function updateProduct(req: Request, res: Response) {
|
||||
res.send ('updateProduct');
|
||||
}
|
||||
|
||||
export function deleteProduct(req: Request, res: Response) {
|
||||
res.send ('deleteProduct');
|
||||
}
|
||||
Reference in New Issue
Block a user