Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
11 changed files with 149 additions and 7 deletions
Showing only changes of commit 3c82107394 - Show all commits

View File

@@ -80,7 +80,7 @@ class SecurityConfig(
"/forget", "/forget",
"/retrieve" "/retrieve"
).anonymous() ).anonymous()
.requestMatchers("/tool/detail/**", "/tool/store").permitAll() .requestMatchers("/tool/detail/**", "/tool/store", "/tool/store/*", "/system/user/info/*").permitAll()
// Authentication required // Authentication required
.anyRequest().authenticated() .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.param.permission.user.*
import top.fatweb.oxygen.api.service.permission.IUserService import top.fatweb.oxygen.api.service.permission.IUserService
import top.fatweb.oxygen.api.vo.PageVo 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.UserWithPasswordRoleInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo
@@ -35,15 +36,34 @@ class UserController(
* @see UserWithPowerInfoVo * @see UserWithPowerInfoVo
*/ */
@Operation(summary = "获取当前用户信息") @Operation(summary = "获取当前用户信息")
@GetMapping("info") @GetMapping("/info")
fun getInfo(): ResponseResult<UserWithPowerInfoVo> = fun getInfo(): ResponseResult<UserWithPowerInfoVo> =
ResponseResult.databaseSuccess(data = userService.getInfo()) 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 * Update current user information
* *
* @param userInfoUpdateParam Update user information parameters
* @return Response object
* @author FatttSnake, fatttsnake@gmail.com * @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0 * @since 1.0.0
* @see UserInfoUpdateParam
* @see ResponseResult
*/ */
@Operation(summary = "更新当前用户信息") @Operation(summary = "更新当前用户信息")
@PatchMapping("info") @PatchMapping("info")
@@ -54,8 +74,12 @@ class UserController(
/** /**
* Change password * Change password
* *
* @param userChangePasswordParam User change password parameters
* @return Response object
* @author FatttSnake, fatttsnake@gmail.com * @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0 * @since 1.0.0
* @see UserChangePasswordParam
* @see ResponseResult
*/ */
@Operation(summary = "更改密码") @Operation(summary = "更改密码")
@PostMapping("info") @PostMapping("info")

View File

@@ -2,8 +2,10 @@ package top.fatweb.oxygen.api.controller.tool
import jakarta.validation.Valid import jakarta.validation.Valid
import org.springframework.web.bind.annotation.GetMapping 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.annotation.BaseController
import top.fatweb.oxygen.api.entity.common.ResponseResult 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.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.service.tool.IStoreService import top.fatweb.oxygen.api.service.tool.IStoreService
import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.PageVo
@@ -14,18 +16,42 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo
* *
* @author FatttSnake, fatttsnake@gmail.com * @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0 * @since 1.0.0
* @see IStoreService
*/ */
@BaseController(path = ["/tool/store"], name = "工具商店", description = "工具商店相关接口") @BaseController(path = ["/tool/store"], name = "工具商店", description = "工具商店相关接口")
class StoreController( class StoreController(
private val storeService: IStoreService 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 * @author FatttSnake, fatttsnake@gmail.com
* @since 1.0.0 * @since 1.0.0
* @see ToolStoreGetParam
* @see ResponseResult
* @see PageVo
* @see ToolVo
*/ */
@GetMapping @GetMapping
fun get(@Valid toolStoreGetParam: ToolStoreGetParam): ResponseResult<PageVo<ToolVo>> = fun get(@Valid toolStoreGetParam: ToolStoreGetParam): ResponseResult<PageVo<ToolVo>> =
ResponseResult.databaseSuccess(data = storeService.getPage(toolStoreGetParam)) 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? 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 * 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> 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 * Select tool in list by tool IDs
* *

View File

@@ -39,6 +39,17 @@ interface IUserService : IService<User> {
*/ */
fun getInfo(): UserWithPowerInfoVo 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 * 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.StrUtil
import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.util.WebUtil
import top.fatweb.oxygen.api.vo.PageVo 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.UserWithPasswordRoleInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo
import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo
@@ -85,13 +86,18 @@ class UserServiceImpl(
WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo) WebUtil.getLoginUsername()?.let(::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo)
?: throw UserNotFoundException() ?: throw UserNotFoundException()
override fun getBasicInfo(username: String): UserWithInfoVo =
baseMapper.selectOneWithBasicInfoByUsername(username)?.let(UserConverter::userToUserWithInfoVo)
?: throw NoRecordFoundException()
override fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean { override fun updateInfo(userInfoUpdateParam: UserInfoUpdateParam): Boolean {
val userId = WebUtil.getLoginUserId() ?: throw AccessDeniedException("Access denied") val userId = WebUtil.getLoginUserId() ?: throw AccessDeniedException("Access denied")
return userInfoService.update( return userInfoService.update(
KtUpdateWrapper(UserInfo()).eq(UserInfo::userId, userId) KtUpdateWrapper(UserInfo()).eq(UserInfo::userId, userId)
.set(UserInfo::avatar, userInfoUpdateParam.avatar) .set(UserInfo::avatar, userInfoUpdateParam.avatar)
.set(UserInfo::nickname, userInfoUpdateParam.nickname) .set(UserInfo::nickname, userInfoUpdateParam.nickname)
) )
} }
override fun password(userChangePasswordParam: UserChangePasswordParam) { 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 com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.oxygen.api.entity.tool.Tool 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.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.PageVo
import top.fatweb.oxygen.api.vo.tool.ToolVo import top.fatweb.oxygen.api.vo.tool.ToolVo
@@ -22,4 +23,12 @@ interface IStoreService : IService<Tool> {
* @since 1.0.0 * @since 1.0.0
*/ */
fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo<ToolVo> 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.converter.tool.ToolConverter
import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.entity.tool.Tool
import top.fatweb.oxygen.api.mapper.tool.StoreMapper 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.param.tool.ToolStoreGetParam
import top.fatweb.oxygen.api.service.tool.IStoreService import top.fatweb.oxygen.api.service.tool.IStoreService
import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.PageVo
@@ -35,4 +36,17 @@ class StoreServiceImpl : ServiceImpl<StoreMapper, Tool>(), IStoreService {
return ToolConverter.toolPageToToolPageVo(toolPage) 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)
}
} }

View File

@@ -60,6 +60,18 @@
and (tsui.email = #{account} or t_s_user.username = #{account}); and (tsui.email = #{account} or t_s_user.username = #{account});
</select> </select>
<select id="selectOneWithBasicInfoByUsername" resultMap="userWithInfoMap">
select t_s_user.id as user_id,
t_s_user.username as user_username,
tsui.id as user_info_id,
tsui.nickname as user_info_nickname,
tsui.avatar as user_info_avatar
from t_s_user
left join (select * from t_s_user_info where deleted = 0) as tsui on t_s_user.id = tsui.user_id
where t_s_user.deleted = 0
and t_s_user.username = #{username};
</select>
<select id="selectPage" resultType="long"> <select id="selectPage" resultType="long">
select t_s_user.id select t_s_user.id
from t_s_user from t_s_user

View File

@@ -38,6 +38,23 @@
) as tb ) as tb
</select> </select>
<select id="selectPageByUsername" resultType="long">
select distinct tb.id
from (select tbtm.id
from (select temp.id, temp.author_id, temp.review, temp.publish
from (select *,
row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc)
as rn
from t_b_tool_main
where deleted = 0) temp
where temp.rn = 1) as tbtm
left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = tbtm.author_id
where tbtm.publish != 0
and tbtm.review = 'PASS'
and tsu.username = #{username}
order by tbtm.publish desc) as tb
</select>
<select id="selectListByIds" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithAuthor"> <select id="selectListByIds" resultMap="top.fatweb.oxygen.api.mapper.tool.ManagementMapper.toolWithAuthor">
select t_b_tool_main.id as tool_id, select t_b_tool_main.id as tool_id,
t_b_tool_main.name as tool_name, t_b_tool_main.name as tool_name,