Add model to ArbitraryStorage db layer

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-06-24 10:07:05 +02:00
parent a207ad7b97
commit 3b1d4b86a9
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 91 additions and 9 deletions

View file

@ -0,0 +1,48 @@
/*
* Nextcloud Talk application
*
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <infoi@andy-scherzinger.de>
*
* model program 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.
*
* model program 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 model program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
object ArbitraryStorageMapper {
fun toModel(entity: ArbitraryStorageEntity?): ArbitraryStorage? {
return if (entity == null) {
null
} else {
ArbitraryStorage(
entity.accountIdentifier,
entity.key,
entity.storageObject,
entity.value
)
}
}
fun toEntity(model: ArbitraryStorage): ArbitraryStorageEntity {
return ArbitraryStorageEntity(
accountIdentifier = model.accountIdentifier,
key = model.key,
storageObject = model.storageObject,
value = model.value
)
}
}

View file

@ -20,10 +20,10 @@
package com.nextcloud.talk.data.storage package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity import com.nextcloud.talk.data.storage.model.ArbitraryStorage
interface ArbitraryStoragesRepository { interface ArbitraryStoragesRepository {
fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorageEntity fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorage
suspend fun deleteArbitraryStorage(accountIdentifier: Long) suspend fun deleteArbitraryStorage(accountIdentifier: Long)
fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorageEntity): Long fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long
} }

View file

@ -20,7 +20,7 @@
package com.nextcloud.talk.data.storage package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity import com.nextcloud.talk.data.storage.model.ArbitraryStorage
class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) : class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) :
ArbitraryStoragesRepository { ArbitraryStoragesRepository {
@ -28,15 +28,17 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
accountIdentifier: Long, accountIdentifier: Long,
key: String, key: String,
objectString: String objectString: String
): ArbitraryStorageEntity { ): ArbitraryStorage {
return arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString) return ArbitraryStorageMapper.toModel(
arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString)
)!!
} }
override suspend fun deleteArbitraryStorage(accountIdentifier: Long) { override suspend fun deleteArbitraryStorage(accountIdentifier: Long) {
arbitraryStoragesDao.deleteArbitraryStorage(accountIdentifier) arbitraryStoragesDao.deleteArbitraryStorage(accountIdentifier)
} }
override fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorageEntity): Long { override fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long {
return arbitraryStoragesDao.saveArbitraryStorage(arbitraryStorage) return arbitraryStoragesDao.saveArbitraryStorage(ArbitraryStorageMapper.toEntity(arbitraryStorage))
} }
} }

View file

@ -0,0 +1,32 @@
/*
* Nextcloud Talk application
*
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <infoi@andy-scherzinger.de>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.data.storage.model
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class ArbitraryStorage(
var accountIdentifier: Long = 0,
var key: String? = null,
var storageObject: String? = null,
var value: String? = null
) : Parcelable

View file

@ -80,8 +80,8 @@ import com.google.android.material.chip.ChipDrawable;
import com.nextcloud.talk.R; import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User; import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.data.user.model.UserEntity;
import com.nextcloud.talk.events.UserMentionClickEvent; import com.nextcloud.talk.events.UserMentionClickEvent;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.utils.text.Spans; import com.nextcloud.talk.utils.text.Spans;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;