Sharingang/Sharingang-Android

View on GitHub
app/src/main/java/com/example/sharingang/database/store/ItemStore.kt

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
package com.example.sharingang.database.store

import com.example.sharingang.models.Item

/**
 * Represents a remote store of items, that we can access in some way.
 *
 * This isn't intended to be used directly in the UI (that's what an ItemRepository
 * would be for), but rather to provide an abstraction over the remote fetching of items.
 */
interface ItemStore {
    /**
     * Set an item
     *
     * Add a new item if the item's id is null.
     * Update an existing item if the item's id is not null.
     *
     * @return id of the item generated by the database
     */
    suspend fun set(item: Item): String?

    /**
     * Returns the item with corresponding id or null if it doesn't exist
     */
    suspend fun get(id: String): Item?

    /**
     * Returns all of the items that exist
     */
    suspend fun getAll(): List<Item>

    /**
     * Delete existing item
     *
     * @return true if the deletion succeeded or there is no item with such id
     */
    suspend fun delete(id: String): Boolean
}