Code Monkey home page Code Monkey logo

wfh-ninja's Introduction

wfh-ninja

WFH-ninja was originally intended to be a "work from home" excuse generator, allowing the community to vote on the most effective excuses. This repo is built as a generic single page app that displays one quote at a time, with features to "upvote" and "downvote" quotes. User submitted quotes require approval by a registered admin via an admin panel.

Live Demo: http://wfh.ninja/

Core features

  • Post new quote (user submission of quotes)
  • Get all approved/ unapproved quotes
  • Approve/ reject single quotes via admin panel
  • Admin panel (/admin) for admin user registration, login, logout and approving/ rejecting of quotes

Architecture

WFH-ninja is built with a Python-Flask backend, with a React/ JS/ Bootstrap frontend. WFH-ninja uses a Postgresql database as the datastore.

Requirements

  • Flask pip install flask
  • SimpleJson pip install simplejson
  • Flask-CORS pip install flask-cors
  • Flask-login pip install flask-login
  • Flask-sqlachemy pip install flask-sqlalchemy
  • Postgresql brew install postgresql
  • Psycopg2 (requires postgres) pip install psycopg2

To run

  1. Set up Database URL
export DATABASE_URL=postgresql://USERNAME:PASSWORD@HOSTURL/DBNAME

Replace USERNAME, PASSWORD, HOSTURL, DBNAME with your credentials.

  1. Set up Database
python initdb.py
  1. Run app
python main.py

Documentation

###Quote object methods###

GET /quote (not logged in)

Returns list of active Quote ids and their details

Result format:

{
   "1": {
    "active": true,
    "conditions": "{}",
    "date_created": "2015-05-17T22:25:59.911361",
    "id": 1,
    "ip": 127.0.0.1,
    "score": 14,
    "text": "Quote 1",
    "view_count": 68
  },
  "10": {
    "active": true,
    "conditions": "{}",
    "date_created": "2015-05-17T23:02:27.596582",
    "id": 10,
    "ip": "127.0.0.1",
    "score": 4,
    "text": "Quote 2",
    "view_count": 13
  }
}

GET /quote?all=true (requires logged in)

If logged in, returns list of all Quote ids and their details. Else, returns list of only active Quote ids and their details.

Result format:

{
   "1": {
    "active": true,
    "conditions": "{}",
    "date_created": "2015-05-17T22:25:59.911361",
    "id": 1,
    "ip": 127.0.0.1,
    "score": 14,
    "text": "Quote 1",
    "view_count": 68
  },
  "13": {
    "active": false,
    "conditions": "{}",
    "date_created": "2015-05-18T23:02:27.596582",
    "id": 13,
    "ip": "127.0.0.1",
    "score": 4,
    "text": "Quote 3",
    "view_count": 15
  }
}

POST /quote

Submits a new quote

Header (application/json):

Name Type Description Required?
text String Body/ Content of Quote Required
conditions JSON Additional properties for the quote, e.g. weather conditions, location, etc Not required

Example:

{
  "text" : "Sample quote",
  "conditions" : { "weather": "sunny" }
}

GET /quote/quote_id

Returns details of Quote of id quote_id

Result format:

{
  "active": false,
  "conditions": "{}",
  "date_created": "2015-05-17T23:51:26.138167",
  "id": 17,
  "ip": "127.0.0.1",
  "score": 124,
  "text": "quote content",
  "view_count": 2
}

DELETE /quote/quote_id (Requires login)

Deletes Quote of id quote_id

Result format:

{
  "Success": "Quote has been deleted"
}

PUT /quote/quote_id/approve (Requires login)

Approves Quote of id quote_id

Result format:

{
  "active": true,
  "conditions": "{}",
  "date_created": "2015-05-17T23:51:26.138167",
  "id": 17,
  "ip": "127.0.0.1",
  "text": "quote content",
  "view_count": 2
}

PUT /quote/quote_id/reject (Requires login)

Rejects Quote of id quote_id

Result format:

{
  "active": false,
  "conditions": "{}",
  "date_created": "2015-05-17T23:51:26.138167",
  "id": 17,
  "ip": "127.0.0.1",
  "text": "quote content",
  "view_count": 2
}

POST /quote/quote_id/vote

Submits a new vote for Quote of id quote_id

Header (application/json):

Name Type Description Required?
value Integer 1 for vote up, -1 for vote down Required

Example:

{
  "value": 1
}

###Admin user object methods### Admin users can access /admin page to approve, reject and delete quotes. The following methods allow the creation of a new admin user.

POST /register

Creates a new user

Header (application/json):

Name Type Description Required?
email String Email of registered user Required
password String Password of registered user Required
secret String Secret registration key (in config.py) to allow only specific users to register Required

Example:

{
  "email": "[email protected]",
  "password": "12345",
  "secret": "secret-registration-key"
}

POST /login

Logs a user in

Header (application/json):

Name Type Description Required?
email String Email of registered user Required
password String Password of registered user Required

Example:

{
  "email": "[email protected]",
  "password": "12345"
}

GET /logout

Logs a user out

Result format:

{
  "Success": "User is logged out"
}

wfh-ninja's People

Contributors

bencxr avatar christinang89 avatar mervync avatar

Watchers

 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.