Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MyKSuite-12): Add models for api call #285

Merged
merged 6 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions MykSuite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ plugins {
id("com.android.library")
alias(core.plugins.kotlin.android)
alias(core.plugins.compose.compiler)
alias(core.plugins.ksp)
kotlin("plugin.parcelize")
kotlin("plugin.serialization") version core.versions.kotlin
id("androidx.navigation.safeargs.kotlin")
}

Expand All @@ -19,6 +21,8 @@ android {
minSdk = legacyMinSdk

consumerProguardFiles("consumer-rules.pro")

ksp { arg("room.schemaLocation", "$projectDir/schemas") }
}

buildTypes {
Expand Down Expand Up @@ -47,6 +51,12 @@ dependencies {
implementation(core.androidx.core.ktx)
implementation(core.material)
implementation(core.navigation.fragment.ktx)
implementation(core.kotlinx.serialization.json)

// Room
implementation(core.room.runtime)
implementation(core.room.ktx)
ksp(core.room.compiler)

// Compose
implementation(core.coil.compose)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "7b5e43bd9cc17b034cf90891e63090d7",
"entities": [
{
"tableName": "MyKSuiteData",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `status` TEXT NOT NULL, `pack_id` INTEGER NOT NULL, `trialExpiryAt` INTEGER, `is_free` INTEGER NOT NULL, `has_auto_renew` INTEGER NOT NULL, `canTrial` INTEGER NOT NULL, `user_id` INTEGER NOT NULL, `k_suite_pack_id` INTEGER NOT NULL, `k_suite_pack_name` TEXT NOT NULL, `k_suite_pack_drive_storage` INTEGER NOT NULL, `k_suite_pack_mail_storage` INTEGER NOT NULL, `k_suite_pack_mail_daily_limit_send` INTEGER NOT NULL, `k_suite_pack_is_max_storage_offer` INTEGER NOT NULL, `drive_id` INTEGER NOT NULL, `drive_name` TEXT NOT NULL, `drive_size` INTEGER NOT NULL, `drive_used_size` INTEGER NOT NULL, `mail_id` INTEGER NOT NULL, `mail_email` TEXT NOT NULL, `mail_daily_limit_sent` INTEGER NOT NULL, `mail_storage_size_limit` INTEGER NOT NULL, `mail_used_size` INTEGER NOT NULL, `mail_mailboxId` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "status",
"columnName": "status",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "kSuitePackId",
"columnName": "pack_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "trialExpiryAt",
"columnName": "trialExpiryAt",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "isFree",
"columnName": "is_free",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "hasAutoRenew",
"columnName": "has_auto_renew",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "canTrial",
"columnName": "canTrial",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "userId",
"columnName": "user_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kSuitePack.id",
"columnName": "k_suite_pack_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kSuitePack.name",
"columnName": "k_suite_pack_name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "kSuitePack.driveStorage",
"columnName": "k_suite_pack_drive_storage",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kSuitePack.mailStorage",
"columnName": "k_suite_pack_mail_storage",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kSuitePack.mailDailyLimitSend",
"columnName": "k_suite_pack_mail_daily_limit_send",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "kSuitePack.isMaxStorageOffer",
"columnName": "k_suite_pack_is_max_storage_offer",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "drive.id",
"columnName": "drive_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "drive.name",
"columnName": "drive_name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "drive.size",
"columnName": "drive_size",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "drive.usedSize",
"columnName": "drive_used_size",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mail.id",
"columnName": "mail_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mail.email",
"columnName": "mail_email",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mail.dailyLimitSent",
"columnName": "mail_daily_limit_sent",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mail.storageSizeLimit",
"columnName": "mail_storage_size_limit",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mail.usedSize",
"columnName": "mail_used_size",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mail.mailboxId",
"columnName": "mail_mailboxId",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7b5e43bd9cc17b034cf90891e63090d7')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Infomaniak Core - Android
* Copyright (C) 2025 Infomaniak Network SA
*
* 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.infomaniak.core.myksuite.ui.data

import androidx.annotation.StringRes
import androidx.room.ColumnInfo
import com.infomaniak.core.myksuite.R
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class KSuitePack(
val id: Int,
val name: String = "",
@SerialName("drive_storage")
@ColumnInfo("drive_storage")
val driveStorage: Long = 0,
@SerialName("mail_storage")
@ColumnInfo("mail_storage")
val mailStorage: Long = 0,
@SerialName("mail_daily_limit_send")
@ColumnInfo("mail_daily_limit_send")
val mailDailyLimitSend: Int = 0,
@SerialName("is_max_storage_offer")
@ColumnInfo("is_max_storage_offer")
val isMaxStorageOffer: Boolean = false,
) {

val type get() = runCatching { enumValueOf<KSuitePackType>(name.uppercase()) }.getOrNull()

enum class KSuitePackType(@StringRes val displayNameRes: Int) {
MY_KSUITE(R.string.myKSuiteName),
MY_KSUITE_PLUS(R.string.myKSuitePlusName),
MY_KSUITE_PLUS_DRIVE_SOLO(R.string.myKSuitePlusName),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Infomaniak Core - Android
* Copyright (C) 2025 Infomaniak Network SA
*
* 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.infomaniak.core.myksuite.ui.data

import androidx.room.ColumnInfo
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

@Serializable
@Entity
data class MyKSuiteData(
@PrimaryKey val id: Int,
val status: String,
@SerialName("pack_id")
@ColumnInfo("pack_id")
val kSuitePackId: Int,
@SerialName("pack")
@Embedded("k_suite_pack_")
val kSuitePack: KSuitePack,
@SerialName("trial_expiry_at")
@ColumnInfo("trial_expiry_at")
val trialExpiryAt: Long? = null,
@SerialName("is_free")
@ColumnInfo("is_free")
val isFree: Boolean,
@Embedded("drive_")
val drive: KSuiteDrive,
@Embedded("mail_")
val mail: KSuiteMail,
@SerialName("has_auto_renew")
@ColumnInfo("has_auto_renew")
val hasAutoRenew: Boolean,
@SerialName("can_trial")
@ColumnInfo("can_trial")
val canTrial: Boolean,
) {

@Transient
@ColumnInfo("user_id")
var userId: Int = 0

val isMyKSuite get() = kSuitePack.type == KSuitePack.KSuitePackType.MY_KSUITE
val isMyKSuitePlus
get() = kSuitePack.type == KSuitePack.KSuitePackType.MY_KSUITE_PLUS ||
kSuitePack.type == KSuitePack.KSuitePackType.MY_KSUITE_PLUS_DRIVE_SOLO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Infomaniak Core - Android
* Copyright (C) 2025 Infomaniak Network SA
*
* 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.infomaniak.core.myksuite.ui.data

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Query
import androidx.room.Upsert

@Dao
interface MyKSuiteDataDao {

@Query("SELECT * FROM MyKSuiteData")
suspend fun getAll(): List<MyKSuiteData>

@Query("SELECT * FROM MyKSuiteData WHERE id = :id LIMIT 1")
suspend fun findById(id: Int): MyKSuiteData?

@Query("SELECT * FROM MyKSuiteData WHERE user_id = :userId LIMIT 1")
suspend fun findByUserId(userId: Int): MyKSuiteData?

@Upsert
suspend fun upsert(data: MyKSuiteData)

@Delete
suspend fun delete(data: MyKSuiteData)
}
Loading