Sha256: 0e085a984be3a9bddcb70c6f12b9fa79d7582c42dccd8fa99cf89ba1b3a39a96

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

class OnboardBrandHandler < BaseHandler
    def mount
        @server.mount_proc('/brand/onboard') do |req, res|
            if req.request_method == 'POST'
                begin
                    data = JSON.parse(req.body)
                    brand_name = data['brand_name']
                    brand_key = data['brand_key']
                    clone_brand_key = data['clone_brand_key']

                    if brand_key
                        result = onboard_brand(brand_name, brand_key, clone_brand_key)
                        res.status = result[:success] ? 200 : 409 # 409 Conflict for existing brand
                        res.body = JSON.generate(result)
                    else
                        res.status = 400
                        res.body = JSON.generate({ success: false, error: 'Missing brand_key parameter' })
                    end
                rescue JSON::ParserError => e
                    handle_error(res, e, "Invalid JSON in request body", 400)
                rescue StandardError => e
                    handle_error(res, e, "Error adding brand")
                end
            else
                method_not_allowed(res)
            end
            res.content_type = 'application/json'
        end
    end

    def onboard_brand(brand_name, brand_key, clone_brand_key = nil)
        if BrandsManager.instance.exists(brand_key)
            return { success: false, message: "Brand with key (#{brand_key}) already added!" }
        end
        SolaraManager.new.onboard(brand_key, brand_name, clone_brand_key: clone_brand_key, open_dashboard: false)
        { success: true, message: "Brand added successfully" }
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solara-0.7.4 solara/lib/core/dashboard/handler/onboard_brand_handler.rb
solara-0.7.3 solara/lib/core/dashboard/handler/onboard_brand_handler.rb
solara-0.7.2 solara/lib/core/dashboard/handler/onboard_brand_handler.rb
solara-0.7.1 solara/lib/core/dashboard/handler/onboard_brand_handler.rb
solara-0.7.0 solara/lib/core/dashboard/handler/onboard_brand_handler.rb
solara-0.6.0 solara/lib/core/dashboard/handler/onboard_brand_handler.rb