Skip to content

Commit 809de56

Browse files
committed
restructure endpoint to use Express Router, add .gitignore, configure /gpul-templates/gpul-school-talk endpoint
1 parent ffff8ba commit 809de56

File tree

9 files changed

+219
-92
lines changed

9 files changed

+219
-92
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.node_modules
1+
node_modules/

auto-gpul-school-talk.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

index.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
const express = require('express');
2-
const swaggerUi = require('swagger-ui-express');
3-
const swaggerJsDoc = require('swagger-jsdoc');
1+
import express from 'express';
2+
import swaggerUi from 'swagger-ui-express';
3+
import swaggerJsDoc from 'swagger-jsdoc';
4+
import gpulTemplatesRouter from './routes/gpul-templates.js';
45

56
const app = express();
67
const port = process.env.PORT || 3000;
78

89
const swaggerOptions = {
910
swaggerDefinition: {
11+
openapi: '3.0.0',
1012
myApi: '0.1.0',
1113
info: {
1214
title: 'GPUL API',
@@ -15,25 +17,18 @@ const swaggerOptions = {
1517
},
1618
servers: [
1719
{
18-
url: 'http://localhost:300'
20+
url: 'http://localhost:3000'
1921
}
2022
],
2123
},
2224
apis: ['./routes/*.js'],
2325
};
2426

2527
const swaggerDocs = swaggerJsDoc(swaggerOptions);
26-
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
27-
28-
app.get('/api/hello', (req, res) => {
29-
res.send('Hello World!');
30-
})
31-
32-
app.get('/gpul-templates', (req, res) => {
33-
34-
res.send('Hello World!');
35-
})
28+
app.use(express.json())
29+
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
3630

31+
app.use('/', gpulTemplatesRouter);
3732

3833
app.listen(port, () => {
3934
console.log(`Server is running on http://localhost:${port}`);

package-lock.json

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"swagger-ui-express": "^5.0.1"
1616
},
1717
"devDependencies": {
18+
"@types/express": "^5.0.3",
19+
"@types/node": "^24.0.10",
1820
"ejs": "^3.1.10"
19-
}
21+
},
22+
"type": "module"
2023
}

public/talk.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
</div>
8888
<p class="time-and-place">
8989
06/07/2025 8:30 a 10:30<br>
90-
Aula 3.5 - Facultade de Informática
90+
Aula Aula de exámenes - Facultade de Informática
9191
</p>
9292
<p class="description">
9393

routes/gpul-templates.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import ejs from 'ejs';
4+
import domToImage from 'dom-to-image-more';
5+
import express from 'express';
6+
7+
const router = express.Router();
8+
9+
//Paths
10+
const startTimestamp = '';
11+
const endTimestamp = '';
12+
/**
13+
* @openapi
14+
* /gpul-templates/gpul-school-talk:
15+
* post:
16+
* summary: Generates a sign for a GPUL School Talk given the provided information.
17+
* tags:
18+
* - Templates
19+
* requestBody:
20+
* description: Information about the talk
21+
* required: true
22+
* content:
23+
* application/json:
24+
* schema:
25+
* type: object
26+
* properties:
27+
* title:
28+
* type: string
29+
* startTime:
30+
* type: string
31+
* endTime:
32+
* type: string
33+
* date:
34+
* type: string
35+
* classroom:
36+
* type: string
37+
* building:
38+
* type: string
39+
* description:
40+
* type: string
41+
* example:
42+
* title: "Arquitectura ECS con Bevy como ejemplo"
43+
* startTime: "8:30"
44+
* endTime: "10:30"
45+
* date: "06/07/2025"
46+
* classroom: "3.5"
47+
* building: "Facultade de Informática"
48+
* description: ""
49+
* responses:
50+
* 201:
51+
* description: Created
52+
* 400:
53+
* description: Bad Request
54+
*/
55+
56+
router.post('/gpul-templates/gpul-school-talk', (req, res) => {
57+
58+
const talk = req.body;
59+
60+
generate(talk);
61+
res.send('Hello World!');
62+
})
63+
64+
export function generate(talk) {
65+
66+
const templatePath = "templates/gpul-school-talk.ejs";
67+
const outputPath = "public/talk.html"
68+
69+
ejs.renderFile(templatePath, {talk }, (err, renderedHtml) => {
70+
if(err) {
71+
console.error("Error while rendering template", err);
72+
return;
73+
}
74+
75+
fs.writeFile(outputPath, renderedHtml, (err) => {
76+
if(err) {
77+
console.error('Error writing HTML file:', err);
78+
return;
79+
}
80+
console.log(`output HTML generated at: ${outputPath}`);
81+
}
82+
)
83+
});
84+
85+
}
86+
87+
export default router;

routes/hello.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

templates/gpul-school-talk.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ p {
8787
</div>
8888
<p class="time-and-place">
8989
<%= talk.date %> <%= talk.startTime %> a <%= talk.endTime %><br>
90-
Aula <%= talk.classroom %> - <%= talk.building %>
90+
<%= talk.classroom %> - <%= talk.building %>
9191
</p>
9292
<p class="description">
9393
<%= talk.description %>

0 commit comments

Comments
 (0)