
module Devops
  module API3
    module Routes
      module DeployRoutes

        def self.registered(app)

          app.get "/deploy/data/:project/:env" do |project, env|
            p = Devops::Db.connector.project project
            data = p.deploy_info(env, params["build_number"])
            content_type "application/json"
            (JSON.pretty_generate data) << "\n"
          end

          app.get "/deploy/data/:file" do |file|
            dir = DevopsConfig.config[:project_info_dir]
            file_path = File.join(dir, file)
            return [404, "Data for '#{file}' not found"] unless File.exists?(file_path)
            content_type "application/json"
            File.read(file_path) + "\n"
          end

          puts "Deploy routes initialized"
        end

      end
    end
  end
end
