|
@ -8,11 +8,32 @@ require "uuid/json" |
|
|
require "../../config" |
|
|
require "../../config" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post "/category" do |context| |
|
|
|
|
|
begin |
|
|
|
|
|
begin |
|
|
|
|
|
user = authenticate_admin!(context.request.headers["user"],UUID.new(context.request.headers["api_token"])) |
|
|
|
|
|
rescue ex |
|
|
|
|
|
halt context, status_code: 403, response: ex.to_s |
|
|
|
|
|
end |
|
|
|
|
|
cat = Category.from_json(context.request.body.not_nil!).not_nil! |
|
|
|
|
|
if cat.name_id.count(' ')==0 |
|
|
|
|
|
File.write Statics.data_path+"category/"+cat.name_id,cat.to_json |
|
|
|
|
|
else |
|
|
|
|
|
halt context, status_code: 400, response: "name_id should not contain spaces ' ' or '/'" |
|
|
|
|
|
end |
|
|
|
|
|
rescue ex |
|
|
|
|
|
halt context, status_code: 500, response: ex.to_s |
|
|
|
|
|
end |
|
|
|
|
|
"OK".to_json |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
get "/category/m/:id" do |context| |
|
|
get "/category/m/:id" do |context| |
|
|
begin |
|
|
begin |
|
|
ret = Category.from_json File.read Statics.data_path+"category/"+context.params.url["id"] |
|
|
ret = Category.from_json File.read Statics.data_path+"category/"+context.params.url["id"] |
|
|
rescue ex |
|
|
rescue ex |
|
|
halt context, status_code: 403, response: ex.to_s |
|
|
|
|
|
|
|
|
halt context, status_code: 404, response: ex.to_s |
|
|
end |
|
|
end |
|
|
ret.to_json |
|
|
ret.to_json |
|
|
end |
|
|
end |
|
@ -21,15 +42,23 @@ get "/category/d/:id" do |context| |
|
|
ret = Array(Product).new |
|
|
ret = Array(Product).new |
|
|
begin |
|
|
begin |
|
|
cat = Category.from_json File.read Statics.data_path+"category/"+context.params.url["id"] |
|
|
cat = Category.from_json File.read Statics.data_path+"category/"+context.params.url["id"] |
|
|
|
|
|
sent=0 |
|
|
|
|
|
skipped=0 |
|
|
|
|
|
skip, limit = Statics.extract_skip_info context |
|
|
|
|
|
|
|
|
cat.products.each do |product| |
|
|
cat.products.each do |product| |
|
|
begin |
|
|
|
|
|
ret.push Product.from_json File.read Statics.data_path+"products/"+product.to_s |
|
|
|
|
|
|
|
|
begin |
|
|
|
|
|
if(skipped<skip) |
|
|
|
|
|
skipped+=1 |
|
|
|
|
|
else |
|
|
|
|
|
ret.push Product.from_json File.read Statics.data_path+"products/"+product.to_s |
|
|
|
|
|
sent+=1 |
|
|
|
|
|
end |
|
|
rescue |
|
|
rescue |
|
|
|
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
rescue ex |
|
|
rescue ex |
|
|
halt context, status_code: 403, response: ex.to_s |
|
|
|
|
|
|
|
|
halt context, status_code: 404, response: ex.to_s |
|
|
end |
|
|
end |
|
|
ret.to_json |
|
|
ret.to_json |
|
|
end |
|
|
end |