Coder Social home page Coder Social logo

cybersmart-locations-api's Introduction

CyberSmart-Locations-API

An API for the managing of Locations in a Smart Home network

CyberSmart

CyberSmart is a system designed to control and manage locations within your home by utilising a range of low cost hardware and Open Source Software solutions. This project is being developed as a University Group Project. The goal of this project is to create a low-cost, low-resource, eco-friendly Smart Home System. Our solution to this is to use a RESTful backend sitting on a hub that calls out to RESTful endpoints of nodes on the network, in order to update their state. In turn, each endpoint on the network polls every half an hour with a state update and timestamp. Each aspect of the system has been designed as a Microservice, allowing for interoperability with other systems.

A big thanks to the following projects and people, without them, CyberSmart would not be possible.

  • NodeJS - For creating a fast, lightweight solution for RESTful web servers! All APIs have been developed in Node.
  • ReactJS - For creating an easy to work with UI design solution. The Frontend design has been developed in ReactJS.
  • Python - For hardware level interaction (GPIO pins).
  • Raspberry Pi Foundation - For consistently providing great quality hardware at brilliant prices! All CyberSmarts Nodes use the Raspberry Pi Zero, running Jessie Pixel Headless and the main hub uses a Raspberry Pi 3 Model B
  • Lubuntu - For creating a neat, lightweight OS solution. The main hub uses Lubuntu.

CyberSmart Related Repositories

Contributors

License

Documentation

Routes

Find

route.get('/all', function(req, res)

This route returns all Locations in the given database context. It takes no parameters. The possible returns are:

  • 200 - OK : This means the request was successful. It should return an array of JSON Objects with all Locations in the database.
  • 404 - Not Found : This means the request failed or no Locations were found.
  • 500 - Server Error : This means something went wrong with the function being called in the controller.
route.get('/location', function(req, res)

This route returns all Locations within a given location. It takes one parameter, Location name. The possible returns are:

  • 200 - OK : This means the request was successful. It should return an array of JSON Objects with all Locations in the given location.
  • 404 - Not Found : This means the request failed or no Locations were found in the location.
  • 500 - Server Error : This means something went wrong with the function being called in the controller.
route.get('/:id', function(req, res)

This route finds a Location by its ID. It takes on parameter, ID, which must be passed in in the format /<id> in the URL. The possible returns are:

  • 200 - OK : This means the request was successful. It should return a JSON Object containing information about the Location with the ID requested.
  • 404 - Not Found : This means the request failed or no Location with the ID requested were found.
  • 500 - Server Error : This means something went wrong with the function being called in the controller.

Insert

route.post('/add', function(req, res)

This route inserts a new Location into the database. It can take five parameters. These are:

  • name:
    • String
    • Required
  • state:
    • Number
    • Required
    • Default : 0
  • active:
    • Boolean
    • Required
    • Default : 0
  • date_added:
    • Date
    • Default : Date.now The possible returns are:
  • 201 - Created : This means a new entry was created in the Location table of the database.
  • 401 - Unauthorized : This means the request was unauthorized and the Location was not inserted into the database.
  • 500 - Server Error : This means the request failed, resulting in a Server Error.

Insert

Delete

route.post('/:id', function(req, res)

This route calls the delete Location by ID function in the Delete handler. The possible parameters are:

  • id : The ID of the Location being deleted The possible returns are:
  • 200 - OK - The function executed successfully, resulting in the deletion of a Location.
  • 401 - Unauthorized : This means the request was unauthorized, meaning something went wrong.
  • 500 - Server Error : This means something went wrong with the delete function, resulting in a server crash.
route.post('/:name', function(req, res)

This route calls the delete Location by name function in the Delete handler. The possible parameters are:

  • name : The name of the Location being deleted The possible returns are:
  • 200 - OK - The function executed successfully, resulting in the deletion of a Location.
  • 401 - Unauthorized : This means the request was unauthorized, meaning something went wrong.
  • 500 - Server Error : This means something went wrong with the delete function, resulting in a server crash.

Handlers

Find

FindAll()

This method searches the database for all Locations. If none found or an error, it rejects the request. It takes no parameters. If the request succeeds, all Locations in the database will be returned.

FindById(id)

This method searches the database for any Locations matching the ID of the id parameter. If no Locations are found or an error occurs, the request is rejected. If the request succeeds, the Location matching that ID will be returned.

Insert

AddLocation(Location)

This method adds a Location to the database, given a Location object. The Location object is then parsed into a newLocation object. If it fails to add a Location to the database, the request is rejected and the method fails. If the request succeeds, it will return the created Location.

Update

UpdateStateById(id, state)

This method finds a Location given an ID and updates the state. If no Location is found or an error occurs, the request is rejected. If the request succeeds, it will return the Location matching the given ID and its updated state.

Delete

DeleteById(id)

This method finds a Location given an ID and sets the property active to false. If there is an error during execution or the result is null, the method fails and is rejected. If the method executes correctly, it sets active to false on the given Location.

DeleteByName(id)

This method finds a Location given a name and sets the property active to false. If there is an error during execution or the result is null, the method fails and is rejected. If the method executes correctly, it sets active to false on the given Location.

cybersmart-locations-api's People

Contributors

brandonjamesparkinson avatar gitpancake avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.