Skip to content

Commit

Permalink
Merge ae1c49e into 42f6248
Browse files Browse the repository at this point in the history
  • Loading branch information
segunolalive committed Oct 18, 2017
2 parents 42f6248 + ae1c49e commit 086a3cc
Show file tree
Hide file tree
Showing 113 changed files with 21,213 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": ["env", "react"],
"plugins": ["transform-object-rest-spread"],
"env": {
"production": {
"plugins": [
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
}
}
}
14 changes: 14 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
engines:
duplication:
enabled: false
config:
languages:
javascript:
mass_threshold: 20
ratings:
paths:
- "**.js"
exclude_paths:
- "test/"
- "node_modules/"
- "templates/"
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: COVERALLS_REPO_TOKEN
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/server/test
/dist
51 changes: 51 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"root": true,
"extends": ["airbnb-base", "plugin:react/recommended"],
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": { "jsx": true }
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js",".jsx"]
}
}
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"max-len": [1, 80, 2],
"import/prefer-default-export": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"import/extensions": "off",
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}],
"class-methods-use-this": 0,
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
}
}
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage
/.nyc_output

# production
/build
/dist

# misc
.DS_Store
/config/db.js
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
/job
*.txt

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eslint:
enabled: true
config_file: .eslintrc
ignore_file: .eslintignore

8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

