diff --git a/Gemfile b/Gemfile index 213cc1e..375d49d 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,6 @@ gem 'pg', '~> 1.2.2' gem 'webpacker', '5.1.1' gem 'bootsnap', '>= 1.1.0', require: false -gem 'jbuilder', '~> 2.10' - gem 'oj', '~> 3.10.6' gem 'kaminari', '~> 1.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index f6cfbfc..c4fb412 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,7 +61,7 @@ GEM msgpack (~> 1.0) builder (3.2.4) coderay (1.1.3) - concurrent-ruby (1.1.6) + concurrent-ruby (1.1.7) crass (1.0.6) dalli (2.7.10) database_cleaner (1.8.5) @@ -92,8 +92,6 @@ GEM rspec (>= 2.99.0, < 4.0) i18n (1.8.5) concurrent-ruby (~> 1.0) - jbuilder (2.10.0) - activesupport (>= 5.0.0) kaminari (1.2.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.1) @@ -245,7 +243,6 @@ DEPENDENCIES factory_bot_rails (~> 5.2.0) guard (~> 2.16.2) guard-rspec - jbuilder (~> 2.10) kaminari (~> 1.2.0) oj (~> 3.10.6) pg (~> 1.2.2) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index a417743..7d7a6ba 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -6,22 +6,14 @@ class NotesController < ApplicationController # GET /notes.json def index @notes = Note.for_user(current_user) + render json: NoteSerializer.for(@notes) end # GET /notes/1 # GET /notes/1.json def show ensure_owner(@note) - end - - # GET /notes/new - def new - @note = Note.new - end - - # GET /notes/1/edit - def edit - ensure_owner(@note) + render json: NoteSerializer.for(@note) end # POST /notes diff --git a/app/controllers/task_items_controller.rb b/app/controllers/task_items_controller.rb index c706e29..9028cd9 100644 --- a/app/controllers/task_items_controller.rb +++ b/app/controllers/task_items_controller.rb @@ -9,7 +9,7 @@ class TaskItemsController < ApplicationController @task_item.task_list = @task_list if @task_item.save - render :show, status: :created, location: [@task_list, @task_item] + render json: TaskItemSerializer.for(@task_item), status: :created, location: [@task_list, @task_item] else render json: @task_item.errors, status: :unprocessable_entity end @@ -17,7 +17,7 @@ class TaskItemsController < ApplicationController def update if @task_item.update(task_item_params) - render :show, status: :ok, location: [@task_list, @task_item] + render json: TaskItemSerializer.for(@task_item), status: :ok, location: [@task_list, @task_item] else render json: @task_item.errors, status: :unprocessable_entity end diff --git a/app/controllers/task_lists_controller.rb b/app/controllers/task_lists_controller.rb index 99254fe..b321401 100644 --- a/app/controllers/task_lists_controller.rb +++ b/app/controllers/task_lists_controller.rb @@ -5,10 +5,12 @@ class TaskListsController < ApplicationController def index @task_lists = TaskList.for_user(current_user).includes(:task_items).order(created_at: :desc) + render json: TaskListSerializer.for(@task_lists) end def show ensure_owner(@task_list) + render json: TaskListSerializer.for(@task_list) end def create @@ -16,7 +18,7 @@ class TaskListsController < ApplicationController @task_list.user = current_user if @task_list.save - render :show, status: :created, location: @task_list + render json: TaskListSerializer.for(@task_list), status: :created, location: @task_list else render json: @task_list.errors, status: :unprocessable_entity end @@ -25,7 +27,7 @@ class TaskListsController < ApplicationController def update ensure_owner(@task_list) do if @task_list.update(task_list_params) - render :show, status: :ok, location: @task_list + render json: TaskListSerializer.for(@task_list), status: :ok, location: @task_list else render json: @task_list.errors, status: :unprocessable_entity end diff --git a/app/models/task_item.rb b/app/models/task_item.rb index 5f266ad..2b30275 100644 --- a/app/models/task_item.rb +++ b/app/models/task_item.rb @@ -1,7 +1,7 @@ class TaskItem < ApplicationRecord include DefaultValues - belongs_to :task_list + belongs_to :task_list, touch: true validates :name, presence: true diff --git a/app/serializers/application_serializer.rb b/app/serializers/application_serializer.rb index 11974f7..3823206 100644 --- a/app/serializers/application_serializer.rb +++ b/app/serializers/application_serializer.rb @@ -1,4 +1,6 @@ class ApplicationSerializer + include Rails.application.routes.url_helpers + class CollectionSerializer < ApplicationSerializer def initialize(items, serializer, opts = {}) diff --git a/app/serializers/note_serializer.rb b/app/serializers/note_serializer.rb new file mode 100644 index 0000000..b1a0f41 --- /dev/null +++ b/app/serializers/note_serializer.rb @@ -0,0 +1,8 @@ +class NoteSerializer < ApplicationSerializer + def serialize + { + **item_properties(:id, :content, :created_at), + url: note_path(item, format: :json) + } + end +end diff --git a/app/serializers/task_item_serializer.rb b/app/serializers/task_item_serializer.rb new file mode 100644 index 0000000..19dd8e0 --- /dev/null +++ b/app/serializers/task_item_serializer.rb @@ -0,0 +1,7 @@ +class TaskItemSerializer < ApplicationSerializer + def serialize + { + **item_properties(:id, :task_list_id, :name, :quantity, :completed, :created_at, :updated_at) + } + end +end \ No newline at end of file diff --git a/app/serializers/task_list_serializer.rb b/app/serializers/task_list_serializer.rb new file mode 100644 index 0000000..d77cd31 --- /dev/null +++ b/app/serializers/task_list_serializer.rb @@ -0,0 +1,8 @@ +class TaskListSerializer < ApplicationSerializer + def serialize + { + **item_properties(:id, :name, :created_at, :updated_at), + task_items: TaskItemSerializer.for(item.task_items).serialize + } + end +end \ No newline at end of file diff --git a/app/views/home/about.html.erb b/app/views/home/about.html.erb deleted file mode 100644 index 6f8a616..0000000 --- a/app/views/home/about.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -
- A Recipe manager. Source available from my Git repository at https://source.elbert.us. -
- -- Parsley is released under the MIT License. All code © Dan Elbert 2016. -
- -
- Food data provided by:
-
- US Department of Agriculture, Agricultural Research Service, Nutrient Data Laboratory. USDA National Nutrient Database for Standard Reference, Release 28. Version Current: September 2015. Internet: http://www.ars.usda.gov/nea/bhnrc/ndl
-
-