diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt index af08ef3..c644e71 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt @@ -39,6 +39,18 @@ class UserController( fun getInfo(): ResponseResult = ResponseResult.databaseSuccess(data = userService.getInfo()) + /** + * Update current user information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "更新当前用户信息") + @PatchMapping("info") + fun updateInfo(@RequestBody @Valid userInfoUpdateParam: UserInfoUpdateParam): ResponseResult = + if (userService.updateInfo(userInfoUpdateParam)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) + else ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_FAILED) + /** * Get user by ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt index c88e333..90e832f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern /** * Verify email parameters @@ -28,6 +29,7 @@ data class VerifyParam( * @since 1.0.0 */ @Schema(description = "昵称", example = "QwQ") + @field:Pattern(regexp = "^.{3,20}$", message = "Nickname must be 3-20 characters") val nickname: String?, /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt new file mode 100644 index 0000000..8a303dc --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt @@ -0,0 +1,32 @@ +package top.fatweb.oxygen.api.param.permission.user + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.Pattern + +/** + * Update user information parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "用户信息更新请求参数") +data class UserInfoUpdateParam( + /** + * Avatar base64 + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "头像") + val avatar: String?, + + /** + * Nickname + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "昵称", example = "QwQ") + @field:Pattern(regexp = "^.{3,20}$", message = "Nickname must be 3-20 characters") + val nickname: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt index 3406bf8..7fb4d8e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt @@ -39,6 +39,14 @@ interface IUserService : IService { */ fun getInfo(): UserWithPowerInfoVo + /** + * Update user information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean + /** * Get one user by ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index c3ad55f..f1e12d9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -84,6 +84,15 @@ class UserServiceImpl( WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo) ?: throw UserNotFoundException() + override fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean { + val userId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() + return userInfoService.update( + KtUpdateWrapper(UserInfo()).eq(UserInfo::userId, userId) + .set(UserInfo::avatar, userInfoUpdateParam.avatar) + .set(UserInfo::nickname, userInfoUpdateParam.nickname) + ) + } + override fun getOne(id: Long): UserWithRoleInfoVo = baseMapper.selectOneWithRoleInfoById(id)?.let(UserConverter::userToUserWithRoleInfoVo) ?: throw UserNotFoundException() diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index 591d72f..fdbb31d 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -152,7 +152,6 @@ tsui.id as user_info_id, tsui.nickname as user_info_nickname, tsui.avatar as user_info_avatar, - tsui.email as user_info_email, tbtb.name as tool_base_name, tbtb.dist_id as tool_base_dist_id, tbtbd.data as tool_base_dist_data, diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index 93192fa..4a6dc96 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -62,7 +62,6 @@ tsui.id as user_info_id, tsui.nickname as user_info_nickname, tsui.avatar as user_info_avatar, - tsui.email as user_info_email, tbtc.id as tool_category_id, tbtc.name as tool_category_name, tbtc.enable as tool_category_enable,