Skip to content

Commit

Permalink
- Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
MayconCardoso committed Oct 14, 2020
1 parent 1adee89 commit 92db8be
Show file tree
Hide file tree
Showing 171 changed files with 5,507 additions and 5,300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.mctech.stocktradetracking.data.timeline_balance.database.TimelineBala
import com.mctech.stocktradetracking.data.timeline_balance.database.TimelineBalanceDatabaseEntity

@Database(
version = 1,
entities = [
StockShareDatabaseEntity::class,
TimelineBalanceDatabaseEntity::class
]
version = 1,
entities = [
StockShareDatabaseEntity::class,
TimelineBalanceDatabaseEntity::class
]
)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun stockShareDao(): StockShareDao
abstract fun timelineBalanceDao(): TimelineBalanceDao
abstract fun stockShareDao(): StockShareDao
abstract fun timelineBalanceDao(): TimelineBalanceDao
}
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import retrofit2.http.GET
import retrofit2.http.Query

interface StockSharePriceAPI {
@GET("v1/stock")
suspend fun getCurrentStockPrice(
@Query("stockCode") stockCode: String
): StockPriceResponse
@GET("v1/stock")
suspend fun getCurrentStockPrice(
@Query("stockCode") stockCode: String
): StockPriceResponse
}

data class StockPriceResponse(
val price: Double? = null,
val open: Double? = null,
val high: Double? = null,
val low: Double? = null,
val volume: Double? = null,
val previousClose: Double? = null,
val marketChange: Double? = null
val price: Double? = null,
val open: Double? = null,
val high: Double? = null,
val low: Double? = null,
val volume: Double? = null,
val previousClose: Double? = null,
val marketChange: Double? = null
)
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package com.mctech.stocktradetracking.data.stock_share.database
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import java.util.*
import java.util.Date

@Entity(
tableName = "stock_share",
indices = [
Index(
value = ["code"],
name = "index_stock_share_code"
),
Index(
value = ["isPositionOpened"],
name = "index_stock_share_position_closed"
)
]
tableName = "stock_share",
indices = [
Index(
value = ["code"],
name = "index_stock_share_code"
),
Index(
value = ["isPositionOpened"],
name = "index_stock_share_position_closed"
)
]
)
data class StockShareDatabaseEntity(
@PrimaryKey
val id: Long? = null,
val code : String,
val shareAmount : Long,
val purchasePrice : Double,
var salePrice : Double = purchasePrice,
val purchaseDate : Date,
val saleDate : Date? = null,
val isPositionOpened : Boolean = true,
var marketChange : Double?,
var previousClose : Double?
@PrimaryKey
val id: Long? = null,
val code: String,
val shareAmount: Long,
val purchasePrice: Double,
var salePrice: Double = purchasePrice,
val purchaseDate: Date,
val saleDate: Date? = null,
val isPositionOpened: Boolean = true,
var marketChange: Double?,
var previousClose: Double?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import com.mctech.stocktradetracking.domain.stock_share.entity.StockShare
import kotlinx.coroutines.flow.Flow

interface LocalStockShareDataSource {
suspend fun observeStockShareList(): Flow<List<StockShare>>
suspend fun observeStockClosedList(): Flow<List<StockShare>>
suspend fun getMarketStatus(): MarketStatus
suspend fun getDistinctStockCode(): List<String>
suspend fun observeStockShareList(): Flow<List<StockShare>>
suspend fun observeStockClosedList(): Flow<List<StockShare>>
suspend fun getMarketStatus(): MarketStatus
suspend fun getDistinctStockCode(): List<String>

suspend fun saveStockShare(share: StockShare)
suspend fun sellStockShare(share: StockShare)
suspend fun deleteStockShare(share: StockShare)
suspend fun closeStockShare(share: StockShare)
suspend fun editStockShareValue(
shareCode: String,
currentPrice: Double,
marketChange: Double? = null,
previousClose : Double? = null
)
suspend fun saveStockShare(share: StockShare)
suspend fun sellStockShare(share: StockShare)
suspend fun deleteStockShare(share: StockShare)
suspend fun closeStockShare(share: StockShare)
suspend fun editStockShareValue(
shareCode: String,
currentPrice: Double,
marketChange: Double? = null,
previousClose: Double? = null
)

}
Loading

0 comments on commit 92db8be

Please sign in to comment.