Skip to content

Commit

Permalink
WTA #71: Updated models.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Dec 23, 2022
1 parent ef051e1 commit c35dca0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .idea/runConfigurations/All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jacob.wakatimeapp.core.models

@Deprecated("Too vague, totalTime and range properties can be derived from dailyStats property")
data class Stats(
val totalTime: Time,
val dailyStats: List<DailyStats>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.jacob.wakatimeapp.core.models

import kotlinx.datetime.LocalDate
import kotlinx.datetime.toLocalDateTime
import kotlinx.serialization.Serializable

@Serializable
data class StatsRange(
val startDate: LocalDate,
val endDate: LocalDate,
)
) {
constructor(startDate: String, endDate: String) : this(
startDate = startDate.toLocalDateTime().date,
endDate = endDate.toLocalDateTime().date,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jacob.wakatimeapp.details.domain.models

import com.jacob.wakatimeapp.core.models.StatsRange
import com.jacob.wakatimeapp.core.models.Time
import kotlinx.datetime.LocalDate

data class ProjectStats(
val totalTime: Time,
val dailyProjectStats: Map<LocalDate, Time>,
val range: StatsRange,
val languages: List<String>,
val operatingSystems: List<String>,
val editors: List<String>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import kotlinx.datetime.toLocalDate
fun GetStatsForRangeResDTO.toModel() = Stats(
totalTime = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal),
dailyStats = getDailyStatsFromDto(data),
range = StatsRange(
startDate = start.takeWhile { it != 'T' }
.toLocalDate(),
endDate = end.takeWhile { it != 'T' }
.toLocalDate(),
),
range = StatsRange(startDate = start, endDate = end),
)

private fun getDailyStatsFromDto(data: List<Data>) = data.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import kotlinx.datetime.toLocalDate
fun GetLast7DaysStatsResDTO.toModel() = WeeklyStats(
totalTime = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal),
dailyStats = getDailyStatsFromDto(data),
range = StatsRange(
startDate = start.takeWhile { it != 'T' }.toLocalDate(),
endDate = end.takeWhile { it != 'T' }.toLocalDate(),
),
range = StatsRange(startDate = start, endDate = end),
)

private fun getDailyStatsFromDto(data: List<Data>) = data.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jacob.wakatimeapp.login.data.mappers // ktlint-disable filename

import com.jacob.wakatimeapp.core.models.UserDetails
import com.jacob.wakatimeapp.login.data.dtos.GetUserDetailsResDTO
import kotlinx.datetime.toLocalDate
import kotlinx.datetime.toLocalDateTime

fun GetUserDetailsResDTO.toModel() = UserDetails(
bio = data.bio,
Expand All @@ -15,7 +15,7 @@ fun GetUserDetailsResDTO.toModel() = UserDetails(
lastProject = data.lastProject,
fullName = data.fullName,
durationsSliceBy = data.durationsSliceBy,
createdAt = data.createdAt.takeWhile { it != 'T' }.toLocalDate(),
createdAt = data.createdAt.toLocalDateTime().date,
dateFormat = data.dateFormat,
photoUrl = "${data.photoUrl}?s=420",
)

0 comments on commit c35dca0

Please sign in to comment.