Add update user info api
This commit is contained in:
@@ -39,6 +39,18 @@ class UserController(
|
|||||||
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
|
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
|
||||||
ResponseResult.databaseSuccess(data = userService.getInfo())
|
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<Nothing> =
|
||||||
|
if (userService.updateInfo(userInfoUpdateParam)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||||
|
else ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_FAILED)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user by ID
|
* Get user by ID
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.permission
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import jakarta.validation.constraints.NotBlank
|
import jakarta.validation.constraints.NotBlank
|
||||||
|
import jakarta.validation.constraints.Pattern
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify email parameters
|
* Verify email parameters
|
||||||
@@ -28,6 +29,7 @@ data class VerifyParam(
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Schema(description = "昵称", example = "QwQ")
|
@Schema(description = "昵称", example = "QwQ")
|
||||||
|
@field:Pattern(regexp = "^.{3,20}$", message = "Nickname must be 3-20 characters")
|
||||||
val nickname: String?,
|
val nickname: String?,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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?
|
||||||
|
)
|
||||||
@@ -39,6 +39,14 @@ interface IUserService : IService<User> {
|
|||||||
*/
|
*/
|
||||||
fun getInfo(): UserWithPowerInfoVo
|
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
|
* Get one user by ID
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -84,6 +84,15 @@ class UserServiceImpl(
|
|||||||
WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo)
|
WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo)
|
||||||
?: throw UserNotFoundException()
|
?: 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 =
|
override fun getOne(id: Long): UserWithRoleInfoVo =
|
||||||
baseMapper.selectOneWithRoleInfoById(id)?.let(UserConverter::userToUserWithRoleInfoVo)
|
baseMapper.selectOneWithRoleInfoById(id)?.let(UserConverter::userToUserWithRoleInfoVo)
|
||||||
?: throw UserNotFoundException()
|
?: throw UserNotFoundException()
|
||||||
|
|||||||
@@ -152,7 +152,6 @@
|
|||||||
tsui.id as user_info_id,
|
tsui.id as user_info_id,
|
||||||
tsui.nickname as user_info_nickname,
|
tsui.nickname as user_info_nickname,
|
||||||
tsui.avatar as user_info_avatar,
|
tsui.avatar as user_info_avatar,
|
||||||
tsui.email as user_info_email,
|
|
||||||
tbtb.name as tool_base_name,
|
tbtb.name as tool_base_name,
|
||||||
tbtb.dist_id as tool_base_dist_id,
|
tbtb.dist_id as tool_base_dist_id,
|
||||||
tbtbd.data as tool_base_dist_data,
|
tbtbd.data as tool_base_dist_data,
|
||||||
|
|||||||
@@ -62,7 +62,6 @@
|
|||||||
tsui.id as user_info_id,
|
tsui.id as user_info_id,
|
||||||
tsui.nickname as user_info_nickname,
|
tsui.nickname as user_info_nickname,
|
||||||
tsui.avatar as user_info_avatar,
|
tsui.avatar as user_info_avatar,
|
||||||
tsui.email as user_info_email,
|
|
||||||
tbtc.id as tool_category_id,
|
tbtc.id as tool_category_id,
|
||||||
tbtc.name as tool_category_name,
|
tbtc.name as tool_category_name,
|
||||||
tbtc.enable as tool_category_enable,
|
tbtc.enable as tool_category_enable,
|
||||||
|
|||||||
Reference in New Issue
Block a user