diff --git a/README.md b/README.md index 31d47d1..b1a318b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,28 @@ -# Shot Bot +# Beverage Bot ## Overview -A service running on Raspberry Pi which pours shots when triggered over the internet. +A service running on Raspberry Pi which pours beverages when triggered over the internet. + +### Liquors +- Dark rum +- Vodka +- Gin +- Cointreau + +### Mixers +- Tonic +- Coke +- Lemonade +- Ginger beer +- Lime juice + +### Beverages +- Cuba Libre +- Gin & Tonic +- Moscow Mule +- Dark & Stormy +- Gin/Vodka Margarita +- & more... ## Prerequisites diff --git a/docs/postman/user-registration.postman_collection.json b/docs/postman/user-registration.postman_collection.json new file mode 100644 index 0000000..a8cb7f8 --- /dev/null +++ b/docs/postman/user-registration.postman_collection.json @@ -0,0 +1,159 @@ +{ + "info": { + "_postman_id": "4b754e10-0098-4aa8-aaa7-00ea325549d3", + "name": "Mongo User Registration", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Create user", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n\t\"name\": \"Laura\",\n\t\"email\": \"me@laurabrandon.codes\",\n\t\"password\": \"pre hashed password\",\n\t\"tokens\": {\n\t\t\"token\": \"WinterIsComing\"\n\t}\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:3000/users", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User login", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n\t\"email\": \"me@laurabrandon.codes\",\n\t\"password\": \"pre hashed password\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:3000/users/login", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users", + "login" + ] + } + }, + "response": [] + }, + { + "name": "User logout", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NTM4NzZ9.PhrWofT8bKk-e7GCtczur1mhnPNVET3MEqAa--RN-t0", + "type": "text" + } + ], + "url": { + "raw": "http://localhost:3000/users/me/logout?Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NDk5OTB9.2Ol6M49XpSeFFXMlSf8AxeVwQ2oCA8KxDPUxR9WxKlU", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users", + "me", + "logout" + ], + "query": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NDk5OTB9.2Ol6M49XpSeFFXMlSf8AxeVwQ2oCA8KxDPUxR9WxKlU" + } + ] + } + }, + "response": [] + }, + { + "name": "User logout all", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "type": "text", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NDk5OTB9.2Ol6M49XpSeFFXMlSf8AxeVwQ2oCA8KxDPUxR9WxKlU" + } + ], + "url": { + "raw": "http://localhost:3000/users/me/logoutall?Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NDk5OTB9.2Ol6M49XpSeFFXMlSf8AxeVwQ2oCA8KxDPUxR9WxKlU", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users", + "me", + "logoutall" + ], + "query": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NDk5OTB9.2Ol6M49XpSeFFXMlSf8AxeVwQ2oCA8KxDPUxR9WxKlU" + } + ] + } + }, + "response": [] + }, + { + "name": "Get user", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZWIwZTAwNjQ4YTdlYTI4MGRlZWI5N2QiLCJpYXQiOjE1ODg2NTM4NzZ9.PhrWofT8bKk-e7GCtczur1mhnPNVET3MEqAa--RN-t0", + "type": "text" + } + ], + "url": { + "raw": "http://localhost:3000/users/me", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users", + "me" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 634b4af..71a1df7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2749,9 +2749,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash.debounce": { diff --git a/package.json b/package.json index 17b52a4..72c7f05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "pi-shot-bot", + "name": "pi-beverage-bot", "version": "1.0.0", - "description": "A bot which pours shots for you when triggered", + "description": "A bot which pours beverages when triggered", "main": "app.js", "scripts": { "start": "env-cmd -f ./.env nodemon src/app.js", @@ -16,9 +16,9 @@ "author": "Laura Brandon", "license": "ISC", "bugs": { - "url": "https://github.com/explaura/pi-shot-bot/issues" + "url": "https://github.com/explaura/pi-beverage-bot/issues" }, - "homepage": "https://github.com/explaura/pi-shot-bot#readme", + "homepage": "https://github.com/explaura/pi-beverage-bot#readme", "dependencies": { "onoff": "^6.0.0", "bcryptjs": "^2.4.3", diff --git a/src/models/Hardware.js b/src/models/Hardware.js index f485d9a..b9c4116 100644 --- a/src/models/Hardware.js +++ b/src/models/Hardware.js @@ -1,11 +1,11 @@ const mongoose = require('mongoose'); const Gpio = require('onoff').Gpio; -const led = new Gpio(17, 'out'); +const pump = new Gpio(17, 'out'); const hardwareSchema = mongoose.Schema(); -hardwareSchema.statics.toggleLed = async function () { - return led.writeSync(led.readSync() ^ 1); +hardwareSchema.statics.togglePump = async function () { + return pump.writeSync(pump.readSync() ^ 1); }; const Hardware = mongoose.model('Hardware', hardwareSchema); diff --git a/src/pumps/pump-layout.json b/src/pumps/pump-layout.json new file mode 100644 index 0000000..6462f94 --- /dev/null +++ b/src/pumps/pump-layout.json @@ -0,0 +1,15 @@ +{ + "pumps": [ + { + "dark-rum": 1, + "vodka": 2, + "gin": 3, + "cointreau": 4, + "tonic": 5, + "coke": 6, + "lemonade": 7, + "ginger-beer": 8, + "lime-juice": 9 + } + ] +} \ No newline at end of file diff --git a/src/recipes/beverages.json b/src/recipes/beverages.json new file mode 100644 index 0000000..d3207d3 --- /dev/null +++ b/src/recipes/beverages.json @@ -0,0 +1,24 @@ +{ + "beverages": [ + { + "cuba-libre": { + "name": "Cuba Libre" + }, + "gin-and-tonic": { + "name": "Gin & Tonic" + }, + "moscow-mule": { + "name": "Moscow Mule" + }, + "dark-and-stormy": { + "name": "Dark & Stormy" + }, + "gin-margarita": { + "name": "Gin Margarita" + }, + "vodka-margarita": { + "name": "Vodka Margarita" + } + } + ] +} \ No newline at end of file diff --git a/src/routers/hardware.js b/src/routers/hardware.js index 7954369..44d7b04 100644 --- a/src/routers/hardware.js +++ b/src/routers/hardware.js @@ -4,9 +4,9 @@ const auth = require('../middleware/auth'); const router = express.Router(); -router.post('/hardware/led', auth, async (req, res) => { +router.post('/hardware/pump', auth, async (req, res) => { try { - await Hardware.toggleLed(); + await Hardware.togglePump(); res.status(200); } catch (error) { res.status(500).send(error);