Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yarapolana committed Apr 25, 2020
0 parents commit f3c40bc
Show file tree
Hide file tree
Showing 93 changed files with 21,618 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
assets/Cronograma.sketch
assets/Cover

.DS_Store
*/.DS_Store
*/*/.DS_Store
*/*/*/.DS_Store

node_modules
*/node_modules
*/*/node_modules/
*/*/*/*node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 yarapolana

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# bootcamp-gostack
Repos for my GoStack Bootcamp Journey
Binary file added assets/exports/Cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/exports/github-cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/exports/notion-cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions nivel-1/node/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "backend-com-node",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon"
},
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"uuidv4": "^6.0.7"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}
99 changes: 99 additions & 0 deletions nivel-1/node/backend/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const express = require("express");
const cors = require("cors");
const { uuid, isUuid } = require("uuidv4");
const app = express();

app.use(
cors({
// origin: "http://localhost:8080",
origin: "*",
})
);

app.use(express.json());

const projects = [];

function logRequests(request, response, next) {
const { method, url } = request;

const logLabel = `[${method.toUpperCase()}] ${url}`;

console.time(logLabel);

next();

console.timeEnd(logLabel);
}

function validadeProjectId(request, response, next) {
const { id } = request.params;

if (!isUuid(id)) {
return response.status(400).json({ error: "Invalid project ID" });
}

next();
}

app.use(logRequests);
app.use("/projects/:id", validadeProjectId);

app.get("/projects", (request, response) => {
const { title } = request.query;

const results = title
? projects.filter((project) => project.title.includes(title))
: projects;

return response.json(results);
});

app.post("/projects", (request, response) => {
const { title, owner } = request.body;

const project = { id: uuid(), title, owner };

projects.push(project);

return response.json(project);
});

app.put("/projects/:id", (request, response) => {
const { id } = request.params;
const { title, owner } = request.body;

const projectIndex = projects.findIndex((project) => project.id === id);

if (projectIndex < 0) {
return response.status(400).json({ error: "Project not found" });
}

const project = {
id,
title,
owner,
};

projects[projectIndex] = project;

return response.json(project);
});

app.delete("/projects/:id", (request, response) => {
const { id } = request.params;

const projectIndex = projects.findIndex((project) => project.id === id);

if (projectIndex < 0) {
return response.status(400).json({ error: "Project not found" });
}

projects.splice(projectIndex, 1);

return response.status(204).send();
});

app.listen(3333, () => {
console.log("🚀 Server running ");
});
Loading

0 comments on commit f3c40bc

Please sign in to comment.