Skip to content

: find an alternative for with_fields #306

@github-actions

Description

@github-actions

# TODO:: find an alternative for with_fields

      query.search_field "name"
      query.sort(NAME_SORT_ASC)
      paginate_results(elastic, query)
    end

    @[AC::Route::GET("/:id")]
    def show(
      @[AC::Param::Info(name: "compilation_status", description: "check if the driver is compiled?", example: "false")]
      include_compilation_status : Bool = true
    ) : Model::Driver | Hash(String, Hash(String, Bool) | JSON::Any)
      # TODO:: find an alternative for with_fields
      !include_compilation_status ? current_driver : with_fields(current_driver, {
        "compilation_status" => Api::Drivers.compilation_status(current_driver, request_id),
      })
    end

    @[AC::Route::PATCH("/:id", body: :driver)]
    @[AC::Route::PUT("/:id", body: :driver)]
    def update(driver : Model::Driver) : Model::Driver
      current = current_driver
      current.assign_attributes(driver)
      raise Error::ModelValidation.new({ActiveModel::Error.new(current_driver, :role, "Driver role must not change")}) if current_driver.role_changed?
      raise Error::ModelValidation.new(current.errors) unless current.save
      current
    end

    @[AC::Route::POST("/", body: :driver, status_code: HTTP::Status::CREATED)]
    def create(driver : Model::Driver) : Model::Driver
      raise Error::ModelValidation.new(driver.errors) unless driver.save
      driver
    end

    @[AC::Route::DELETE("/:id", status_code: HTTP::Status::ACCEPTED)]
    def destroy : Nil
      current_driver.destroy
    end

    @[AC::Route::POST("/:id/recompile", status: {
      Nil => HTTP::Status::ALREADY_REPORTED,
    })]
    def recompile : Model::Driver?
      if current_driver.commit.starts_with?("RECOMPILE")
        nil
      else
        if (recompiled = Drivers.recompile(current_driver))
          if recompiled.destroyed?
            raise Error::NotFound.new("driver was deleted")
          else
            recompiled
          end
        else
          raise IO::TimeoutError.new("time exceeded waiting for driver to recompile")
        end
      end
    end

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions