Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lexwilliam committed Jul 15, 2024
1 parent 6185ffb commit 2693ae0
Show file tree
Hide file tree
Showing 83 changed files with 2,014 additions and 1,338 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {

defaultConfig {
applicationId = "com.lexwilliam.invence"
minSdk = 24
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
Expand Down
29 changes: 2 additions & 27 deletions app/src/main/java/com/lexwilliam/invence/ui/RootNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import androidx.navigation.NavHostController
import androidx.navigation.NavOptions
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.barcode.navigation.barcodeNavigation
import com.example.barcode.navigation.navigateToBarcode
import com.lexwilliam.auth.navigation.loginNavigation
import com.lexwilliam.auth.util.GoogleAuthUiClient
import com.lexwilliam.company.navigation.companyFormNavigation
Expand Down Expand Up @@ -65,13 +63,10 @@ fun RootNavGraph(
toProductForm = { productUUID ->
navController.navigateToProductForm(productUUID)
},
toProductDetail = { productUUID -> navController.navigateToProductDetail(productUUID) },
toBarcode = { navController.navigateToBarcode() }
toProductDetail = { productUUID -> navController.navigateToProductDetail(productUUID) }
)
productFormNavigation(
onBackStack = navController::navigateUp,
toBarcode = { onlyID -> navController.navigateToBarcode(onlyID) },
toInventory = navController::navigateToInventory
onBackStack = navController::navigateUp
)
productDetailNavigation(
onBackStack = navController::navigateUp,
Expand All @@ -86,26 +81,6 @@ fun RootNavGraph(
companyFormNavigation(
toHome = navController::navigateToHome
)
barcodeNavigation(
onBackStack = navController::navigateUp,
toProductDetail = { productUUID ->
navController.navigateToProductDetail(
productUUID,
NavOptions.Builder()
.setPopUpTo(Screen.BARCODE, true)
.build()
)
},
toProductForm = { productUUID, onlyID ->
navController.navigateToProductForm(
productUUID,
onlyID,
NavOptions.Builder()
.setPopUpTo(Screen.BARCODE, true)
.build()
)
}
)
cartNavigation(
toOrder = { orderUUID -> navController.navigateToOrder(orderUUID) }
)
Expand Down
2 changes: 1 addition & 1 deletion data/branch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.lexwilliam.branch.di

import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.firestore.FirebaseFirestore
import com.lexwilliam.branch.repository.BranchRepository
import com.lexwilliam.branch.repository.firebaseBranchRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {
@Singleton
@Provides
fun providesBranchRepository(
analytics: FirebaseCrashlytics,
store: FirebaseFirestore
): BranchRepository = firebaseBranchRepository(analytics, store)
package com.lexwilliam.branch.di

import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.firestore.FirebaseFirestore
import com.lexwilliam.branch.repository.BranchRepository
import com.lexwilliam.branch.repository.firebaseBranchRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {
@Singleton
@Provides
fun providesBranchRepository(
analytics: FirebaseCrashlytics,
store: FirebaseFirestore
): BranchRepository = firebaseBranchRepository(analytics, store)
}
2 changes: 1 addition & 1 deletion data/company/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion data/log/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
3 changes: 0 additions & 3 deletions data/log/src/main/java/com/lexwilliam/log/model/dto/LogDto.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.lexwilliam.log.model.dto

import android.os.Build
import androidx.annotation.RequiresApi
import com.google.firebase.firestore.PropertyName
import com.lexwilliam.core.util.validateUUID
import com.lexwilliam.firebase.toDate
Expand All @@ -10,7 +8,6 @@ import com.lexwilliam.log.model.DataLog
import kotlinx.datetime.Instant
import java.util.Date

@RequiresApi(Build.VERSION_CODES.O)
data class LogDto(
val uuid: String? = null,
@JvmField @PropertyName("branch_uuid")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.lexwilliam.log.repository

import android.os.Build
import androidx.annotation.RequiresApi
import arrow.core.Either
import arrow.core.raise.catch
import arrow.core.raise.either
Expand All @@ -18,7 +16,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import java.util.UUID

@RequiresApi(Build.VERSION_CODES.O)
fun firebaseLogRepository(
analytics: FirebaseCrashlytics,
store: FirebaseFirestore
Expand Down
2 changes: 1 addition & 1 deletion data/order/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion data/product/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ object ProductModule {
analytics: FirebaseCrashlytics,
store: FirebaseFirestore,
storage: FirebaseStorage
): ProductRepository = firebaseProductRepository(analytics, store, storage)
): ProductRepository =
firebaseProductRepository(
analytics,
store,
storage
)

@Singleton
@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.lexwilliam.product.model.dto

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.net.toUri
import com.google.firebase.Timestamp
import com.google.firebase.firestore.PropertyName
Expand All @@ -10,7 +8,6 @@ import com.lexwilliam.firebase.toTimestamp
import com.lexwilliam.product.model.Product
import kotlinx.datetime.Instant

@RequiresApi(Build.VERSION_CODES.O)
data class ProductDto(
val uuid: String? = null,
val name: String? = null,
Expand Down
2 changes: 1 addition & 1 deletion data/transaction/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion data/user/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
5 changes: 2 additions & 3 deletions data/user/src/main/java/com/lexwilliam/user/di/UserModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ object UserModule {
@Provides
fun providesSessionManager(
auth: FirebaseAuth,
crashlytics: FirebaseCrashlytics,
userRepository: UserRepository
): SessionManager = firebaseSessionManager(auth, crashlytics, userRepository)
crashlytics: FirebaseCrashlytics
): SessionManager = firebaseSessionManager(auth, crashlytics)

@Singleton
@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.lexwilliam.user.model

import com.google.firebase.firestore.PropertyName
import com.lexwilliam.core.util.validateUUID

data class EmployeeShiftDto(
@JvmField @PropertyName("user_uuid")
val userUUID: String? = null,
@JvmField @PropertyName("branch_uuid")
val branchUUID: String? = null,
val username: String? = null,
val shift: List<String>? = null
) {
fun toDomain() =
EmployeeShift(
userUUID = userUUID ?: "",
branchUUID = branchUUID.validateUUID(),
username = username ?: "",
shift = shift ?: emptyList()
)

companion object {
fun fromDomain(domain: EmployeeShift) =
EmployeeShiftDto(
userUUID = domain.userUUID,
branchUUID = domain.branchUUID.toString(),
username = domain.username,
shift = domain.shift
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import arrow.core.right
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.firestore.FirebaseFirestore
import com.lexwilliam.firebase.FirestoreConfig
import com.lexwilliam.user.model.EmployeeShift
import com.lexwilliam.user.model.EmployeeShiftDto
import com.lexwilliam.user.model.User
import com.lexwilliam.user.model.UserDto
import com.lexwilliam.user.util.FetchUserFailure
import com.lexwilliam.user.util.UnknownFailure
import com.lexwilliam.user.util.UpsertShiftFailure
import com.lexwilliam.user.util.UpsertUserFailure
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -83,4 +86,44 @@ fun firebaseUserRepository(
UnknownFailure(t.message)
}
}

override fun observeShift(uuid: String): Flow<EmployeeShift?> =
callbackFlow {
val reference =
store
.collection(FirestoreConfig.COLLECTION_EMPLOYEE_SHIFT)
.document(uuid)

val registration =
reference.addSnapshotListener { value, error ->
error?.let { exception ->
analytics.recordException(exception)
trySend(null)
}

trySend(
value
?.toObject(EmployeeShiftDto::class.java)
?.toDomain()
)
}

awaitClose { registration.remove() }
}

override suspend fun upsertShift(
shift: EmployeeShift
): Either<UpsertShiftFailure, EmployeeShift> {
return Either.catch {
store
.collection(FirestoreConfig.COLLECTION_EMPLOYEE_SHIFT)
.document(shift.userUUID.toString())
.set(EmployeeShiftDto.fromDomain(shift))
shift
}.mapLeft { t ->
t.printStackTrace()
analytics.recordException(t)
UnknownFailure(t.message)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import arrow.core.Either
import arrow.core.right
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.lexwilliam.user.repository.UserRepository
import com.lexwilliam.user.source.SessionManager
import com.lexwilliam.user.util.LoginFailure
import com.lexwilliam.user.util.LogoutFailure
Expand All @@ -14,8 +13,7 @@ import kotlinx.coroutines.flow.callbackFlow

fun firebaseSessionManager(
auth: FirebaseAuth,
crashlytics: FirebaseCrashlytics,
userRepository: UserRepository
crashlytics: FirebaseCrashlytics
) = object : SessionManager {
override val sessionDataFlow: Flow<Session> =
callbackFlow {
Expand All @@ -26,12 +24,9 @@ fun firebaseSessionManager(
?.getIdToken(false)
?.addOnSuccessListener {
val userUUID = firebaseAuth.currentUser?.uid
// val userData =
// runBlocking { userUUID?.let { userRepository.fetchUser(it) } }
val session =
Session(
userUUID = userUUID
// branchUUID = userData?.getOrNull()?.branchUUID?.toString()
)
trySend(session)
}
Expand Down
2 changes: 1 addition & 1 deletion domain/branch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion domain/company/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion domain/log/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 24
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
Loading

0 comments on commit 2693ae0

Please sign in to comment.