app/src/main/java/com/geekorum/ttrss/sync/DatabaseService.kt
author Da Risk <da_risk@geekorum.com>
Sat, 11 May 2019 19:53:20 -0700
changeset 149 1e4bb9b9b86c
parent 137 5464f07a306c
child 150 c6077ce0d399
permissions -rw-r--r--
Synchronization: convert DAO to kotlin and use suspendable functions

/*
 * Geekttrss is a RSS feed reader application on the Android Platform.
 *
 * Copyright (C) 2017-2019 by Frederic-Charles Barthelery.
 *
 * This file is part of Geekttrss.
 *
 * Geekttrss is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Geekttrss is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.geekorum.ttrss.sync

import com.geekorum.ttrss.data.Article
import com.geekorum.ttrss.data.Category
import com.geekorum.ttrss.data.Feed
import com.geekorum.ttrss.data.Transaction

/**
 * Database access interface for the synchronization process.
 */
interface DatabaseService {
    fun beginTransaction()
    fun endTransaction()
    fun setTransactionSuccessful()
    suspend fun <R> runInTransaction(block: suspend () -> R)

    suspend fun insertFeeds(feeds: List<Feed>)
    suspend fun deleteFeedsAndArticles(feeds: List<Feed>)
    suspend fun getFeeds(): List<Feed>

    suspend fun insertCategories(categories: List<Category>)
    suspend fun deleteCategories(categories: List<Category>)
    suspend fun getCategories(): List<Category>

    suspend fun getTransactions(): List<Transaction>
    suspend fun deleteTransaction(transaction: Transaction)

    suspend fun getArticle(id: Long): Article?
    suspend fun insertArticles(articles: List<Article>)
    suspend fun updateArticle(article: Article)
    suspend fun getLatestArticleId(): Long?

    suspend fun updateArticleMetadata(
        id: Long, unread: Boolean, transientUnread: Boolean, starred: Boolean,
        published: Boolean, lastTimeUpdated: Long, isUpdated: Boolean)
}