From aede04ab0134c18fda8f022d2e7c00826b3f37b0 Mon Sep 17 00:00:00 2001 From: Leonel Zalegas Date: Wed, 17 Jul 2024 21:57:45 -0300 Subject: [PATCH] -DataBase Created -added internet permissions -added more dependencies -added retrofit client -added mappers --- app/.gitignore | 3 ++- app/build.gradle.kts | 9 +++++++ app/src/main/AndroidManifest.xml | 2 ++ .../Domain/model/CompanyListing.kt | 7 ++++++ .../data/local/CompanyListingEntity.kt | 12 +++++++++ .../mainFeature/data/local/StockDao.kt | 25 +++++++++++++++++++ .../mainFeature/data/local/StockDatabase.kt | 11 ++++++++ .../mainFeature/data/mapper/CompanyMapper.kt | 20 +++++++++++++++ .../mainFeature/data/remote/StockClient.kt | 13 ++++++++++ gradle/libs.versions.toml | 9 +++++++ 10 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/Domain/model/CompanyListing.kt create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/CompanyListingEntity.kt create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/StockDao.kt create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/StockDatabase.kt create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/data/mapper/CompanyMapper.kt create mode 100644 app/src/main/java/com/example/stockmarketcheck/mainFeature/data/remote/StockClient.kt diff --git a/app/.gitignore b/app/.gitignore index 42afabf..4b7fa2b 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ -/build \ No newline at end of file +/build +Config.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b8450f4..8763e9d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -117,4 +117,13 @@ dependencies { // OkHttp implementation(libs.okhttp3.okhttp) implementation(libs.okhttp3.logging.interceptor) + + // compose + implementation(libs.androidx.lifecycle.viewmodel.compose) + implementation(libs.androidx.material.icons.extended) + implementation(libs.androidx.material) + + // Kotlin Coroutines + implementation(libs.kotlinx.coroutines.core) + implementation(libs.kotlinx.coroutines.android) } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index de40e6a..d02c352 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + ) + + @Query("DELETE FROM companylistingentity") + suspend fun clearCompanyListings() + + @Query( + """ + SELECT * + FROM companylistingentity + WHERE LOWER(name) LIKE '%' || LOWER(:query) || '%' OR + UPPER(:query) == symbol + """, + ) + suspend fun searchCompanyListings(query: String): List +} \ No newline at end of file diff --git a/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/StockDatabase.kt b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/StockDatabase.kt new file mode 100644 index 0000000..799d955 --- /dev/null +++ b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/local/StockDatabase.kt @@ -0,0 +1,11 @@ +package com.example.stockmarketcheck.mainFeature.data.local + +import androidx.room.Database + +@Database( + entities = [CompanyListingEntity::class], + version = 1, +) +abstract class StockDatabase { + abstract val dao: StockDao +} \ No newline at end of file diff --git a/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/mapper/CompanyMapper.kt b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/mapper/CompanyMapper.kt new file mode 100644 index 0000000..baf19ea --- /dev/null +++ b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/mapper/CompanyMapper.kt @@ -0,0 +1,20 @@ +package com.example.stockmarketcheck.mainFeature.data.mapper + +import com.example.stockmarketcheck.mainFeature.Domain.model.CompanyListing +import com.example.stockmarketcheck.mainFeature.data.local.CompanyListingEntity + +fun CompanyListingEntity.toCompanyListing(): CompanyListing { + return CompanyListing( + name = name, + symbol = symbol, + exchange = exchange, + ) +} + +fun CompanyListing.toCompanyListingEntity(): CompanyListingEntity { + return CompanyListingEntity( + name = name, + symbol = symbol, + exchange = exchange, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/remote/StockClient.kt b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/remote/StockClient.kt new file mode 100644 index 0000000..188cd51 --- /dev/null +++ b/app/src/main/java/com/example/stockmarketcheck/mainFeature/data/remote/StockClient.kt @@ -0,0 +1,13 @@ +package com.example.stockmarketcheck.mainFeature.data.remote + +import com.example.stockmarketcheck.Config +import okhttp3.ResponseBody +import retrofit2.http.GET +import retrofit2.http.Query + +interface StockClient { + @GET("query?function=LISTING_STATUS") + suspend fun getListings( + @Query("apikey") apikey: String = Config.API_KEY, + ): ResponseBody +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 24f82cd..b8b5149 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,10 +5,14 @@ coreKtx = "1.13.1" junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" +kotlinxCoroutinesAndroid = "1.7.3" +kotlinxCoroutinesCore = "1.7.3" lifecycleRuntimeKtx = "2.8.3" activityCompose = "1.9.0" composeBom = "2024.04.01" composeNavigation = "2.8.0-beta05" +material = "1.6.8" +materialIconsExtended = "" moshiKotlin = "1.15.0" moshiKotlinCodegen = "1.15.0" okHttpVersion = "4.12.0" @@ -23,6 +27,9 @@ hiltLifecycleViewmodel = "1.0.0-alpha03" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleRuntimeKtx" } +androidx-material = { module = "androidx.compose.material:material", version.ref = "material" } +androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" } androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomRuntime" } androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomRuntime" } androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomRuntime" } @@ -40,6 +47,8 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" } +kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutinesAndroid" } +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" } moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshiKotlin" } moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshiKotlinCodegen" } navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "composeNavigation" }