Timesheet Service - mikev-duff/duff_rails_springboard GitHub Wiki

This documents the steps taken to turn the Duff Springboard project into the Timesheet Service.

The Timesheet Service is intended to provide REST interfaces and maintain a database of time sheet entries for mobile client apps. A Timesheet entry consists of the following fields:

  • user name
  • project name
  • task name
  • date task was performed
  • hours
  • notes

The REST service allows for users to create, read, update, and delete their own entries; furthermore, an admin user has the capability to read entries for all users in order to analyze the data and/or create reports.

The motivation behind this project is to show how the Springboard project can be used to create and deploy a simple REST service; as well as to create something with some marginal utility. It uses scaffolding to quickly and easily create the service.

Generate Scaffolding

  • Fork or branch the duff_rails_springboard project

    git clone [email protected]:mikev-duff/duff_rails_springboard.git

    git checkout -b timesheet

  • Generate the Timesheet Entry scaffold

    rails generate scaffold TimesheetEntry user_id:integer project_name:string task_name:string performed_on:date hours:float notes:text --no-test-framework

  • Migrate the database

    bundle exec rake db:migrate

  • Start the server locally

    rails s

At this point, users can sign up, and timesheet entries can be created, read, updated, and deleted at this URL:

http://0.0.0.0:3000/timesheet_entries

For example, the JSON for the first timesheet entry can be found at:

http://0.0.0.0:3000/timesheet_entries/1.json

Unfortunately, there is no authorization policy around accessing these entries (i.e., anyone can update anyone else's entries); fixing that is the focus of the next section.

Authorization Policy

The Springboard project already has authorization policies for User objects in app/controllers/user_controller.rb; the same mechanism will be used for the TimesheetEntry objects.

  • add before_filters in the timesheet_entries_controller.rb

Deploy to Heroku

To create and push your project:

heroku create --stack cedar [appname]
git push heroku master
heroku run rake db:migrate

If you're working on a branch (for example, called 'timesheet'), you can push that branch:

git push heroku timesheet:master