Skip to content

Commit

Permalink
feat(explore): tạo study set bằng AI (sử dụng coin để tạo)
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Nov 30, 2024
1 parent d832948 commit e65b696
Show file tree
Hide file tree
Showing 26 changed files with 358 additions and 80 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
localProperties.getProperty("REWARD_ADS_ID") ?: "ca-app-pub-5725743620724195/5188260450"
val rewardedInterstitialAdsId: String =
localProperties.getProperty("REWARDED_INTERSTITIAL_ADS_ID")
?: "ca-app-pub-3940256099942544/5354046379"
?: "ca-app-pub-5725743620724195/6760705307"
val oneSignalAppId: String = localProperties.getProperty("ONESIGNAL_APP_ID")
?: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba"
val revenueCatApiKey: String = localProperties.getProperty("REVENUECAT_API_KEY")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.pwhs.quickmem.core.data.enums

enum class CoinAction (val action: String) {
ADD("add"),
SUBTRACT("subtract")
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/pwhs/quickmem/core/datastore/AppManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.util.Patterns
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import com.pwhs.quickmem.util.dataStore
import kotlinx.coroutines.flow.Flow
Expand All @@ -23,6 +24,7 @@ class AppManager(private val context: Context) {
val USER_BIRTHDAY = stringPreferencesKey("USER_BIRTHDAY")
val PUSH_NOTIFICATIONS = booleanPreferencesKey("PUSH_NOTIFICATIONS")
val APP_PUSH_NOTIFICATIONS = booleanPreferencesKey("APP_PUSH_NOTIFICATIONS")
val USER_COINS = intPreferencesKey("USER_COINS")
}

val isFirstRun: Flow<Boolean> = context.dataStore.data
Expand Down Expand Up @@ -72,6 +74,11 @@ class AppManager(private val context: Context) {
preferences[USER_BIRTHDAY] ?: ""
}

val userCoins: Flow<Int> = context.dataStore.data
.map { preferences ->
preferences[USER_COINS] ?: 0
}

suspend fun saveIsFirstRun(isFirstRun: Boolean) {
Timber.d("Saving is first run: $isFirstRun")
context.dataStore.edit { preferences ->
Expand Down Expand Up @@ -150,6 +157,13 @@ class AppManager(private val context: Context) {
}
}

suspend fun saveUserCoins(coins: Int) {
Timber.d("Saving user coins: $coins")
context.dataStore.edit { preferences ->
preferences[USER_COINS] = coins
}
}

suspend fun clearAllData() {
context.dataStore.edit { preferences ->
preferences.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ data class AuthResponseDto(
val provider: String? = null,
@SerializedName("isVerified")
val isVerified: Boolean? = null,
@SerializedName("coin")
val coin: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ data class GetUserProfileResponseDto(
val avatarUrl: String,
@SerializedName("role")
val role: String,
@SerializedName("coin")
val coin: Int,
@SerializedName("createdAt")
val createdAt: String,
@SerializedName("updatedAt")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pwhs.quickmem.data.dto.user

import com.google.gson.annotations.SerializedName

data class UpdateCoinRequestDto(
@SerializedName("userId")
val userId: String,
@SerializedName("coin")
val coin: Int,
@SerializedName("action")
val action: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pwhs.quickmem.data.dto.user

import com.google.gson.annotations.SerializedName

data class UpdateCoinResponseDto(
@SerializedName("message")
val message: String,
@SerializedName("coinAction")
val coinAction: String,
@SerializedName("coins")
val coins: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fun GetUserProfileResponseDto.toModel() = GetUserProfileResponseModel(
username = username,
avatarUrl = avatarUrl,
createdAt = createdAt,
updatedAt = updatedAt
updatedAt = updatedAt,
coin = coin
)

fun GetUserProfileResponseModel.toDto() = GetUserProfileResponseDto(
Expand All @@ -22,5 +23,6 @@ fun GetUserProfileResponseModel.toDto() = GetUserProfileResponseDto(
username = username,
avatarUrl = avatarUrl,
createdAt = createdAt,
updatedAt = updatedAt
updatedAt = updatedAt,
coin = coin
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pwhs.quickmem.data.mapper.user

import com.pwhs.quickmem.data.dto.user.UpdateCoinRequestDto
import com.pwhs.quickmem.domain.model.users.UpdateCoinRequestModel

fun UpdateCoinRequestDto.toModel() = UpdateCoinRequestModel(
userId = userId,
coin = coin,
action = action
)

fun UpdateCoinRequestModel.toDto() = UpdateCoinRequestDto(
userId = userId,
coin = coin,
action = action
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pwhs.quickmem.data.mapper.user

import com.pwhs.quickmem.data.dto.user.UpdateCoinResponseDto
import com.pwhs.quickmem.domain.model.users.UpdateCoinResponseModel

fun UpdateCoinResponseDto.toModel() = UpdateCoinResponseModel(
message = message,
coinAction = coinAction,
coins = coins
)

fun UpdateCoinResponseModel.toDto() = UpdateCoinResponseDto(
message = message,
coinAction = coinAction,
coins = coins
)
8 changes: 8 additions & 0 deletions app/src/main/java/com/pwhs/quickmem/data/remote/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ import com.pwhs.quickmem.data.dto.subject.GetTop5SubjectResponseDto
import com.pwhs.quickmem.data.dto.upload.DeleteImageDto
import com.pwhs.quickmem.data.dto.upload.UploadImageResponseDto
import com.pwhs.quickmem.data.dto.user.SearchUserResponseDto
import com.pwhs.quickmem.data.dto.user.UpdateCoinRequestDto
import com.pwhs.quickmem.data.dto.user.UpdateCoinResponseDto
import com.pwhs.quickmem.data.dto.user.UserDetailResponseDto
import okhttp3.MultipartBody
import retrofit2.Response
Expand Down Expand Up @@ -183,6 +185,12 @@ interface ApiService {
@Query("page") page: Int?
): List<SearchUserResponseDto>

@POST("auth/coin")
suspend fun updateCoin(
@Header("Authorization") token: String,
@Body request: UpdateCoinRequestDto
): UpdateCoinResponseDto

// Upload
@Multipart
@POST("upload")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.pwhs.quickmem.core.utils.Resources
import com.pwhs.quickmem.data.dto.verify_email.EmailRequestDto
import com.pwhs.quickmem.data.mapper.auth.toDto
import com.pwhs.quickmem.data.mapper.auth.toModel
import com.pwhs.quickmem.data.mapper.user.toDto
import com.pwhs.quickmem.data.mapper.user.toModel
import com.pwhs.quickmem.data.paging.UserPagingSource
import com.pwhs.quickmem.data.remote.ApiService
Expand Down Expand Up @@ -40,6 +41,8 @@ import com.pwhs.quickmem.domain.model.auth.VerifyEmailResponseModel
import com.pwhs.quickmem.domain.model.auth.VerifyPasswordRequestModel
import com.pwhs.quickmem.domain.model.auth.VerifyPasswordResponseModel
import com.pwhs.quickmem.domain.model.users.SearchUserResponseModel
import com.pwhs.quickmem.domain.model.users.UpdateCoinRequestModel
import com.pwhs.quickmem.domain.model.users.UpdateCoinResponseModel
import com.pwhs.quickmem.domain.model.users.UserDetailResponseModel
import com.pwhs.quickmem.domain.repository.AuthRepository
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -363,4 +366,23 @@ class AuthRepositoryImpl @Inject constructor(
}
}
}

override suspend fun updateCoin(
token: String,
updateCoinRequestModel: UpdateCoinRequestModel
): Flow<Resources<UpdateCoinResponseModel>> {
return flow {
emit(Resources.Loading())
try {
val response = apiService.updateCoin(
token,
updateCoinRequestModel.toDto()
)
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
emit(Resources.Error(e.toString()))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class AuthResponseModel(
val refreshToken: String? = null,
val provider: String? = null,
val isVerified: Boolean? = null,
val coin: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class GetUserProfileResponseModel(
val email: String,
val avatarUrl: String,
val role: String,
val coin: Int,
val createdAt: String,
val updatedAt: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pwhs.quickmem.domain.model.users

data class UpdateCoinRequestModel(
val userId: String,
val coin: Int,
val action: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pwhs.quickmem.domain.model.users

data class UpdateCoinResponseModel(
val message: String,
val coinAction: String,
val coins: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.pwhs.quickmem.domain.model.auth.VerifyEmailResponseModel
import com.pwhs.quickmem.domain.model.auth.VerifyPasswordRequestModel
import com.pwhs.quickmem.domain.model.auth.VerifyPasswordResponseModel
import com.pwhs.quickmem.domain.model.users.SearchUserResponseModel
import com.pwhs.quickmem.domain.model.users.UpdateCoinRequestModel
import com.pwhs.quickmem.domain.model.users.UpdateCoinResponseModel
import com.pwhs.quickmem.domain.model.users.UserDetailResponseModel
import kotlinx.coroutines.flow.Flow

Expand Down Expand Up @@ -110,4 +112,8 @@ interface AuthRepository {
changeRoleRequestModel: ChangeRoleRequestModel
): Flow<Resources<ChangeRoleResponseModel>>

suspend fun updateCoin(
token: String,
updateCoinRequestModel: UpdateCoinRequestModel
): Flow<Resources<UpdateCoinResponseModel>>
}
Loading

0 comments on commit e65b696

Please sign in to comment.