Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cache #20

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8d43411
base navigation
LucasPrioste92 Apr 5, 2024
673aeb2
Merge branch 'feature/splash-screen' into feature/navigation
LucasPrioste92 Apr 5, 2024
907f2ce
update colors background and add scaffold to support bottom bar
LucasPrioste92 Apr 8, 2024
14c67a3
bottom bar
LucasPrioste92 Apr 8, 2024
388f4f2
route with arg symbolId on Detail screen
LucasPrioste92 Apr 8, 2024
398453d
initial setup alpaca API
LucasPrioste92 Apr 8, 2024
3f5ed1f
update dimensions
LucasPrioste92 Apr 8, 2024
51bce36
Merge branch 'feature/navigation' into feature/alpaca-api
LucasPrioste92 Apr 8, 2024
31d797e
update alpaca news service
LucasPrioste92 Apr 10, 2024
739ee01
- refactor alpaca news ws service
LucasPrioste92 Apr 11, 2024
201b4b2
- alpaca news API
LucasPrioste92 Apr 11, 2024
b539b0c
- alpaca news API
LucasPrioste92 Apr 11, 2024
2798774
- setup Unit Test libs
LucasPrioste92 Apr 11, 2024
d26ca4f
- faker dependency
LucasPrioste92 Apr 12, 2024
2b44d41
- unit test (NewsRepository)
LucasPrioste92 Apr 12, 2024
734e555
- unit test (ChangeFilterNews UseCase)
LucasPrioste92 Apr 12, 2024
e487af3
- main carousel news
LucasPrioste92 Apr 17, 2024
84360dd
- main carousel news add anim
LucasPrioste92 Apr 18, 2024
aac9174
- show all news
LucasPrioste92 Apr 19, 2024
0b8c085
- real time news
LucasPrioste92 Apr 22, 2024
80c43b2
- pagination news
LucasPrioste92 Apr 22, 2024
dd409ca
- date picker ui
LucasPrioste92 Apr 24, 2024
3f639fa
- logic to apply filters on VM
LucasPrioste92 Apr 26, 2024
9a765df
- unit test
LucasPrioste92 Apr 29, 2024
fa5c993
- update libs
LucasPrioste92 Apr 29, 2024
232d958
- update symbol crypto
LucasPrioste92 Apr 29, 2024
660586c
- assets API
LucasPrioste92 May 2, 2024
9d0225c
- refactor alpaca data API
LucasPrioste92 May 2, 2024
92f6b79
- trades, quotes, bars info
LucasPrioste92 May 2, 2024
faaf727
- use case to get realtime tardes, quotes and bar
LucasPrioste92 May 6, 2024
0616d85
- unit test MarketRemoteDataSource and AssetRemoteDataSource
LucasPrioste92 May 6, 2024
b6235b6
- unit test AssetsRepository
LucasPrioste92 May 6, 2024
107ed0d
- search input assets
LucasPrioste92 May 8, 2024
5f26ec9
- handle error assets list
LucasPrioste92 May 13, 2024
cda4490
- ui test HomeViewModel
LucasPrioste92 May 13, 2024
378bf20
- header detail screen
LucasPrioste92 May 13, 2024
972655e
- base chart
LucasPrioste92 May 15, 2024
c12e93a
- new version chart
LucasPrioste92 May 20, 2024
40285a7
- update chart
LucasPrioste92 May 21, 2024
9c475d8
- update chart
LucasPrioste92 May 23, 2024
14785b8
- get real time quotes
LucasPrioste92 May 24, 2024
2b2ab02
- get trades
LucasPrioste92 May 28, 2024
2312385
- enabled pull to refresh
LucasPrioste92 May 28, 2024
68d5979
- chart just consume horizontal dragging
LucasPrioste92 May 28, 2024
5253271
- unit test DetailViewModel
LucasPrioste92 May 29, 2024
a85b968
setup room db
LucasPrioste92 May 31, 2024
978cf5c
cache all assets
LucasPrioste92 Jun 4, 2024
90efc9b
cache news and logic to clean cache and retrieve news when the app is…
LucasPrioste92 Jun 12, 2024
cb01fec
update popBackStack to navigateUp
LucasPrioste92 Jun 12, 2024
d2e4719
fix bug when user is offline and data is not being loaded from cache
LucasPrioste92 Jun 12, 2024
c593db9
unit test Assets Cached
LucasPrioste92 Jun 12, 2024
88df26d
unit test News Cached
LucasPrioste92 Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- unit test MarketRemoteDataSource and AssetRemoteDataSource
LucasPrioste92 committed May 6, 2024
commit 0616d856c9010a644b4337c016cb98d422e27d77
Original file line number Diff line number Diff line change
@@ -134,13 +134,14 @@ fun QuoteAssetDto.toQuoteAsset() = QuoteAsset(
id = tradeId,
bidPrice = bidPrice,
askPrice = askPrice,
timeStamp = timeStamp.toLocalDateTimeWithNanoSecond(),
timeStamp = requestDate.toLocalDateTimeWithNanoSecond(),
symbol = symbol,
)

