diff --git a/.gitignore b/.gitignore index 65df034..0e673f8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ /log/*.log /tmp -# Ignore .env (ENV variables), coverage (SimpleCov), .DS_Store +# Ignore .env (ENV variables), coverage (SimpleCov), .DS_Store, heroku .env coverage/ -.DS_Store \ No newline at end of file +.DS_Store +heroku.txt \ No newline at end of file diff --git a/README.md b/README.md index 4218820..745fe42 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,18 @@ [![Circle CI](https://circleci.com/gh/mtvillwock/jho.svg?style=svg&circle-token=:61c1a903f8b4b59801920e70480195dbc7295f69)](https://circleci.com/gh/mtvillwock/jho) +![JHO screenshot](./dbc-mixer-jho.png) + +## Test Drive + +1. `git clone https://github.com/mtvillwock/JHO.git` - clone down local copy of API +1. `cd JHO` - change directory +2. `bundle install` - install gems / dependencies +3. `rake db:create` - create database +4. `rake db:migrate` - migrate database tables +3. `rails s` - start server +4. Use the [client repo](https://github.com/mtvillwock/JHO_Angular_Experimentation) to interact with the API. + ## Implemented: - Rails API [deployed](https://jho.herokuapp.com) on Heroku diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index b227287..d2cead4 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -8,26 +8,36 @@ def index end def dashboard - - board = @current_user.boards.first - lists = board.lists - cards = lists.map { |list| list.cards } + board = @current_user.boards.first # Board object + lists = board.lists # ActiveRecord collection of List objects + cards = lists.map { |list| list.cards } # AR collection of AR collections of cards + flat_cards = cards.flatten! + tasks = flat_cards.map { |card| card.tasks } # AR collection of AR collection of tasks # create a hash of the board's attributes board_hash = board.attributes + # initialize lists key in board hash board_hash["lists"] = [] - # build out nested board hash by adding lists and cards + # build out nested board hash by adding lists, cards and tasks lists.each_with_index do |list, index| + # add hash of the list's attributes to lists array board_hash["lists"] << list.attributes - board_hash["lists"][index]['cards'] = list.cards + # initialize cards key in list hash + board_hash["lists"][index]["cards"] = [] + cards.each_with_index do |card, i| + # add hash of the cards's attributes to cards array + board_hash["lists"][index]["cards"] << card.attributes + # set card["tasks"] to an AR collection of the card's tasks + board_hash["lists"][index]["cards"][i]["tasks"] = card.tasks + end end - # refactoring for efficiency + # refactor with include/joins for efficiency # board.lists.include(:cards).to_json - # definitely should refactor this to use ActiveModel::Serializer - render json: { board: board_hash, lists: lists, cards: cards.flatten! } + # refactor this to use ActiveModel::Serializer or jBuilder for easier JSON manipulation + render json: { board: board_hash, lists: lists, cards: cards.flatten!, tasks: tasks.flatten! } end def create diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 9437cf9..3c521e7 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -37,6 +37,6 @@ def destroy private def task_params - params.require(:task).permit(:card_id, :title, :completed) + params.require(:task).permit(:card_id, :title, :completed, :notes) end end diff --git a/db/migrate/20150927032613_add_notes_to_tasks.rb b/db/migrate/20150927032613_add_notes_to_tasks.rb new file mode 100644 index 0000000..9e7d48c --- /dev/null +++ b/db/migrate/20150927032613_add_notes_to_tasks.rb @@ -0,0 +1,5 @@ +class AddNotesToTasks < ActiveRecord::Migration + def change + add_column :tasks, :notes, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index e11a53a..adf1870 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150915011113) do +ActiveRecord::Schema.define(version: 20150927032613) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -78,6 +78,7 @@ t.boolean "completed", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "notes" end create_table "users", force: :cascade do |t| diff --git a/dbc-mixer-jho.png b/dbc-mixer-jho.png new file mode 100644 index 0000000..edf946a Binary files /dev/null and b/dbc-mixer-jho.png differ diff --git a/jho-schema.xml b/jho-schema.xml new file mode 100644 index 0000000..1fa9e12 --- /dev/null +++ b/jho-schema.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +INTEGER +NULL + +VARCHAR +NULL + +INTEGER +NULL + + +id + +
+ + +INTEGER +NULL + +id + +
+ + +INTEGER +NULL + +VARCHAR +NULL + +INTEGER +NULL + + +INTEGER +NULL + +id + +
+ + +INTEGER +NULL + +INTEGER +NULL + + +id + +
+ + +INTEGER +NULL + +INTEGER +NULL + + +VARCHAR +NULL + +id + +
+