TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/AlejoTaller/llms.txt
Use this file to discover all available pages before exploring further.
shared-sale module is the single source of truth for all sale-related business logic across AlejoTaller’s Android surfaces. Both the customer app (app) and the operator scanner (alejotallerscan) depend on this library so that sale creation, local persistence, remote synchronization, and realtime Appwrite event handling are never implemented twice. Concrete infrastructure (Room DAOs, Appwrite Databases calls, Pusher gateway) lives in shared-data; shared-sale exposes only pure domain entities, use cases, and repository/realtime contracts.
What It Exports
| Layer | Contents |
|---|---|
| Domain entities | Sale, SaleItem, PaymentChannel, BuyState, DeliveryType, Currency, DeliveryAddress |
| Use cases | 8 use cases covering creation, observation, sync, realtime, and delivery |
| Repository contracts | SaleRepository, SaleIdProvider, SaleNotificationUserProvider, TelegramNotificator, RealtimeSyncGateway |
| DI | SharedSaleFeatureModule (Koin anchor object) |
Domain Entities
Sale
The root aggregate. Every field that varies at runtime — verification state, delivery preference, address — is modelled as an optional or enum so the entity remains valid across all lifecycle stages.
Sale
DeliveryAddress captures full Cuban addressing data and is JSON-serialized when persisted to Room or Appwrite:
SaleItem
A single line item within a sale. Both productId and quantity are validated eagerly in init.
PaymentChannel
Enumerates the two accepted electronic payment rails in the Cuban market.
BuyState Lifecycle
A sale moves through the following states driven by operator confirmations arriving via Appwrite realtime events:UpdateSaleVerificationFromRealtimeCaseUse is the only place this transition is written; it guards against redundant saves by comparing the current state before persisting.
Use Cases
All use cases follow the Kotlinoperator fun invoke convention.
RegisterNewSaleCauseUse
Creates a new sale by assigning a unique ID, sending a Telegram notification to the current user, and persisting to the repository. The flow fails fast if the current user cannot be resolved.
Result<String> containing the new sale’s ID.
ObserveAllSalesCaseUse
Wraps the SaleRepository.observeAll() cold Flow so ViewModels never import repository types directly.
GetSalesByIdCaseUse
Fetches a single sale by its string ID. Returns Result.failure if the sale is not found locally.
UpdateDeliveryTypeCaseUse
Updates the deliveryType field on an existing sale after reading the current record. Accepts either DeliveryType.PICKUP or DeliveryType.DELIVERY.
SyncSalesCaseUse
Delegates a full offline-to-remote sync for a given userId to the repository. The heavy reconciliation logic (pending queue resolution, retry with back-off) lives in SaleOfflineFirstRepository inside shared-data.
SubscribeRealtimeSyncCaseUse
Opens a Pusher/Appwrite realtime subscription for the given user. Exposes four callbacks so callers can react to connection state, sale events, and promotional pushes independently.
InterpretSaleRealtimeEventCaseUse
Parses an incoming SaleRealtimeEvent and converts it into a list of SaleRealtimeCommand actions (in-app message + push notification). Returns an empty list if the event is missing a saleId or userId.
UpdateSaleVerificationFromRealtimeCaseUse
Applies the verification outcome from a realtime event to the local repository. Reads the current sale, maps isSuccess to BuyState.VERIFIED or BuyState.DELETED, and only persists if the state actually changes.
Koin DI Module
SharedSaleFeatureModule is a Kotlin object that serves as a logical grouping anchor for Koin bindings in each consuming app module.
SaleOfflineFirstRepository, SaleNetRepositoryImpl, RealtimeSyncGateway, and all use-case classes — are declared in the :app or :alejotallerscan DI modules so each surface supplies its own Appwrite client and Room database instances.
Adding to a Gradle Module
shared-sale is an Android library. Add it as an implementation dependency in any Android module’s build.gradle.kts:
shared-sale depends transitively on project(":shared-core") and project(":shared-auth"), as well as the Appwrite SDK, Ktor, Pusher, and kotlinx-datetime. These are brought in automatically. The module requires minSdk = 26 and compiles against SDK 36 with Java 17 source compatibility.