feat: add pieces page

This commit is contained in:
Alessandre Laguierce 2024-12-03 19:24:26 +01:00
parent 12da240bad
commit e54159b323
5 changed files with 140 additions and 17 deletions

View File

@ -1,4 +1,4 @@
import { Request, Response } from 'express';
import { Request, RequestHandler, Response } from 'express';
import { Colour, Pattern, Shape, Piece, ComplexPiece } from '../types/piece';
import { Either, eitherLeft, eitherRight, eitherFormatError } from '../utils/utils';
import { getEntity, getEntities, registerEntity, toColour, getColour, getColours, createColour, toPattern, getPattern, getPatterns, createPattern, toShape, getShape, getShapes, createShape, getPiece, getPieces, createPiece } from '../services/pieces.service';
@ -90,4 +90,36 @@ const registerPiece = async (req: Request, res: Response) => {
res.send(createPiece(colour.left, pattern.left, shape.left));
};
export { retrieveColour, retrieveColours, registerColour, retrievePattern, retrievePatterns, registerPattern, retrieveShape, retrieveShapes, registerShape, retrievePiece, retrievePieces, registerPiece };
const allPieces: RequestHandler = async (_req, res) => {
const pieces = await getPieces();
res.render('pieces.ejs', { pieces });
};
const pieceById: RequestHandler<{ id: number; }> = async (req, res) => {
const pieceEither: Either<Piece, string> = await getPiece(req.params.id);
if (pieceEither.hasRight) {
res.status(400).send();
return;
}
const piece: Piece = pieceEither.left;
res.render('piece.ejs', { piece });
};
const pieceController = {
allPieces,
pieceById,
retrieveColour,
retrieveColours,
registerColour,
retrievePattern,
retrievePatterns,
registerPattern,
retrieveShape,
retrieveShapes,
registerShape,
retrievePiece,
retrievePieces,
registerPiece
};
export default pieceController;

View File

@ -18,8 +18,8 @@ routes.get("/rendu", (_req, res) => {
routes.use("/static", express.static(path.join(__dirname, '../static')));
routes.use("/auth", authRoute);
routes.use("/marques", getUsername, verifyAuthentication, marquesRoute);
routes.use("/pieces", getUsername, verifyAuthentication, piecesRoute);
routes.use("/marques", marquesRoute);
routes.use("/pieces", piecesRoute);
routes.use("/membres", memberRouter);
routes.use("/models", modelRouter);
routes.use("/boxes", boxRouter);

View File

@ -1,19 +1,19 @@
import express from 'express';
import { retrieveColour, retrieveColours, registerColour, retrievePattern, retrievePatterns, registerPattern, retrieveShape, retrieveShapes, registerShape, retrievePiece, retrievePieces, registerPiece } from '../controllers/piece.controller';
import pieceController from '../controllers/piece.controller';
const router = express.Router();
router.get("/colour", retrieveColours);
router.get("/colour/:id", retrieveColour);
router.post("/colour/register", registerColour);
router.get("/pattern", retrievePatterns);
router.get("/pattern/:id", retrievePattern);
router.post("/pattern/register", registerPattern);
router.get("/shape", retrieveShapes);
router.get("/shape/:id", retrieveShape);
router.post("/shape/register", registerShape);
router.get("/", retrievePieces);
router.get("/:id", retrievePiece);
router.post("/register", registerPiece);
router.get("/colour", pieceController.retrieveColours);
router.get("/colour/:id", pieceController.retrieveColour);
router.post("/colour/register", pieceController.registerColour);
router.get("/pattern", pieceController.retrievePatterns);
router.get("/pattern/:id", pieceController.retrievePattern);
router.post("/pattern/register", pieceController.registerPattern);
router.get("/shape", pieceController.retrieveShapes);
router.get("/shape/:id", pieceController.retrieveShape);
router.post("/shape/register", pieceController.registerShape);
router.get("/", pieceController.allPieces);
router.get("/:id", pieceController.pieceById);
router.post("/register", pieceController.registerPiece);
export default router;

View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Information - <%=piece.id_piece%>
</title>
<%- include('partials/links.ejs') %>
</head>
<body>
<%- include('partials/header.ejs') %>
<main>
<h1>
Information de la pièce
</h1>
<table>
<thead>
<tr>
<th>Id Pièce</th>
<th>Couleur</th>
<th>Motif</th>
<th>Forme</th>
</tr>
</thead>
<tbody>
<tr>
<td><%=piece.id_piece%></td>
<td><%=piece.colour.name%> (<%=piece.colour.id_colour%>)</td>
<td><%=piece.pattern.name%> (<%=piece.pattern.id_pattern%>)</td>
<td><%=piece.shape.name%> (<%=piece.shape.id_shape%>)</td>
</tr>
</tbody>
</table>
</main>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Liste des membres
</title>
<%- include('partials/links.ejs') %>
</head>
<body>
<%- include('partials/header.ejs') %>
<main>
<h1>
Liste des pièces
</h1>
<table>
<thead>
<tr>
<th>Id Pièce</th>
<th>Couleur</th>
<th>Motif</th>
<th>Forme</th>
</tr>
</thead>
<tbody>
<% pieces.forEach(function(p) { %>
<tr>
<td><%=p.id_piece%></td>
<td><%=p.colour.name%> (<%=p.colour.id_colour%>)</td>
<td><%=p.pattern.name%> (<%=p.pattern.id_pattern%>)</td>
<td><%=p.shape.name%> (<%=p.shape.id_shape%>)</td>
</tr>
<% }); %>
</tbody>
</table>
</main>
</body>
</html>