diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt index d42d5af..c62c302 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt @@ -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() } 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 a332fec..e7c4490 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 @@ -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 = 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 = + 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") diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt index 52d1daa..3c18850 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt @@ -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> = 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> = + ResponseResult.databaseSuccess(data = storeService.getPage(pageSortParam, username)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt index 836b217..80c1aad 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt @@ -27,6 +27,17 @@ interface UserMapper : BaseMapper { */ 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 * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index ec3c0f6..96da5e0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -28,6 +28,18 @@ interface StoreMapper : BaseMapper { */ fun selectPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + /** + * 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, @Param("username") username: String): IPage + /** * Select tool in list by tool IDs * 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 ff456b6..06351d7 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,17 @@ interface IUserService : IService { */ 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 * 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 270d933..d0a4d30 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 @@ -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) { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt index 4ef68cd..956d114 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -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 { * @since 1.0.0 */ fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo + + /** + * Get tool by username in page + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun getPage(pageSortParam: PageSortParam, username: String): PageVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index cc68ac2..a59d487 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -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(), IStoreService { return ToolConverter.toolPageToToolPageVo(toolPage) } + + override fun getPage(pageSortParam: PageSortParam, username: String): PageVo { + val toolIdsPage = Page(pageSortParam.currentPage, 20) + toolIdsPage.setOptimizeCountSql(false) + + val toolIdsIPage = baseMapper.selectPageByUsername(toolIdsPage, username) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } } \ No newline at end of file diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index a844fc3..40cb1fb 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -60,6 +60,18 @@ and (tsui.email = #{account} or t_s_user.username = #{account}); + + + +