fun QuotesCryptoResponseDto.toQuotesResponseDto() = QuotesResponseDto(
quotes = quotes.entries.first().value,
pageToken = pageToken,
symbol = quotes.entries.first().key,
)

fun TradesResponseDto.toTradesResponse() = TradesResponse(
@@ -151,11 +152,12 @@ fun TradesResponseDto.toTradesResponse() = TradesResponse(
fun TradeAssetDto.toTradeAsset() = TradeAsset(
id = tradeId,
tradePrice = tradePrice,
timeStamp = timeStamp.toLocalDateTimeWithNanoSecond(),
timeStamp = dateTransaction.toLocalDateTimeWithNanoSecond(),
symbol = symbol,
)

fun TradesCryptoResponseDto.toTradesResponseDto() = TradesResponseDto(
trades = trades.entries.first().value,
pageToken = pageToken,
symbol = trades.entries.first().key,
)
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api
import com.google.gson.annotations.SerializedName

data class BarAssetDto(
@SerializedName("T") val type: String? = null,
@SerializedName("c") val closingPrice: Double,
@SerializedName("h") val highPrice: Double,
@SerializedName("l") val lowPrice: Double,
Original file line number Diff line number Diff line change
@@ -3,9 +3,10 @@ package dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api
import com.google.gson.annotations.SerializedName

data class QuoteAssetDto(
@SerializedName("T") val type: String? = null,
@SerializedName("i") val tradeId: Long,
@SerializedName("bp") val bidPrice: Double,
@SerializedName("ap") val askPrice: Double,
@SerializedName("t") val timeStamp: String,
@SerializedName("t") val requestDate: String,
@SerializedName("S") val symbol: String? = null,
)
Original file line number Diff line number Diff line change
@@ -5,4 +5,5 @@ import com.google.gson.annotations.SerializedName
data class QuotesResponseDto(
val quotes: List<QuoteAssetDto>,
@SerializedName("next_page_token") val pageToken: String? = null,
val symbol: String,
)
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@ package dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api
import com.google.gson.annotations.SerializedName

data class TradeAssetDto(
@SerializedName("T") val type: String? = null,
@SerializedName("i") val tradeId: Long,
@SerializedName("p") val tradePrice: Double,
@SerializedName("t") val timeStamp: String,
@SerializedName("t") val dateTransaction: String,
@SerializedName("S") val symbol: String? = null,
)
Original file line number Diff line number Diff line change
@@ -5,4 +5,5 @@ import com.google.gson.annotations.SerializedName
data class TradesResponseDto(
val trades: List<TradeAssetDto>,
@SerializedName("next_page_token") val pageToken: String? = null,
val symbol: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.pinkroom.marketsight.data.data_source

import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import dev.pinkroom.marketsight.data.remote.AlpacaPaperApi
import dev.pinkroom.marketsight.domain.model.assets.TypeAsset
import dev.pinkroom.marketsight.factories.AssetDtoFactory
import dev.pinkroom.marketsight.util.MainCoroutineRule
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test

@OptIn(ExperimentalCoroutinesApi::class)
class AssetsRemoteDataSourceTest{
@get:Rule
val coroutineRule = MainCoroutineRule()

private val assetDtoFactory = AssetDtoFactory()
private val alpacaPaperApi = mockk<AlpacaPaperApi>()
private val assetsRemoteDataSource = AssetsRemoteDataSource(
alpacaPaperApi = alpacaPaperApi
)

@Test
fun `When call getAllAssets, Then return list of assets`() = runTest {
// GIVEN
val type = TypeAsset.Stock
mockResponseGetAssetsPaperApi(typeAsset = type)

// WHEN
val response = assetsRemoteDataSource.getAllAssets(typeAsset = type)

// THEN
coVerify { alpacaPaperApi.getAssets(typeAsset = type.value, status = any()) }
assertThat(response).isNotEmpty()
response.forEach {
assertThat(it.type).isEqualTo(type.value)
}
}

private fun mockResponseGetAssetsPaperApi(
typeAsset: TypeAsset,
){
coEvery {
alpacaPaperApi.getAssets(typeAsset = any(), status = any())
}.returns(
assetDtoFactory.listAssets(number = 250, type = typeAsset)
)
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.pinkroom.marketsight.factories

import com.github.javafaker.Faker
import dev.pinkroom.marketsight.data.remote.model.dto.alpaca_paper_api.AssetDto
import dev.pinkroom.marketsight.domain.model.assets.TypeAsset
import kotlin.random.Random

class AssetDtoFactory: BaseFactory<AssetDto> {

private val faker = Faker()
override fun build() = AssetDto(
id = faker.number().randomNumber().toString(),
type = if (Random.nextInt() % 2 == 0) "us_equity" else "crypto",
symbol = faker.stock().nsdqSymbol(),
name = faker.stock().nsdqSymbol(),
exchange = "NASDAQ",
)

fun listAssets(number: Int, type: TypeAsset) = List(number) { build(type = type) }

private fun build(type: TypeAsset) = AssetDto(
id = faker.number().randomNumber().toString(),
type = type.value,
symbol = faker.stock().nsdqSymbol(),
name = faker.stock().nsdqSymbol(),
exchange = "NASDAQ",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.pinkroom.marketsight.factories

import com.github.javafaker.Faker
import dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api.BarAssetDto

class BarAssetDtoFactory: BaseFactory<BarAssetDto> {

private val faker = Faker()
override fun build() = BarAssetDto(
tradeCountInBar = faker.number().randomDigit(),
barVolume = faker.number().randomDouble(10,1,1000),
timestamp = "2024-04-11T13:45:17.0231232021Z",
lowPrice = faker.number().randomDouble(10,1,1000),
highPrice = faker.number().randomDouble(10,1,1000),
closingPrice = faker.number().randomDouble(10,1,1000),
openingPrice = faker.number().randomDouble(10,1,1000),
volumeWeightedAvgPrice = faker.number().randomDouble(10,1,1000),
)

fun buildList(number: Int, symbol: String, type: String? = null) = List(number){
build().copy(symbol = symbol, type = type)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.pinkroom.marketsight.factories

import com.github.javafaker.Faker
import dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api.QuoteAssetDto
import kotlin.random.Random

class QuoteAssetDtoFactory: BaseFactory<QuoteAssetDto> {

private val faker = Faker()
override fun build() = QuoteAssetDto(
type = if (Random.nextInt() % 2 == 0) "us_equity" else "crypto",
tradeId = faker.number().randomNumber(),
bidPrice = faker.number().randomDouble(100,1,1000000),
askPrice = faker.number().randomDouble(100,1,1000000),
requestDate = "2024-05-03T16:58:38.422833437Z",
)

fun buildList(number: Int, type: String? = null, symbol: String? = null) = List(number) {
build().copy(type = type, symbol = symbol)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.pinkroom.marketsight.factories

import com.github.javafaker.Faker
import dev.pinkroom.marketsight.data.remote.model.dto.alpaca_api.TradeAssetDto
import kotlin.random.Random

class TradeAssetDtoFactory: BaseFactory<TradeAssetDto> {

private val faker = Faker()
override fun build() = TradeAssetDto(
type = if (Random.nextInt() % 2 == 0) "us_equity" else "crypto",
tradePrice = faker.number().randomDouble(1000,1,10000000),
tradeId = faker.number().randomNumber(),
dateTransaction = "2024-05-03T16:58:38.422833437Z",
)

fun buildList(number: Int, type: String? = null, symbol: String? = null) = List(number) {
build().copy(type = type, symbol = symbol)
}
}