-
Notifications
You must be signed in to change notification settings - Fork 5
Resource API
Resources in Blogify are fetched, updated, created and deleted through a single interface, which abstracts away all the logic
A Resource
represents a data model used by Blogify. They are implemented as Kotlin data classes, for example here is an example Resource:
data class Person (
val firstName: String,
val lastName: String,
override val uuid: UUID = UUID.randomUUID() /* temporary */
): Resource(uuid)
Resources all have a number of things in common, we will explore those in the coming paragraphs.
This is pretty self-explanatory.
Blogify has an included mechanism for generating a blueprint for producing DTOs for client-to-server transfer, internally called a PropMap
for property map.
Every PropMap
stores a list of PropMap.PropertyHandle
objects, which have three possible values: Ok
, Computed
or AccessDenied
. Ok
and Computed
(both of which implement PropertyHandle.Valid
) represent a property that can be accessed on an object of the class the PropMap
was generated from, while AccessDenied
is generated for a property that can't be read on that object.
A PropMap
can be obtained in two ways :
val personPropMap = Person::class.cachedPropMap() // Method #1
val personPropMap = personObject.cachedPropMap() // Method #2
To generate a DTO from that PropMap
, two methods are available :
-
Resource::sanitize()
, which returns aMap<String, Any?>
of all properties obtained from handles that implementPropertyHandle.Valid
-
Resource::slice(selectedPropertyNames: Set<String>)
, which returns aMap<String, Any?>
of all properties obtained from the handles with names specified inselectedPropertyNames
which implementValid
-
Note - if a requested property is marked as
AccessDenied
or is not found, its name will be included in the_accessDenied
and_notFound
fields of the DTO, respectively.
-
Note - if a requested property is marked as
The Service<R : Resource>
class provides abstractions for CRUD operations on resources of its type R
. Read the provided KDoc for more information
Note - ALL operations using Service
return an Sr
(SuspendableResult
) object. Please see documentation on the Result
library for more information