RestQuery

class RestQuery<T, I, Q>(resource: Resource<T, I>, initialId: I, contentType: String, remote: Request, buildQuery: suspend Request.(Q) -> Response) : QueryRepository<T, I, Q>

provides services to deal with queries for REST-API to a defined Resource

Parameters

resource

definition of the Resource

initialId

id to compare a given resource for differentiation of adding or updating

contentType

to be used by the REST-API

remote

base Request to be used by all subsequent requests. Use it to configure authentication, etc.

buildQuery

function to build a Request for a given object defining the query

Constructors

Link copied to clipboard
fun <T, I, Q> RestQuery(resource: Resource<T, I>, initialId: I, contentType: String, remote: Request, buildQuery: suspend Request.(Q) -> Response)

Functions

Link copied to clipboard
open suspend override fun addOrUpdate(entities: List<T>, entity: T): List<T>

sends a post-(for add) or a put-(for update) request to remote/{id} with the serialized entity in it's body. The initialId is used to determine if it should saved or updated.

Link copied to clipboard
open suspend override fun delete(entities: List<T>, id: I): List<T>

deletes one entity from the list

open suspend override fun delete(entities: List<T>, ids: List<I>): List<T>

deletes multiple entities from the list

Link copied to clipboard
open suspend override fun query(query: Q): List<T>

queries the resource by sending the request which is build by buildQuery using the query

Link copied to clipboard
open suspend override fun updateMany(entities: List<T>, entitiesToUpdate: List<T>): List<T>

updates given entities in the entities list (sending a put-request to the base-url of the resource for every updated entity)

Properties

Link copied to clipboard
val contentType: String
Link copied to clipboard
val initialId: I