Add developer profile api

This commit is contained in:
2024-02-23 11:01:03 +08:00
parent d38f9f4a58
commit 3c82107394
11 changed files with 149 additions and 7 deletions

View File

@@ -80,7 +80,7 @@ class SecurityConfig(
"/forget",
"/retrieve"
).anonymous()
.requestMatchers("/tool/detail/**", "/tool/store").permitAll()
.requestMatchers("/tool/detail/**", "/tool/store", "/tool/store/*", "/system/user/info/*").permitAll()
// Authentication required
.anyRequest().authenticated()
}

View File

@@ -10,6 +10,7 @@ import top.fatweb.oxygen.api.entity.common.ResponseResult
import top.fatweb.oxygen.api.param.permission.user.*
import top.fatweb.oxygen.api.service.permission.IUserService
import top.fatweb.oxygen.api.vo.PageVo
import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo
@@ -35,15 +36,34 @@ class UserController(
* @see UserWithPowerInfoVo
*/
@Operation(summary = "获取当前用户信息")
@GetMapping("info")
@GetMapping("/info")
fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
ResponseResult.databaseSuccess(data = userService.getInfo())
/**
* Get basic user information
*
* @param username Username
* @return Response object includes user basic information
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see ResponseResult
* @see UserWithPowerInfoVo
*/
@Operation(summary = "获取指定用户基本信息")
@GetMapping("/info/{username}")
fun getBasicInfo(@PathVariable username: String): ResponseResult<UserWithInfoVo> =
ResponseResult.databaseSuccess(data = userService.getBasicInfo(username))
/**
* Update current user information
*
* @param userInfoUpdateParam Update user information parameters
* @return Response object
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see UserInfoUpdateParam
* @see ResponseResult
*/
@Operation(summary = "更新当前用户信息")
@PatchMapping("info")
@@ -54,8 +74,12 @@ class UserController(
/**
* Change password
*
* @param userChangePasswordParam User change password parameters
* @return Response object
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see UserChangePasswordParam
* @see ResponseResult
*/
@Operation(summary = "更改密码")
@PostMapping("info")

View File

@@ -2,8 +2,10 @@ package top.fatweb.oxygen.api.controller.tool
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import top.fatweb.oxygen.api.annotation.BaseController
import top.fatweb.oxygen.api.entity.common.ResponseResult
import top.fatweb.oxygen.api.param.PageSortParam
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.service.tool.IStoreService
import top.fatweb.oxygen.api.vo.PageVo
@@ -14,18 +16,42 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see IStoreService
*/
@BaseController(path = ["/tool/store"], name = "工具商店", description = "工具商店相关接口")
class StoreController(
private val storeService: IStoreService
) {
/**
* Get store tool in page
* Get store tool paging information
*
* @param toolStoreGetParam Get tool parameters in tool store
* @return Response object includes store tool paging information
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see ToolStoreGetParam
* @see ResponseResult
* @see PageVo
* @see ToolVo
*/
@GetMapping
fun get(@Valid toolStoreGetParam: ToolStoreGetParam): ResponseResult<PageVo<ToolVo>> =
ResponseResult.databaseSuccess(data = storeService.getPage(toolStoreGetParam))
/**
* Get store tool paging information by username
*
* @param username Username
* @param pageSortParam Page sort parameters
* @return Response object includes store tool paging information
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see PageSortParam
* @see ResponseResult
* @see PageVo
* @see ToolVo
*/
@GetMapping("/{username}")
fun get(@PathVariable username: String, @Valid pageSortParam: PageSortParam): ResponseResult<PageVo<ToolVo>> =
ResponseResult.databaseSuccess(data = storeService.getPage(pageSortParam, username))
}

View File

@@ -27,6 +27,17 @@ interface UserMapper : BaseMapper<User> {
*/
fun selectOneWithPowerInfoByAccount(@Param("account") account: String): User?
/**
* Select one user with basic information by username
*
* @param username Username
* @return User object with basic information
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see User
*/
fun selectOneWithBasicInfoByUsername(@Param("username") username: String): User?
/**
* Select user ID in page
*

View File

@@ -28,6 +28,18 @@ interface StoreMapper : BaseMapper<Tool> {
*/
fun selectPage(page: IPage<Long>, @Param("searchValue") searchValue: String?): IPage<Long>
/**
* Select tool ID by username in page
*
* @param page Pagination
* @param username Username
* @return Tool ID in page
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see IPage
*/
fun selectPageByUsername(page: IPage<Long>, @Param("username") username: String): IPage<Long>
/**
* Select tool in list by tool IDs
*

View File

@@ -39,6 +39,17 @@ interface IUserService : IService<User> {
*/
fun getInfo(): UserWithPowerInfoVo
/**
* Get user information by username
*
* @param username Username
* @return UserWithInfoVo object
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
* @see UserWithInfoVo
*/
fun getBasicInfo(username: String): UserWithInfoVo
/**
* Update user information
*

View File

@@ -28,6 +28,7 @@ import top.fatweb.oxygen.api.util.RedisUtil
import top.fatweb.oxygen.api.util.StrUtil
import top.fatweb.oxygen.api.util.WebUtil
import top.fatweb.oxygen.api.vo.PageVo
import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo
@@ -85,13 +86,18 @@ class UserServiceImpl(
WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo)
?: throw UserNotFoundException()
override fun getBasicInfo(username: String): UserWithInfoVo =
baseMapper.selectOneWithBasicInfoByUsername(username)?.let(UserConverter::userToUserWithInfoVo)
?: throw NoRecordFoundException()
override fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean {
val userId = WebUtil.getLoginUserId() ?: throw AccessDeniedException("Access denied")
return userInfoService.update(
KtUpdateWrapper(UserInfo()).eq(UserInfo::userId, userId)
.set(UserInfo::avatar, userInfoUpdateParam.avatar)
.set(UserInfo::nickname, userInfoUpdateParam.nickname)
)
KtUpdateWrapper(UserInfo()).eq(UserInfo::userId, userId)
.set(UserInfo::avatar, userInfoUpdateParam.avatar)
.set(UserInfo::nickname, userInfoUpdateParam.nickname)
)
}
override fun password(userChangePasswordParam: UserChangePasswordParam) {

View File

@@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.service.tool
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.Tool
import top.fatweb.oxygen.api.param.PageSortParam
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.vo.PageVo
import top.fatweb.oxygen.api.vo.tool.ToolVo
@@ -22,4 +23,12 @@ interface IStoreService : IService<Tool> {
* @since 1.0.0
*/
fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo>
/**
* Get tool by username in page
*
* @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0
*/
fun getPage(pageSortParam: PageSortParam, username: String): PageVo<ToolVo>
}

View File

@@ -6,6 +6,7 @@ import org.springframework.stereotype.Service
import top.fatweb.oxygen.api.converter.tool.ToolConverter
import top.fatweb.oxygen.api.entity.tool.Tool
import top.fatweb.oxygen.api.mapper.tool.StoreMapper
import top.fatweb.oxygen.api.param.PageSortParam
import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.service.tool.IStoreService
import top.fatweb.oxygen.api.vo.PageVo
@@ -35,4 +36,17 @@ class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
return ToolConverter.toolPageToToolPageVo(toolPage)
}
override fun getPage(pageSortParam: PageSortParam, username: String): PageVo<ToolVo> {
val toolIdsPage = Page<Long>(pageSortParam.currentPage, 20)
toolIdsPage.setOptimizeCountSql(false)
val toolIdsIPage = baseMapper.selectPageByUsername(toolIdsPage, username)
val toolPage = Page<Tool>(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total)
if (toolIdsIPage.total > 0) {
toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records))
}
return ToolConverter.toolPageToToolPageVo(toolPage)
}
}