From b050d19b2b929496190afbcffcae6341610a5323 Mon Sep 17 00:00:00 2001 From: Shiina Kin Date: Mon, 25 Nov 2024 20:56:48 +0800 Subject: [PATCH] refactor: change email field in UserVO to non-nullable and add albumCount to UserPageVO --- app/openapi/openapi.json | 10 +++++++--- .../main/kotlin/io/sakurasou/controller/vo/UserVO.kt | 3 ++- .../kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt | 7 +++++-- .../main/kotlin/io/sakurasou/model/dao/user/Users.kt | 5 +---- ui/packages/api-client/src/models/user-page-vo.ts | 6 ++++++ ui/packages/api-client/src/models/user-vo.ts | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/openapi/openapi.json b/app/openapi/openapi.json index 429bc684..ecc34e99 100644 --- a/app/openapi/openapi.json +++ b/app/openapi/openapi.json @@ -3778,7 +3778,7 @@ "type" : "string" }, "email" : { - "type" : [ "null", "string" ] + "type" : "string" }, "groupName" : { "type" : "string" @@ -3805,7 +3805,7 @@ "type" : "string" } }, - "required" : [ "albumCount", "allSize", "createTime", "groupName", "id", "imageCount", "isBanned", "isDefaultImagePrivate", "totalImageSize", "username" ] + "required" : [ "albumCount", "allSize", "createTime", "email", "groupName", "id", "imageCount", "isBanned", "isDefaultImagePrivate", "totalImageSize", "username" ] }, "CommonResponse_UserVO" : { "type" : "object", @@ -3905,6 +3905,10 @@ "UserPageVO" : { "type" : "object", "properties" : { + "albumCount" : { + "type" : "integer", + "format" : "int64" + }, "createTime" : { "type" : "string" }, @@ -3930,7 +3934,7 @@ "type" : "string" } }, - "required" : [ "createTime", "groupName", "id", "imageCount", "isBanned", "totalImageSize", "username" ] + "required" : [ "albumCount", "createTime", "groupName", "id", "imageCount", "isBanned", "totalImageSize", "username" ] }, "CommonResponse_PageResult_UserPageVO" : { "type" : "object", diff --git a/app/src/main/kotlin/io/sakurasou/controller/vo/UserVO.kt b/app/src/main/kotlin/io/sakurasou/controller/vo/UserVO.kt index 5e447697..d3b927f3 100644 --- a/app/src/main/kotlin/io/sakurasou/controller/vo/UserVO.kt +++ b/app/src/main/kotlin/io/sakurasou/controller/vo/UserVO.kt @@ -14,7 +14,7 @@ data class UserVO( val id: Long, val username: String, val groupName: String, - val email: String?, + val email: String, val isDefaultImagePrivate: Boolean, val isBanned: Boolean, val createTime: LocalDateTime, @@ -33,5 +33,6 @@ data class UserPageVO( val isBanned: Boolean, val createTime: LocalDateTime, val imageCount: Long, + val albumCount: Long, val totalImageSize: Double ) \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt b/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt index ac841183..9c25d72f 100644 --- a/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt @@ -3,6 +3,7 @@ package io.sakurasou.model.dao.user import io.sakurasou.controller.request.PageRequest import io.sakurasou.controller.vo.PageResult import io.sakurasou.controller.vo.UserPageVO +import io.sakurasou.model.dao.album.Albums import io.sakurasou.model.dao.group.Groups import io.sakurasou.model.dao.image.Images import io.sakurasou.model.dto.UserInsertDTO @@ -92,10 +93,11 @@ class UserDaoImpl : UserDao { query .adjustColumnSet { innerJoin(Groups) { Users.groupId eq Groups.id } + .leftJoin(Albums) { Users.id eq Albums.userId } .leftJoin(Images) { Users.id eq Images.userId } } - .adjustSelect { select(Users.fields + Groups.name + Images.id.count() + Images.size.sum()) } - .groupBy(Users.id, Users.name, Users.isBanned, Groups.name) + .adjustSelect { select(Users.fields + Groups.name + Albums.id.count() + Images.id.count() + Images.size.sum()) } + .groupBy(Users.id, Users.name, Users.isBanned, Groups.name, Users.createTime) .also { pageRequest.additionalCondition?.let { map -> map["isBanned"]?.let { isBanned -> @@ -115,6 +117,7 @@ class UserDaoImpl : UserDao { isBanned = it[Users.isBanned], createTime = it[Users.createTime], imageCount = it[Images.id.count()], + albumCount = it[Albums.id.count()], totalImageSize = it[Images.size.sum()]?.let { size -> if (size != 0L) size / 1024 / 1024.0 else 0.0 } ?: 0.0 diff --git a/app/src/main/kotlin/io/sakurasou/model/dao/user/Users.kt b/app/src/main/kotlin/io/sakurasou/model/dao/user/Users.kt index e642452a..50552d62 100644 --- a/app/src/main/kotlin/io/sakurasou/model/dao/user/Users.kt +++ b/app/src/main/kotlin/io/sakurasou/model/dao/user/Users.kt @@ -29,12 +29,9 @@ object Users : LongIdTable("users") { } val columnMap = mapOf( - "id" to Users.id, - "name" to Users.name, - "isBanned" to Users.isBanned, - "groupName" to Groups.name, "createTime" to Users.createTime, "imageCount" to Images.id.count(), + "albumCount" to Albums.id.count(), "totalImageSize" to Images.size.sum() ) } \ No newline at end of file diff --git a/ui/packages/api-client/src/models/user-page-vo.ts b/ui/packages/api-client/src/models/user-page-vo.ts index f5bd29c6..eda37edd 100644 --- a/ui/packages/api-client/src/models/user-page-vo.ts +++ b/ui/packages/api-client/src/models/user-page-vo.ts @@ -20,6 +20,12 @@ * @interface UserPageVO */ export interface UserPageVO { + /** + * + * @type {number} + * @memberof UserPageVO + */ + 'albumCount': number; /** * * @type {string} diff --git a/ui/packages/api-client/src/models/user-vo.ts b/ui/packages/api-client/src/models/user-vo.ts index e52a5a9c..8aac2eb0 100644 --- a/ui/packages/api-client/src/models/user-vo.ts +++ b/ui/packages/api-client/src/models/user-vo.ts @@ -43,7 +43,7 @@ export interface UserVO { * @type {string} * @memberof UserVO */ - 'email'?: string | null; + 'email': string; /** * * @type {string}