-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add book and author routes and controllers
- Loading branch information
Showing
12 changed files
with
2,499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
### Ejercicio API REST (Nodejs) | ||
|
||
**Requisitos**: Tener instalado Nodejs (v16.x.x o superior). Tener instalado npm. | ||
|
||
**Duración máxima**: 40 minutos | ||
|
||
**Enunciado**: | ||
|
||
```bash | ||
Crear una API REST en Node.js que gestione Libros y Autores. Se deben crear 2 endpoints para operar con la misma. | ||
|
||
Se puede usar almacenamiento en memoria o el sistema gestor de bases de datos de su preferencia. | ||
``` | ||
|
||
**Entidad Libro (book):** | ||
|
||
- id: number | ||
- title: string | ||
- chapters: number. Representa la cantidad de capítulos. | ||
- pages: number. Representa la cantidad de páginas. | ||
|
||
**Entidad Autor (author):** | ||
|
||
- id: number | ||
- name: string | ||
|
||
- [] _Debe existir una relación del tipo Many-to-Many entre los libros y los autores_ | ||
|
||
**Endpoints:** | ||
|
||
1. **Nuevo Libro**: Creará un nuevo libro, aportando todos sus datos incluidos los autores. | ||
2. **Obtener todos los libros**: Deberá devolver un listado de libros con sus autores. | ||
3. **Crear un autor**: Creará un nuevo autor | ||
4. **Obtener todos los autores**: Deberá devolver un listado de todos los autores con los libros que tengan. | ||
5. **Obtener Promedio de Páginas por Capítulo**: Obtener el dato de una instancia de Libro ya creada. Se debe devolver el id del libro consultado y un promedio de páginas por capítulo. Ambos en formato cadena, y con 2 decimales para el promedio. | ||
|
||
- [] _Para la prueba es necesario realizar lo que dicta el enunciado, aunque se pueden agregar características no mencionadas (manejo de errores, repositorio de datos, validaciones, etc.)._ | ||
- [] _Se pueden asumir los aspectos que no aclare el enunciado, y realizar aclaraciones personales en caso de ser necesario._ | ||
|
||
¡Mucha suerte! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
GET http://localhost:3000/books | ||
|
||
### | ||
|
||
GET http://localhost:3000/books/2/pages-average | ||
|
||
### | ||
|
||
POST http://localhost:3000/books | ||
content-type: application/json | ||
|
||
{ | ||
"id": 1, | ||
"title": "Harry Potter y la gallina partida", | ||
"chapters": 13, | ||
"pages": 356 | ||
} | ||
|
||
### | ||
|
||
GET http://localhost:3000/authors | ||
|
||
### | ||
|
||
POST http://localhost:3000/authors | ||
content-type: application/json | ||
|
||
{ | ||
"id": 2, | ||
"name": "Jorge Luis" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import express from 'express' | ||
import { bookRouter } from './src/routes/book.js' | ||
import { authorRouter } from './src/routes/author.js' | ||
|
||
const PORT = process.env.PORT ?? 3000 | ||
const app = express() | ||
|
||
app.use(express.json()) | ||
app.disable('x-powered-by') | ||
|
||
app.use('/books', bookRouter) | ||
app.use('/authors', authorRouter) | ||
|
||
const server = app.listen(PORT, () => { | ||
console.log(`Server listening on port ${PORT}`) | ||
}) | ||
|
||
server.on('error', (error) => { | ||
console.error('Error starting server:', error) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "challenge-node", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"description": "Challenge para prueba técnica de API node", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "node --watch main.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "Federico Krenn", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "4.18.2", | ||
"sequelize": "6.35.2" | ||
}, | ||
"devDependencies": { | ||
"standard": "17.1.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "standard" | ||
} | ||
} |
Oops, something went wrong.