-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from Cambalab/161-replace-server-author-servi…
…ces-specific-data-generators-with-fake-data-generator 161 replace server author services specific data generators with fake data generator
- Loading branch information
Showing
8 changed files
with
220 additions
and
201 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
const createMagazinesService = require("./services/magazines"); | ||
const createArticlesService = require('./services/articles'); | ||
const createAuthorsService = require('./services/authors'); | ||
const createAuthService= require('./services/auth'); | ||
const createMagazinesService = require('./services/magazines') | ||
const createArticlesService = require('./services/articles') | ||
const createAuthorsService = require('./services/authors') | ||
const createAuthService = require('./services/auth') | ||
|
||
/* eslint-enable */ | ||
|
||
var cors = require("cors"); | ||
const app = express(); | ||
var cors = require('cors') | ||
const app = express() | ||
|
||
app.use(cors()); | ||
app.options("*", cors()); | ||
app.use(cors()) | ||
app.options('*', cors()) | ||
|
||
app.use(express.static(__dirname)); | ||
app.use(express.static(__dirname)) | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.json()) | ||
|
||
createArticlesService(app); | ||
createMagazinesService(app); | ||
createAuthService(app); | ||
createAuthorsService(app); | ||
createArticlesService(app) | ||
createMagazinesService(app) | ||
createAuthService(app) | ||
createAuthorsService(app) | ||
|
||
const port = process.env.PORT || 8080; | ||
const port = process.env.PORT || 8080 | ||
|
||
module.exports = app.listen(port, () => { | ||
/* eslint-disable no-console */ | ||
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`); | ||
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`) | ||
/* eslint-enable no-console */ | ||
}); | ||
}) |
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 |
---|---|---|
@@ -1,92 +1,91 @@ | ||
const Ipsum = require("bavaria-ipsum"); | ||
const Ipsum = require('bavaria-ipsum') | ||
|
||
module.exports = function (app) { | ||
|
||
const ipsum = new Ipsum(); | ||
module.exports = function(app) { | ||
const ipsum = new Ipsum() | ||
|
||
const articles = [ | ||
{ | ||
id: 1, | ||
title: ipsum.generateSentence(), | ||
content: ipsum.generateParagraph() | ||
content: ipsum.generateParagraph(), | ||
}, | ||
{ | ||
id: 2, | ||
title: ipsum.generateSentence(), | ||
content: ipsum.generateParagraph() | ||
content: ipsum.generateParagraph(), | ||
}, | ||
{ | ||
id: 3, | ||
title: ipsum.generateSentence(), | ||
content: ipsum.generateParagraph() | ||
} | ||
]; | ||
content: ipsum.generateParagraph(), | ||
}, | ||
] | ||
|
||
app.get("/api/articles", (req, res) => { | ||
res.json(articles); | ||
}); | ||
app.get('/api/articles', (req, res) => { | ||
res.json(articles) | ||
}) | ||
|
||
app.get("/api/articles/:id", (req, res) => { | ||
const article = articles.find(a => a.id.toString() === req.params.id); | ||
const index = articles.indexOf(article); | ||
app.get('/api/articles/:id', (req, res) => { | ||
const article = articles.find(a => a.id.toString() === req.params.id) | ||
const index = articles.indexOf(article) | ||
|
||
res.json(articles[index]); | ||
}); | ||
res.json(articles[index]) | ||
}) | ||
|
||
app.patch("/api/articles/:id", (req, res) => { | ||
const { body } = req; | ||
const article = articles.find(a => a.id.toString() === req.params.id); | ||
const index = articles.indexOf(article); | ||
app.patch('/api/articles/:id', (req, res) => { | ||
const { body } = req | ||
const article = articles.find(a => a.id.toString() === req.params.id) | ||
const index = articles.indexOf(article) | ||
|
||
if (index >= 0) { | ||
article.title = body.title; | ||
article.content = body.content; | ||
articles[index] = article; | ||
article.title = body.title | ||
article.content = body.content | ||
articles[index] = article | ||
} | ||
|
||
res.json(article); | ||
}); | ||
res.json(article) | ||
}) | ||
|
||
app.put("/api/articles/:id", (req, res) => { | ||
const { body } = req; | ||
const article = articles.find(a => a.id.toString() === req.params.id); | ||
const index = articles.indexOf(article); | ||
app.put('/api/articles/:id', (req, res) => { | ||
const { body } = req | ||
const article = articles.find(a => a.id.toString() === req.params.id) | ||
const index = articles.indexOf(article) | ||
|
||
if (index >= 0) { | ||
article.title = body.title; | ||
article.content = body.content; | ||
articles[index] = article; | ||
article.title = body.title | ||
article.content = body.content | ||
articles[index] = article | ||
} | ||
|
||
res.json(article); | ||
}); | ||
res.json(article) | ||
}) | ||
|
||
app.delete("/api/articles/:id", (req, res) => { | ||
const article = articles.find(a => a.id.toString() === req.params.id); | ||
const index = articles.indexOf(article); | ||
app.delete('/api/articles/:id', (req, res) => { | ||
const article = articles.find(a => a.id.toString() === req.params.id) | ||
const index = articles.indexOf(article) | ||
|
||
if (index >= 0) articles.splice(index, 1); | ||
if (index >= 0) articles.splice(index, 1) | ||
|
||
res.status(202).send(); | ||
}); | ||
res.status(202).send() | ||
}) | ||
|
||
app.post("/api/articles", (req, res) => { | ||
app.post('/api/articles', (req, res) => { | ||
let id | ||
if (!articles.length) { | ||
id = 0 | ||
} else { | ||
id = articles[articles.length - 1].id + 1; | ||
id = articles[articles.length - 1].id + 1 | ||
} | ||
const { body } = req; | ||
const { body } = req | ||
|
||
const article = { | ||
id, | ||
title: body.title, | ||
content: body.content | ||
}; | ||
content: body.content, | ||
} | ||
|
||
articles.push(article); | ||
articles.push(article) | ||
|
||
res.status(201).send(article); | ||
}); | ||
res.status(201).send(article) | ||
}) | ||
} |
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
Oops, something went wrong.