Add update user info api
This commit is contained in:
@@ -39,6 +39,18 @@ class UserController(
|
||||
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
|
||||
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
|
||||
*
|
||||
|
||||
@@ -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?,
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
* Update user information
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean
|
||||
|
||||
/**
|
||||
* Get one user by ID
|
||||
*
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user