workarea-commerce / workarea-api Goto Github PK
View Code? Open in Web Editor NEWAdds JSON REST APIs to the Workarea Commerce Platform
Home Page: https://www.workarea.com
License: Other
Adds JSON REST APIs to the Workarea Commerce Platform
Home Page: https://www.workarea.com
License: Other
Is your feature request related to a problem? Please describe.
While doing performance reviews I noticed that the API bulk operations don't make use of bulk indexing as far as I can tell. Not a problem per se, just seems like an obvious improvement.
Describe the solution you'd like
Modify Workarea::Api::Admin::BulkUpsert#perform!
to disable normal indexing callbacks and collect the models being changed so you can then call the bulk method on the ES Document classes.
Is your feature request related to a problem? Please describe.
Based on test/integration/workarea/api/admin/recommendation_settings_integration_test.rb
:
require 'test_helper'
module Workarea
module Api
module Admin
class RecommendationSettingsIntegrationTest < IntegrationTest
include Workarea::Admin::IntegrationTest
setup :set_product
def set_product
@product = create_product
end
def create_recommendation_settings
Recommendation::Settings.create!(id: @product.id)
end
def test_shows_recommendation_settings
recommendation_settings = create_recommendation_settings
get admin_api.product_recommendation_settings_path(@product.id)
result = JSON.parse(response.body)['recommendation_settings']
assert_equal(
recommendation_settings,
Recommendation::Settings.new(result)
)
end
def test_updates_recommendation_settings
recommendation_settings = create_recommendation_settings
patch admin_api.product_recommendation_settings_path(@product.id),
params: { recommendation_settings: { product_ids: ['foo'] } }
assert_equal(['foo'], recommendation_settings.reload.product_ids)
end
end
end
end
end
it seems that a Recommendation::Settings
should be created before to hit the different endpoints. Not doing so would return a similar error to:
{
"params": [
"S20BRK1389"
],
"problem": "Document(s) not found for class Workarea::Recommendation::Settings with id(s) S20BRK1389."
}
However we don't currently have an endpoint to do so (create a Workarea::Recommendation::Setting
for the product_id
given).
After some digging in the core it seems that this creation is implicit anyway app/controllers/workarea/admin/recommendations_controller.rb
:
module Workarea
module Admin
class RecommendationsController < Admin::ApplicationController
required_permissions :catalog
before_action :find_product
before_action :find_settings
def edit
end
def update
# ...
end
private
def find_product
# ...
end
def find_settings
# Note that we use find_or_initialize_by
model = Recommendation::Settings.find_or_initialize_by(id: @product.id)
@settings = RecommendationsViewModel.new(model, view_model_options)
end
end
end
end
Possible solutions to fix this weirdness
Workarea::Recommendation::Settings
in workarea-core
when a new product is created (worker, inline, ...) to always have the 1:1 relationship.workarea-api
to programmatically create the relationship./workarea-api-4.5.3/admin/app/controllers/workarea/api/admin/recommendation_settings_controller.rb
:module Workarea
module Api
module Admin
class RecommendationSettingsController < Admin::ApplicationController
before_action :find_recommendation_settings
swagger_path '/products/{product_id}/recommendation_settings' do
# ...
end
def show
respond_with recommendation_settings: @recommendation_settings
end
def update
@recommendation_settings.update_attributes!(params[:recommendation_settings])
respond_with recommendation_settings: @recommendation_settings
end
private
def find_recommendation_settings
# Use find_or_initialize_by here
@recommendation_settings = Recommendation::Settings.find(params[:product_id])
end
end
end
end
end
Personally I'm rolling with the find_or_initialize_by (solution 3) for the current build I'm working on.
Cheers 🍻
This is an example task for you to see how a “real” task in this project works.
Goal: Based on research, we’ve found the top 3 blockers to using calendar and are implementing solutions to solve: discoverability, speed, and functionality.
Metrics: 30% higher calendar usage after 90 days.
This project template is set up in Board View with columns to help you track your team's work. We've provided some example content in this template to get you started, but you should add tasks, change task names, and add any other info to make this project your own.
Learn more about planning your sprints in Asana:
https://asana.com/guide/examples/eng/sprint-planning
https://academy.asana.com/series/product-use-cases/sprint-planning-course
Send feedback about this template:
https://asana.com/research/templates-feedback
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.