Skip to content

Commit

Permalink
implemented data,database,model modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bedirhansaricayir committed Jul 18, 2024
1 parent 119ed6e commit af3acca
Show file tree
Hide file tree
Showing 48 changed files with 1,384 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
Expand Down Expand Up @@ -88,6 +89,7 @@ dependencies {
api(project(":core:network"))
api(project(":core:navigation"))
api(project(":core:designsystem"))
api(project(":core:data"))

Kotlin.list.forEach(::api)
Compose.list.forEach(::api)
Expand All @@ -100,4 +102,5 @@ dependencies {
}

api(Androidx.splash)
coreLibraryDesugaring(ThirdParty.desugaring)
}
1 change: 1 addition & 0 deletions buildSrc/src/main/java/BuildPlugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object BuildPlugins {
const val KOTLIN_JVM_PLUGIN = "org.jetbrains.kotlin.jvm"
const val KOTLIN_ANDROID_JB_PLUGIN = "org.jetbrains.kotlin.android"
const val SERIALIZATION_PLUGIN = "plugin.serialization"
const val KOTLIN_PARCELIZE = "kotlin-parcelize"


}
1 change: 1 addition & 0 deletions core/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id(BuildPlugins.ANDROID_LIBRARY_PLUGIN)
id(BuildPlugins.KOTLIN_ANDROID_PLUGIN)
id(BuildPlugins.DAGGER_HILT)
id(BuildPlugins.KSP_PLUGIN)
}

