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 diff --git a/challenges/crud/backend/Dockerfile b/challenges/crud/backend/Dockerfile new file mode 100644 index 0000000..611919d --- /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 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 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