Sha256: 9cb1965224fadb00ff6a3f724ac847f15fa5088683a54edd13b84c13a3a7a1c6

Contents?: true

Size: 1.98 KB

Versions: 6

Compression:

Stored size: 1.98 KB

Contents

Dir['*.rb'].each { |file| require_relative file }

class EditSectionHandler < BaseHandler
    def mount
        @server.mount_proc('/section/edit') do |req, res|
            if req.request_method == 'POST'
                begin
                    request_payload = JSON.parse(req.body)
                    brand_key = request_payload['brand_key']
                    key = request_payload['key']
                    data = request_payload['data']

                    update_section(key, data, brand_key)
                    set_current_brand_content_changed(brand_key, true)

                    res.status = 200
                    res.body = JSON.generate({ success: true, message: "Configuration for #{key} updated successfully" })
                    res.content_type = 'application/json'
                rescue JSON::ParserError => e
                    handle_error(res, e, "Invalid JSON in request body", 400)
                rescue StandardError => e
                    handle_error(res, e, "Error updating configuration")
                end
            else
                method_not_allowed(res)
            end
        end
    end

    def update_section(key, data, brand_key)
        template = BrandConfigurationsManager.new(brand_key).template_with_key(key)

        path = template[:path]
        
        if File.exist?(path)
            if key === 'InfoPlist.xcstrings'
                InfoPListStringCatalogManager.new(FilePath.brand_infoplist_string_catalog(brand_key)).update(data)
            else
                File.write(path, JSON.pretty_generate(data))
            end
            Solara.logger.debug("Updated Config for #{path}: #{data}")
        else
            raise "Config file not found: #{path}"
        end
    rescue StandardError => e
        Solara.logger.failure("Error updating section: #{e.message}")
        raise
    end

    def set_current_brand_content_changed(brand_key, changed)
        BrandsManager.instance.set_current_brand_content_changed(brand_key, changed)
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solara-0.4.0 solara/lib/core/dashboard/handler/edit_section_handler.rb
solara-0.3.0 solara/lib/core/dashboard/handler/edit_section_handler.rb
solara-0.2.4 solara/lib/core/dashboard/handler/edit_section_handler.rb
solara-0.2.3 solara/lib/core/dashboard/handler/edit_section_handler.rb
solara-0.2.2 solara/lib/core/dashboard/handler/edit_section_handler.rb
solara-0.2.1 solara/lib/core/dashboard/handler/edit_section_handler.rb