add new api
This commit is contained in:
3
app/assets/javascripts/api/products.coffee
Normal file
3
app/assets/javascripts/api/products.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/javascripts/products.coffee
Normal file
3
app/assets/javascripts/products.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/api/products.scss
Normal file
3
app/assets/stylesheets/api/products.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the api/products controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/products.scss
Normal file
3
app/assets/stylesheets/products.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the products controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
19
app/controllers/api/products_controller.rb
Normal file
19
app/controllers/api/products_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Api::ProductsController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token
|
||||
|
||||
def index
|
||||
session_token=params[:session_token]
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
if !check_member.nil?
|
||||
categories =ProductCategory.all
|
||||
arr_category=Array.new
|
||||
categories.each do |cat|
|
||||
str={:id => cat.id,:name => cat.name}
|
||||
arr_category.push(str)
|
||||
end
|
||||
@out=true,arr_category
|
||||
else
|
||||
@out=false,"Sorry!Unauthorized user!"
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/api/products_helper.rb
Normal file
2
app/helpers/api/products_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Api::ProductsHelper
|
||||
end
|
||||
2
app/helpers/products_helper.rb
Normal file
2
app/helpers/products_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ProductsHelper
|
||||
end
|
||||
3
app/models/product_category.rb
Normal file
3
app/models/product_category.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ProductCategory < ApplicationRecord
|
||||
|
||||
end
|
||||
2
app/models/product_type.rb
Normal file
2
app/models/product_type.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class ProductType < ApplicationRecord
|
||||
end
|
||||
7
app/views/api/products/index.json.jbuilder
Normal file
7
app/views/api/products/index.json.jbuilder
Normal file
@@ -0,0 +1,7 @@
|
||||
if @out[0] == true
|
||||
json.set! :status, @out[0]
|
||||
json.set! :data, @out[1]
|
||||
else
|
||||
json.set! :status, @out[0]
|
||||
json.set! :message,@out[1]
|
||||
end
|
||||
7
db/migrate/20170208065307_create_product_types.rb
Normal file
7
db/migrate/20170208065307_create_product_types.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class CreateProductTypes < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :product_types do |t|
|
||||
t.string :name
|
||||
end
|
||||
end
|
||||
end
|
||||
8
db/migrate/20170208065316_create_product_categories.rb
Normal file
8
db/migrate/20170208065316_create_product_categories.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class CreateProductCategories < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :product_categories do |t|
|
||||
t.string :name
|
||||
t.references :product_type
|
||||
end
|
||||
end
|
||||
end
|
||||
7
test/controllers/api/products_controller_test.rb
Normal file
7
test/controllers/api/products_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Api::ProductsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/controllers/products_controller_test.rb
Normal file
7
test/controllers/products_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ProductsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
11
test/fixtures/product_categories.yml
vendored
Normal file
11
test/fixtures/product_categories.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
11
test/fixtures/product_types.yml
vendored
Normal file
11
test/fixtures/product_types.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
||||
7
test/models/product_category_test.rb
Normal file
7
test/models/product_category_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ProductCategoryTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/product_type_test.rb
Normal file
7
test/models/product_type_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ProductTypeTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user