-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
713eeb5
commit 489b772
Showing
81 changed files
with
438 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ require: | |
|
||
AllCops: | ||
NewCops: enable | ||
SuggestExtensions: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module ApplicationCable | ||
class Channel < ActionCable::Channel::Base | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,107 @@ | ||
class Api::ItemsController < ApplicationController | ||
# frozen_string_literal: true | ||
|
||
include ProductSearch | ||
module Api | ||
# Controller for accessing items (products) in the API | ||
class ItemsController < ApplicationController | ||
include ProductSearch | ||
|
||
protect_from_forgery with: :null_session | ||
protect_from_forgery with: :null_session | ||
|
||
before_action :doorkeeper_authorize!, only: [:create, :update] | ||
before_action :set_item, only: [:show, :update, :destroy] | ||
before_action :doorkeeper_authorize!, only: %i[create update] | ||
before_action :set_item, only: %i[show update] | ||
|
||
rescue_from ActiveRecord::RecordNotFound, with: :product_not_found | ||
rescue_from ActiveRecord::RecordNotFound, with: :product_not_found | ||
|
||
def index | ||
@items = product_search(params) | ||
end | ||
def index | ||
@items = product_search(params) | ||
end | ||
|
||
def show | ||
if @item | ||
render json: @item | ||
else | ||
render json: { error: "Product '#{params[:id]}' not found" }, status: :not_found | ||
def show | ||
if @item | ||
render json: @item | ||
else | ||
render json: { error: "Product '#{params[:id]}' not found" }, status: :not_found | ||
end | ||
end | ||
end | ||
|
||
def create | ||
@item = Product.new(item_params) | ||
def create | ||
@item = Product.new(item_params) | ||
|
||
respond_to do |format| | ||
if @item.save | ||
format.json { render :show, status: :created, location: @item } | ||
else | ||
format.json { render json: @item.errors, status: :unprocessable_entity } | ||
respond_to do |format| | ||
if @item.save | ||
format.json { render :show, status: :created, location: @item } | ||
else | ||
format.json { render json: @item.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @item.update(item_params) | ||
format.json { render :show, status: :ok, location: @item } | ||
else | ||
format.json { render json: @item.errors, status: :unprocessable_entity } | ||
def update | ||
respond_to do |format| | ||
if @item.update(item_params) | ||
format.json { render :show, status: :ok, location: @item } | ||
else | ||
format.json { render json: @item.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
private | ||
|
||
def set_item | ||
@item = if params[:id] == '00000000000000' | ||
test_item | ||
else | ||
Product.from_param(params[:id]) | ||
def set_item | ||
@item = if params[:id] == '00000000000000' | ||
test_item | ||
else | ||
Product.from_param(params[:id]) | ||
end | ||
end | ||
end | ||
|
||
def product_not_found(_exception) | ||
render json: { error: "Product '#{params[:id]}' not found" }, status: :not_found | ||
end | ||
def product_not_found(_exception) | ||
render json: { error: "Product '#{params[:id]}' not found" }, status: :not_found | ||
end | ||
|
||
def item_params | ||
params | ||
.permit( | ||
:gtin, | ||
:name, | ||
:brand_name, | ||
properties: {} | ||
) | ||
end | ||
def item_params | ||
params | ||
.permit( | ||
:gtin, | ||
:name, | ||
:brand_name, | ||
properties: {} | ||
) | ||
end | ||
|
||
# TODO the Datakick test item also has images attached. | ||
# | ||
def test_item | ||
Product.new( | ||
gtin: '00000000000000', | ||
properties: { | ||
brand_name: "ayam", | ||
name: "testname", | ||
size: "081216382297", | ||
ingredients: "Chocolate", | ||
serving_size: "34g", | ||
servings_per_container: "10", | ||
calories: 5, | ||
fat_calories: 5, | ||
fat: 0.5, | ||
saturated_fat: 0.5, | ||
trans_fat: 0.5, | ||
polyunsaturated_fat: 0.5, | ||
monounsaturated_fat: 0.5, | ||
cholesterol: 0, | ||
sodium: 0, | ||
potassium: 0, | ||
carbohydrate: 0, | ||
fiber: 0, | ||
sugars: 0, | ||
protein: 0, | ||
author: "MyAuthor", | ||
publisher: "MyPublisher", | ||
pages: 0, | ||
alcohol_by_volume: 40.0, | ||
} | ||
) | ||
# TODO: the Datakick test item also has images attached. | ||
# | ||
def test_item # rubocop:disable Metrics/MethodLength | ||
Product.new( | ||
gtin: '00000000000000', | ||
properties: { | ||
brand_name: 'ayam', | ||
name: 'testname', | ||
size: '081216382297', | ||
ingredients: 'Chocolate', | ||
serving_size: '34g', | ||
servings_per_container: '10', | ||
calories: 5, | ||
fat_calories: 5, | ||
fat: 0.5, | ||
saturated_fat: 0.5, | ||
trans_fat: 0.5, | ||
polyunsaturated_fat: 0.5, | ||
monounsaturated_fat: 0.5, | ||
cholesterol: 0, | ||
sodium: 0, | ||
potassium: 0, | ||
carbohydrate: 0, | ||
fiber: 0, | ||
sugars: 0, | ||
protein: 0, | ||
author: 'MyAuthor', | ||
publisher: 'MyPublisher', | ||
pages: 0, | ||
alcohol_by_volume: 40.0 | ||
} | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
# Base controller | ||
class ApplicationController < ActionController::Base | ||
before_action :set_paper_trail_whodunnit | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class HomeController < ApplicationController | ||
|
||
def index | ||
# frozen_string_literal: true | ||
|
||
end | ||
# Home (dashboard) controller | ||
class HomeController < ApplicationController | ||
def index; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
module ApplicationHelper | ||
# frozen_string_literal: true | ||
|
||
module ApplicationHelper # rubocop:disable Style/Documentation | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.