android {
namespace = "com.lifting.app.core.data"
compileSdk = AppConfig.COMPILE_SDK

defaultConfig {
minSdk = AppConfig.MIN_SDK

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
api(project(":core:database"))
Kotlin.list.forEach(::api)

with(Di){
api(hiltAndroid)
ksp(hiltAndroidCompiler)
ksp(hiltCompiler)
}
}
Empty file added core/data/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/data/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions core/data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lifting.app.core.data.di

import com.lifting.app.core.data.repository.exercises.ExercisesRepository
import com.lifting.app.core.data.repository.exercises.ExercisesRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

/**
* Created by bedirhansaricayir on 18.07.2024
*/

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {

@Binds
internal abstract fun bindsExercisesRepository(
exercisesRepository: ExercisesRepositoryImpl
): ExercisesRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.lifting.app.core.data.repository.exercises

import com.lifting.app.core.model.Exercise
import com.lifting.app.core.model.ExerciseCategory
import com.lifting.app.core.model.ExerciseWithInfo
import com.lifting.app.core.model.ExerciseWithMuscle
import com.lifting.app.core.model.LogEntriesWithWorkout
import kotlinx.coroutines.flow.Flow

/**
* Created by bedirhansaricayir on 15.07.2024
*/

interface ExercisesRepository {

fun getExercise(exerciseId: String): Flow<Exercise>

fun getAllExercises(): Flow<List<Exercise>>

fun getAllExerciseWithInfo(searchQuery: String?): Flow<List<ExerciseWithInfo>>

fun getAllExercisesWithMuscle(): Flow<List<ExerciseWithMuscle>>

fun getAllLogEntries(exerciseId: String): Flow<List<LogEntriesWithWorkout>>

fun getVisibleLogEntries(exerciseId: String): Flow<List<LogEntriesWithWorkout>>

fun getVisibleLogEntriesCount(exerciseId: String): Flow<Long>

suspend fun createExercise(
name: String? = null,
notes: String? = null,
primaryMuscleTag: String? = null,
secondaryMuscleTag: String? = null,
category: ExerciseCategory? = null,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.lifting.app.core.data.repository.exercises

import com.lifting.app.core.database.dao.ExercisesDao
import com.lifting.app.core.database.model.ExerciseEntity
import com.lifting.app.core.database.model.ExerciseWithInfoResource
import com.lifting.app.core.database.model.ExerciseWithMuscleResource
import com.lifting.app.core.database.model.LogEntriesWithWorkoutResource
import com.lifting.app.core.database.model.toDomain
import com.lifting.app.core.model.Exercise
import com.lifting.app.core.model.ExerciseCategory
import com.lifting.app.core.model.ExerciseWithInfo
import com.lifting.app.core.model.ExerciseWithMuscle
import com.lifting.app.core.model.LogEntriesWithWorkout
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import java.util.UUID
import javax.inject.Inject

/**
* Created by bedirhansaricayir on 18.07.2024
*/

internal class ExercisesRepositoryImpl @Inject constructor(
private val exercisesDao: ExercisesDao
): ExercisesRepository {
override fun getExercise(exerciseId: String): Flow<Exercise> = exercisesDao.getExercise(exerciseId).map { it.toDomain() }

override fun getAllExercises(): Flow<List<Exercise>> = exercisesDao.getAllExercises().map { it.map(ExerciseEntity::toDomain)}

override fun getAllExerciseWithInfo(searchQuery: String?): Flow<List<ExerciseWithInfo>> = exercisesDao.getAllExercisesWithInfo(searchQuery).map { it.map(ExerciseWithInfoResource::toDomain) }

override fun getAllExercisesWithMuscle(): Flow<List<ExerciseWithMuscle>> = exercisesDao.getAllExercisesWithMuscles().map { it.map(ExerciseWithMuscleResource::toDomain) }

override fun getAllLogEntries(exerciseId: String): Flow<List<LogEntriesWithWorkout>> = exercisesDao.getAllLogEntries(exerciseId).map { it.map(LogEntriesWithWorkoutResource::toDomain) }

override fun getVisibleLogEntries(exerciseId: String): Flow<List<LogEntriesWithWorkout>> = exercisesDao.getVisibleLogEntries(exerciseId).map { it.map(LogEntriesWithWorkoutResource::toDomain) }

override fun getVisibleLogEntriesCount(exerciseId: String): Flow<Long> = exercisesDao.getVisibleLogEntriesCount(exerciseId)

override suspend fun createExercise(
name: String?,
notes: String?,
primaryMuscleTag: String?,
secondaryMuscleTag: String?,
category: ExerciseCategory?
) = exercisesDao.insertExercise(
ExerciseEntity(
exerciseId = UUID.randomUUID().toString(),
name = name,
notes = notes,
primaryMuscleTag = primaryMuscleTag,
secondaryMuscleTag = secondaryMuscleTag,
category = category,
)
)
}
1 change: 1 addition & 0 deletions core/database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugins {
id(BuildPlugins.ANDROID_LIBRARY_PLUGIN)
id(BuildPlugins.KOTLIN_ANDROID_PLUGIN)
id(BuildPlugins.KSP_PLUGIN)
}

android {
namespace = "com.lifting.app.core.database"
compileSdk = AppConfig.COMPILE_SDK

defaultConfig {
minSdk = AppConfig.MIN_SDK

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
api(project(":core:model"))

with(Room) {
implementation(room)
implementation(roomRuntime)
ksp(roomCompiler)
}

with(Di) {
implementation(hiltAndroid)
ksp(hiltCompiler)
ksp(hiltAndroidCompiler)
}

coreLibraryDesugaring(ThirdParty.desugaring)
}
Empty file.
21 changes: 21 additions & 0 deletions core/database/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.lifting.app.core.database

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.lifting.app.core.database.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/database/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.lifting.app.core.database

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.lifting.app.core.database.dao.ExercisesDao
import com.lifting.app.core.database.model.ExerciseEntity
import com.lifting.app.core.database.model.ExerciseLogEntryEntity
import com.lifting.app.core.database.model.ExerciseSetGroupNoteEntity
import com.lifting.app.core.database.model.ExerciseWorkoutJunction
import com.lifting.app.core.database.model.MuscleEntity
import com.lifting.app.core.database.model.WorkoutEntity
import com.lifting.app.core.database.util.Converters

/**
* Created by bedirhansaricayir on 18.07.2024
*/

@Database(
entities = [
ExerciseEntity::class,
ExerciseLogEntryEntity::class,
ExerciseSetGroupNoteEntity::class,
MuscleEntity::class,
WorkoutEntity::class,
ExerciseWorkoutJunction::class,
],
version = 1,
exportSchema = true
)
@TypeConverters(Converters::class)
internal abstract class LiftingDatabase: RoomDatabase() {
abstract fun exercisesDao(): ExercisesDao
}
Loading

0 comments on commit af3acca

Please sign in to comment.