Skip to content

Commit

Permalink
-DataBase Created
Browse files Browse the repository at this point in the history
-added internet permissions
-added more dependencies
-added retrofit client
-added mappers
  • Loading branch information
LeonelZalegas committed Jul 18, 2024
1 parent f5a9597 commit aede04a
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
Config.kt
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.stockmarketcheck.mainFeature.Domain.model

data class CompanyListing(
val name: String,
val symbol: String,
val exchange: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.stockmarketcheck.mainFeature.data.local

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class CompanyListingEntity(
val name: String,
val symbol: String,
val exchange: String,
@PrimaryKey val id: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.stockmarketcheck.mainFeature.data.local

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface StockDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCompanyListings(companyListingEntities: List<CompanyListingEntity>)

@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<CompanyListingEntity>
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<latest_compose_version>"
moshiKotlin = "1.15.0"
moshiKotlinCodegen = "1.15.0"
okHttpVersion = "4.12.0"
Expand All @@ -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" }
Expand All @@ -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" }
Expand Down

0 comments on commit aede04a

Please sign in to comment.