From 0025cf87f4ad6e3864442cef5e4e82a70a30c463 Mon Sep 17 00:00:00 2001 From: Maycon Brito Date: Sat, 10 Oct 2020 15:20:00 -0300 Subject: [PATCH 1/5] Docker file para o backend do crud * Expose na porta 3004 * Imagem alpine do node 14 --- challenges/crud/backend/Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 challenges/crud/backend/Dockerfile diff --git a/challenges/crud/backend/Dockerfile b/challenges/crud/backend/Dockerfile new file mode 100644 index 0000000..f2ada08 --- /dev/null +++ b/challenges/crud/backend/Dockerfile @@ -0,0 +1,9 @@ +FROM node:14-alpine + +COPY . /app +WORKDIR /app + +RUN yarn install +EXPOSE 3004 + +ENTRYPOINT ["yarn", "start", "PORT=3004"] \ No newline at end of file From 9417cf7db4e6bb6e462f02d1797fc763c60993d3 Mon Sep 17 00:00:00 2001 From: Maycon Brito Date: Sat, 10 Oct 2020 15:24:25 -0300 Subject: [PATCH 2/5] =?UTF-8?q?Dockerfile=20para=20conteineriza=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20CRUD=20-=20Backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Imagem Node 14 versão alpine * Expose na porta 3004 --- challenges/crud/backend/Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/challenges/crud/backend/Dockerfile b/challenges/crud/backend/Dockerfile index f2ada08..611919d 100644 --- a/challenges/crud/backend/Dockerfile +++ b/challenges/crud/backend/Dockerfile @@ -1,9 +1,9 @@ -FROM node:14-alpine - -COPY . /app -WORKDIR /app - -RUN yarn install -EXPOSE 3004 - +FROM node:14-alpine + +COPY . /app +WORKDIR /app + +RUN yarn install +EXPOSE 3004 + ENTRYPOINT ["yarn", "start", "PORT=3004"] \ No newline at end of file From 278edf4ae562e645e50dc6478c8bb959b8289eee Mon Sep 17 00:00:00 2001 From: Maycon Brito Date: Sat, 10 Oct 2020 15:45:28 -0300 Subject: [PATCH 3/5] =?UTF-8?q?Dockerfile=20para=20conteineriza=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20CRUD=20-=20Frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Imagem Node 14 versão alpine * Expose na porta 3004 --- challenges/crud/frontend/Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 challenges/crud/frontend/Dockerfile diff --git a/challenges/crud/frontend/Dockerfile b/challenges/crud/frontend/Dockerfile new file mode 100644 index 0000000..0979323 --- /dev/null +++ b/challenges/crud/frontend/Dockerfile @@ -0,0 +1,9 @@ +FROM node:14-alpine + +COPY . /app +WORKDIR /app + +RUN yarn install +EXPOSE 3000 + +ENTRYPOINT ["yarn", "start", "PORT=3000"] \ No newline at end of file From e5c65e2e8f334a325d6c4471cc3041d2e9348cdb Mon Sep 17 00:00:00 2001 From: Maycon Brito Date: Sat, 10 Oct 2020 17:01:14 -0300 Subject: [PATCH 4/5] Docker file para a calculadora * Expose na porta 3000 * Imagem alpine do node 14 --- challenges/calculadora/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 challenges/calculadora/Dockerfile diff --git a/challenges/calculadora/Dockerfile b/challenges/calculadora/Dockerfile new file mode 100644 index 0000000..d91cc91 --- /dev/null +++ b/challenges/calculadora/Dockerfile @@ -0,0 +1,14 @@ +FROM node:14-alpine + +COPY . /app +WORKDIR /app +ENV PATH /app/node_modules/.bin:$PATH + +RUN yarn install +RUN yarn build +EXPOSE 3000 + +# +# This container needs to be runned in interactive mode (tty) +# +ENTRYPOINT ["yarn", "start", "PORT=3000"] \ No newline at end of file From 8a8872e5e62b2daaadb9b418e3cc16055d1e391c Mon Sep 17 00:00:00 2001 From: Maycon Brito Date: Mon, 12 Oct 2020 23:11:55 -0300 Subject: [PATCH 5/5] Implementando rotas e o controller de commits completo --- .../src/controllers/CommitController.js | 47 ++++++++++++++++--- challenges/crud/backend/src/routes.js | 20 ++++++-- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/challenges/crud/backend/src/controllers/CommitController.js b/challenges/crud/backend/src/controllers/CommitController.js index 2223738..694415e 100644 --- a/challenges/crud/backend/src/controllers/CommitController.js +++ b/challenges/crud/backend/src/controllers/CommitController.js @@ -3,25 +3,58 @@ const connection = require("../database/Connection"); module.exports = { async index(req, res) { - //#Erorr002155 + connection('commits').select() + .then((rows) => { + res.status(200).json(rows); + }) + .catch(err => { console.log(err); throw err; }); }, async indexById(req, res) { - //#Erorr002155 + connection('commits').select().where({ id: req.params.id }) + .then((rows) => { + res.status(200).json(rows); + }) + .catch(err => { console.log(err); throw err; }); + }, async create(req, res) { - //#Erorr002155 + connection.table('commits').insert({ + nome: req.body['name'], + descricao: req.body['description'], + branch_id: req.body['branch'] + }).then(() => { + res.status(200).json({ + status: 'success' + }); + }).catch(err => { console.log(err); throw err; }); }, async edit(req, res) { - //#Erorr002155 + if (req.body['id'] == undefined) { + res.status(404).json(); + + } else { + connection.table('commits') + .where({ id: req.body['id'] }) + .update({ + nome: req.body['name'], + descricao: req.body['description'], + branch_id: req.body['branch'] + }).then(() => { + res.status(200).json({ + status: 'success' + }); + }).catch(err => { console.log(err); throw err; }); + } }, async delete(req, res) { - //#Erorr002155 - - return res.status(204).send(); + connection.table('commits').delete().where({ id: req.params.id }) + .then(() => { + return res.status(204).send(); + }).catch(err => { console.log(err); throw err; }); }, } \ No newline at end of file diff --git a/challenges/crud/backend/src/routes.js b/challenges/crud/backend/src/routes.js index f944127..36dbc90 100644 --- a/challenges/crud/backend/src/routes.js +++ b/challenges/crud/backend/src/routes.js @@ -4,10 +4,22 @@ const routes = express.Router(); const BranchController = require('./controllers/BranchController'); const CommitController = require('./controllers/CommitController'); -routes.get(/*'#Erroorrs12200009150'*/, /*#Erroorrs00009150*/); -routes.post(/*'#Erroorrs12200009150'*/, /*#Erroorrs00009150*/); +routes + .route('/branchs') + .get(BranchController.index) + .delete(BranchController.delete) + .post(BranchController.create) + .put(BranchController.edit); -routes.put(/*'#Erroorrs12200009150'*/, /*#Erroorrs00009150*/); -routes.delete(/*'#Erroorrs12200009150'*/, /*#Erroorrs00009150*/); +routes + .route('/commits') + .get(CommitController.index) + .post(CommitController.create) + .put(CommitController.edit); + +routes + .route('/commits/:id') + .get(CommitController.indexById) + .delete(CommitController.delete) module.exports = routes; \ No newline at end of file