add new api

This commit is contained in:
Sunandar
2017-02-08 17:35:47 +06:30
parent 26d42631c7
commit 43ada02033
18 changed files with 112 additions and 0 deletions

View 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/

View 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/

View 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/

View 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/

View 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

View File

@@ -0,0 +1,2 @@
module Api::ProductsHelper
end

View File

@@ -0,0 +1,2 @@
module ProductsHelper
end

View File

@@ -0,0 +1,3 @@
class ProductCategory < ApplicationRecord
end

View File

@@ -0,0 +1,2 @@
class ProductType < ApplicationRecord
end

View 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

View 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

View 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

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class Api::ProductsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View 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
View 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
View 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

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class ProductCategoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class ProductTypeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end