Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Fábio Salata committed Jul 24, 2021
2 parents b1f5254 + 58b82df commit 7735098
Show file tree
Hide file tree
Showing 124 changed files with 7,588 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# Others
.DS_Store
Backend-node/node_modules
8 changes: 8 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
line_length: 140
type_body_length: 400

disabled_rules:
- identifier_name
- unused_closure_parameter
- force_cast
- file_length
2 changes: 2 additions & 0 deletions Backend-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
.DS_Store
58 changes: 58 additions & 0 deletions Backend-node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var compression = require("compression");
var morgan = require("morgan");
var counters = require("./lib/counters");

app.use(morgan("combined"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

// [json] GET /api/v1/counters
// => [
// => {id: "asdf", title: "boop", count: 4},
// => {id: "zxcv", title: "steve", count: 3}
// => ]
app.get("/api/v1/counters", function(req, res) {
res.json(counters.all())
});

// [json] POST {title: "bob"} /api/v1/counters
// => [
// => {id: "asdf", title: "boop", count: 4},
// => {id: "zxcv", title: "steve", count: 3},
// => {id: "qwer", title: "bob", count: 0}
// => ]
app.post("/api/v1/counter", function(req, res) {
res.json(counters.create(req.body.title));
})

// [json] DELETE {id: "asdf"} /api/v1/counter
// => [
// => {id: "zxcv", title: "steve", count: 3},
// => {id: "qwer", title: "bob", count: 0}
// => ]
app.delete("/api/v1/counter", function(req, res) {
res.json(counters.delete(req.body.id));
});

// [json] POST {id: "qwer"} /api/v1/counter/inc
// => [
// => {id: "zxcv", title: "steve", count: 3},
// => {id: "qwer", title: "bob", count: 1}
// => ]
app.post("/api/v1/counter/inc", function(req, res) {
res.json(counters.inc(req.body.id));
});

// [json] POST {id: "zxcv"} /api/v1/counter/dec
// => [
// => {id: "zxcv", title: "steve", count: 2},
// => {id: "qwer", title: "bob", count: 1}
// => ]
app.post("/api/v1/counter/dec", function(req, res) {
res.json(counters.dec(req.body.id));
});

app.listen(3000, console.log.bind(null, "Listening on TCP port " + 3000));
37 changes: 37 additions & 0 deletions Backend-node/lib/counters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var _ = require("lodash");
var __Counters = {};

module.exports = {
all : getAll,
create : create,
inc : applyTo("count", inc),
dec : applyTo("count", dec),
delete : del
};

function genId() {
return (+new Date() + ~~(Math.random * 999999)).toString(36);
}

function getAll() { return _.map(__Counters, _.identity); }

function create(title) {
var id = genId();
__Counters[id] = {id: id, title: title, count: 0};
return getAll();
}

function del(id) {
delete __Counters[id];
return getAll();
}

function applyTo(key, fn) {
return function(id) {
__Counters[id][key] = fn(__Counters[id][key]);
return getAll();
}
}

function inc(n) { return n + 1; }
function dec(n) { return n - 1; }
Loading

0 comments on commit 7735098

Please sign in to comment.