module.exports = {
"config": path.resolve('./server/config', 'config.js'),
"models-path": path.resolve('./server/models'),
"seeders-path": path.resolve('./server/seeders'),
"migrations-path": path.resolve('./server/migrations')
};
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "6"
env:
global:
- export NODE_ENV=test
script:
- npm test
after_success:
- npm run coverage
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node dist/server/bin/www.js
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[![Build Status](https://travis-ci.org/segunolalive/helloBooks.svg?branch=master)](https://travis-ci.org/segunolalive/helloBooks)
[![Coverage Status](https://coveralls.io/repos/github/segunolalive/helloBooks/badge.svg?branch=master)](https://coveralls.io/github/segunolalive/helloBooks?branch=master)
[![Code Climate](https://codeclimate.com/github/segunolalive/helloBooks/badges/gpa.svg)](https://codeclimate.com/github/segunolalive/helloBooks?branch=master)

# helloBooks

### A Library app
Hello books is an application that provides users with access to books from wherever they are.
Beeing a virtual library, users can borrow and read their favorite books using any device.
HelloBooks exposes RESTful API endpoints such that anyone customize the method of consuming
the resources.

### Development
This is a javascript application built with [**Express**](http://expressjs.com/)
framework on the nodejs platform. Authentication of users is done via
[**JSON Web Tokens**](https://jwt.io/) .

#### Features
- Login/Sign up to gain access to routes
- A library of books from different categories
- Ability to borrow books repeatedly
- Track your reading/borrowing history
- Admin access to modify book details

#### API Routes
- sign up route:
**POST** /api/v1/users/signup
parameters - username, password, email
optional parameters - firstName, lastName


- login route:
**POST** /api/v1/users/signin
parameters - username, password

- get books (view library):
**GET** /api/v1/books'

- get book (view a book's metadata):
**GET** /api/v1/books/:id
parameters - bookId (number)

- add a new book to library:
**POST** /api/v1/books
request body - authors, title, description, cover, bookfile, total

- modify book information:
**PUT** /api/v1/books/
request body - authors, title, description, cover, bookfile, total (any)
query parameters - book id (number)

- borrow book:
**POST** /api/v1/users/:id/books
parameters - user id
query parameters - book id (number)

- return book:
**PUT** /api/v1/users/:id/books
parameters - user id
query parameters - book id (number)

- get borrowed books:
**GET** /api/v1/users/:id/books
27 changes: 27 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "helloBooks",
"scripts": {},
"env": {
"DATABASE_URL": {
"required": true
},
"NODE_ENV": {
"required": true
},
"NODE_MODULES_CACHE": {
"required": true
},
"SECRET": {
"required": true
}
},
"formation": {},
"addons": [
"papertrail"
],
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
38 changes: 38 additions & 0 deletions client/actions/actionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import keyMirror from './keyMirror';
/**
* array of action types
* @type {Array}
*/
const actionList = [
'SIGN_UP',
'LOGIN',
'LOGOUT',
'SET_LOGIN_STATUS',
'UPDATE_PROFILE',
'SET_BOOK_ID',
'GET_BOOK',
'GET_BOOKS',
'GET_BORROWED_BOOKS',
'GET_TRANSACTION_HISTORY',
'GET_ALL_BORROWED',
'GET_BOOK_CATEGORIES',
'BORROW_BOOK',
'RETURN_BOOK',
'CREATE_BOOK',
'READ_BOOK',
'EDIT_BOOK_INFO',
'DELETE_BOOK',
'UPLOAD_BOOK_FILE',
'UPLOAD_BOOK_COVER',
'SAVE_STATE',
'GET_SAVED_STATE',
'GET_ADMIN_NOTIFICATIONS',
];

/**
* action types object
* @type {Object}
*/
const actionTypes = keyMirror(actionList);

export default actionTypes;
106 changes: 106 additions & 0 deletions client/actions/adminActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import axios from 'axios';
import actionTypes from '../actions/actionTypes';
import API from './api';

const Materialize = window.Materialize;


/**
* @param {Object} book - book
* @returns {Object} - Object containing action type and user
*/
export const editBookAction = book => ({
type: actionTypes.EDIT_BOOK,
book,
});


/**
* edit book Detail
* @param {Integer} id book Id
* @param {Object} data book data with with to update database
* @return {Object} dispatches an action to the redux store
*/
export const editBook = (id, data) => dispatch => (
axios.put(`${API}/books/${id}`, data)
.then((response) => {
Materialize.toast(response.data.message, 2500, 'teal darken-4');
}, (error) => {
Materialize.toast(error.response.data.message, 2500, 'red darken-4');
})
.catch((error) => {
Materialize.toast(error, 2500, 'red darken-4');
})
);


/**
* @param {Object} book - book
* @returns {Object} - Object containing action type and book
*/
export const addBookAction = book => ({
type: actionTypes.ADD_BOOK,
book,
});


/**
* @param {Object} book - book
* @returns {Object} - Object containing action type and book
*/
export const setBookToEdit = book => ({
type: actionTypes.SET_BOOK_TO_EDIT,
book,
});


/**
* get the book to edit
* @param {Number} id book id
* @return {Object} redux action
*/
export const bookToEdit = id => dispatch => (
axios.get(`${API}/books/${id}`)
.then((response) => {
dispatch(setBookToEdit(response.data.data));
})
.catch((error) => {
Materialize.toast(error, 2500, 'red darken-4');
})
);


/**
* add new book to database
* @param {Object} data book data
* @return {Object} dispatches an action to the redux store
*/
export const addBook = data => dispatch => (
axios.post(`${API}/books`, data)
.then((response) => {
Materialize.toast(response.data.message, 2500, 'teal darken-4');
}, (error) => {
Materialize.toast(error.response.data.message, 2500, 'red darken-4');
})
.catch((error) => {
Materialize.toast(error, 2500, 'red darken-4');
})
);


/**
* het book Detail
* @param {Object} category new book category
* @return {Object} dispatches an action to the redux store
*/
export const addBookCategory = category => dispatch => (
axios.post(`${API}/books/category`, { category })
.then((response) => {
Materialize.toast(response.data.message, 2500, 'teal darken-4');
})
.catch(() => {
Materialize.toast(`Something went wrong. Ensure you're not adding
an existing category`, 2500, 'red darken-4'
);
})
);
13 changes: 13 additions & 0 deletions client/actions/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let api = '/api/v1';

if (process.env.NODE_ENV === 'development') {
api = 'http://localhost:5000/api/v1';
}

/**
* api url
* @type {String}
*/
const API = api;

export default API;

0 comments on commit 086a3cc

Please sign in to comment.