Coder Social home page Coder Social logo

workarea-commerce / workarea-api Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 1.0 1.07 MB

Adds JSON REST APIs to the Workarea Commerce Platform

Home Page: https://www.workarea.com

License: Other

Ruby 95.26% HTML 1.80% JavaScript 0.25% CSS 0.24% Haml 2.45%
workarea workarea-commerce json-api rest-api ecommerce

workarea-api's People

Contributors

meowsus avatar mttdffy avatar tubbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

workarea-api's Issues

Use Bulk Indexing during Bulk operations

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.

Recommendations endpoints suggestion

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

  1. We could automatically create a Workarea::Recommendation::Settings in workarea-core when a new product is created (worker, inline, ...) to always have the 1:1 relationship.
  2. We could add an endpoint in workarea-api to programmatically create the relationship.
  3. Tweak /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 🍻

[EXAMPLE TASK] - Launch updated calendar feature

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.

[READ ME] - Instructions for using this template

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.