-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1adee89
commit 92db8be
Showing
171 changed files
with
5,507 additions
and
5,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
data/src/main/java/com/mctech/stocktradetracking/data/database/Converters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package com.mctech.stocktradetracking.data.database | ||
|
||
import androidx.room.TypeConverter | ||
import java.util.* | ||
import java.util.Date | ||
|
||
class Converters { | ||
@TypeConverter | ||
fun fromTimestamp(value: Long?): Date? { | ||
return value?.let { Date(it) } | ||
} | ||
@TypeConverter | ||
fun fromTimestamp(value: Long?): Date? { | ||
return value?.let { Date(it) } | ||
} | ||
|
||
@TypeConverter | ||
fun dateToTimestamp(date: Date?): Long? { | ||
return date?.time | ||
} | ||
@TypeConverter | ||
fun dateToTimestamp(date: Date?): Long? { | ||
return date?.time | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 50 additions & 45 deletions
95
data/src/main/java/com/mctech/stocktradetracking/data/stock_share/database/StockShareDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
package com.mctech.stocktradetracking.data.stock_share.database | ||
|
||
import androidx.room.* | ||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import com.mctech.stocktradetracking.domain.stock_share.entity.StockShare | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface StockShareDao { | ||
// ============================================================================ | ||
// Realtime | ||
// ============================================================================ | ||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 1 ORDER BY code") | ||
fun observeAllOpenedPosition(): Flow<List<StockShare>> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 0 ORDER BY code") | ||
fun observeStockClosedList(): Flow<List<StockShare>> | ||
|
||
|
||
// ============================================================================ | ||
// Single shot | ||
// ============================================================================ | ||
@Transaction | ||
@Query("SELECT DISTINCT code FROM stock_share WHERE isPositionOpened = 1") | ||
suspend fun loadDistinctStockCodes(): List<String> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 1 AND code = :code LIMIT 1") | ||
suspend fun loadStockSharePosition(code: String): StockShare? | ||
|
||
@Transaction | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun save(stockShare: StockShareDatabaseEntity) | ||
|
||
@Transaction | ||
@Delete | ||
suspend fun delete(stockShare: StockShareDatabaseEntity) | ||
|
||
@Query("UPDATE stock_share SET salePrice = :currentPrice WHERE code = :code AND isPositionOpened = 1 ") | ||
suspend fun editStockSharePriceManually(code: String, currentPrice: Double) | ||
|
||
@Query("UPDATE stock_share SET isPositionOpened = 0, salePrice = :salePrice WHERE id = :id") | ||
suspend fun closeStockShare(id: Long, salePrice : Double) | ||
|
||
@Query("UPDATE stock_share SET salePrice = :currentPrice, previousClose = :previousClose, marketChange = :marketChange WHERE code = :code AND isPositionOpened = 1") | ||
suspend fun editStockSharePriceAutomatically( | ||
code: String, | ||
currentPrice: Double, | ||
marketChange: Double, | ||
previousClose: Double | ||
) | ||
// ============================================================================ | ||
// Realtime | ||
// ============================================================================ | ||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 1 ORDER BY code") | ||
fun observeAllOpenedPosition(): Flow<List<StockShare>> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 0 ORDER BY code") | ||
fun observeStockClosedList(): Flow<List<StockShare>> | ||
|
||
|
||
// ============================================================================ | ||
// Single shot | ||
// ============================================================================ | ||
@Transaction | ||
@Query("SELECT DISTINCT code FROM stock_share WHERE isPositionOpened = 1") | ||
suspend fun loadDistinctStockCodes(): List<String> | ||
|
||
@Transaction | ||
@Query("SELECT * FROM stock_share WHERE isPositionOpened = 1 AND code = :code LIMIT 1") | ||
suspend fun loadStockSharePosition(code: String): StockShare? | ||
|
||
@Transaction | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun save(stockShare: StockShareDatabaseEntity) | ||
|
||
@Transaction | ||
@Delete | ||
suspend fun delete(stockShare: StockShareDatabaseEntity) | ||
|
||
@Query("UPDATE stock_share SET salePrice = :currentPrice WHERE code = :code AND isPositionOpened = 1 ") | ||
suspend fun editStockSharePriceManually(code: String, currentPrice: Double) | ||
|
||
@Query("UPDATE stock_share SET isPositionOpened = 0, salePrice = :salePrice WHERE id = :id") | ||
suspend fun closeStockShare(id: Long, salePrice: Double) | ||
|
||
@Query("UPDATE stock_share SET salePrice = :currentPrice, previousClose = :previousClose, marketChange = :marketChange WHERE code = :code AND isPositionOpened = 1") | ||
suspend fun editStockSharePriceAutomatically( | ||
code: String, | ||
currentPrice: Double, | ||
marketChange: Double, | ||
previousClose: Double | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.