Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

: find an alternative for with_fields #306

Open
github-actions bot opened this issue Sep 26, 2022 · 0 comments
Open

: find an alternative for with_fields #306

github-actions bot opened this issue Sep 26, 2022 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant