Skip to content

Commit

Permalink
feat(UserVO.kt): add albumCount and allSize fields to UserVO to provi…
Browse files Browse the repository at this point in the history
…de more detailed user data

refactor(UserVO.kt, UserPageVO.kt): change totalImageSize type from Long to Double for precision

perf(UserDaoImpl.kt): convert totalImageSize from bytes to megabytes

feat(UserServiceImpl.kt): calculate albumCount and allSize for more comprehensive user metrics
  • Loading branch information
ShiinaKin committed Oct 28, 2024
1 parent 25b02de commit 6874d99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/src/main/kotlin/io/sakurasou/controller/vo/UserVO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ data class UserVO(
val isBanned: Boolean,
val createTime: LocalDateTime,
val imageCount: Long,
val totalImageSize: Long
val albumCount: Long,
val totalImageSize: Double,
val allSize: Double
)

@Serializable
Expand All @@ -31,5 +33,5 @@ data class UserPageVO(
val isBanned: Boolean,
val createTime: LocalDateTime,
val imageCount: Long,
val totalImageSize: Long
val totalImageSize: Double
)
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class UserDaoImpl : UserDao {
isBanned = it[Users.isBanned],
createTime = it[Users.createTime],
imageCount = it[Images.id.count()],
totalImageSize = it[Images.size.sum()] ?: 0
totalImageSize = it[Images.size.sum()]?.let { size -> size / 1024 / 1024.0 } ?: 0.0
)
}.toList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class UserServiceImpl(
return dbQuery {
val user = userDao.findUserById(id) ?: throw UserNotFoundException()
val group = groupDao.findGroupById(user.groupId)!!
val albumCount = albumDao.countAlbumByUserId(id)
val (count, totalSize) = imageDao.getImageCountAndTotalSizeOfUser(id)
UserVO(
id = user.id,
Expand All @@ -213,7 +214,9 @@ class UserServiceImpl(
isBanned = user.isBanned,
createTime = user.createTime,
imageCount = count,
totalImageSize = totalSize
albumCount = albumCount,
totalImageSize = totalSize / 1024 / 1024.0,
allSize = group.config.groupStrategyConfig.maxSize / 1024 / 1024.0,
)
}
}
Expand Down

0 comments on commit 6874d99

Please sign in to comment.