This is a web app to model a bookshop. It uses Ruby on Rails to build a backend with APIs and the front end frame React to render the content.
The owner of Charlie's Czech Bookshop, wants an app which will help him keep on top of his store's inventory. The customers will not see the app, the purpose is that that the site will be used to check stock levels and see what needs to order soon.
- Clone project and change directory into project.
git clone git@github.com:Charliemowood/bookshop-rails-react.git && cd bookshop-rails-react - Change directory into rails part of the part of the project.
cd bookshop_api - Install all gems needed.
bundle install - Migrate the datebase:
rake db:migrate - Seed the database:
rake db:seed - Start up the server that runs the API, keep running:
rails server -p 5000
- From root of project change directory into React part of the project:
cd react - Install necessary packages from npm.
npm install - Run webpack in new terminal window:
npm run build - Run server in new terminal window:
node server.js - Navigate to server in your favorite browser:
localhost:3000
To ensure that the app will function you will need to use one of the following addons and enable CORS.
https://addons.mozilla.org/en-US/firefox/addon/cors-everywhere/
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
The API is json based built using Ruby on Rails.
Example request, to perform a GET request returning the INDEX of current books.
localhost:3000/api/booksOutput of request:
[
{
"id": 39,
"title": "Biggles Flies North",
"price": 10,
"img": "placeholder",
"stock": 30,
"status": "low",
"author": {
"name": "Enid Blyton"
}
},
{
"id": 40,
"title": "Five Run Away",
"price": 7,
"img": "placeholder",
"stock": 3,
"status": "high",
"author": {
"name": "WE Johns"
}
},
{
"id": 41,
"title": "The ship that flew",
"price": 20,
"img": "placeholder",
"stock": 10,
"status": "medium",
"author": {
"name": "Hilda Lewis"
}
}
]