feat(auth): add user profile to auth token response

- Add jwt configuration in application.yaml
- Include user profile information in authentication response
- Implement user profile response DTO with role mapping
- Fix typo in UserProfileService interface and implementation class names
- Add pagination support for user list endpoint
- Configure MyBatis Plus interceptor for MariaDB
- Add MyBatis Plus JSQLParser dependency
- Implement page-based user retrieval with role information
- Remove obsolete MyBatis configuration class
- Update controller to use paginated user data
- Replace manual user conversion with constructor mapping
- Rename UserProfileServcie to UserProfileService consistently
This commit is contained in:
Chaos
2025-11-24 17:10:01 +08:00
parent ec49ea8e25
commit a5a23a6b52
12 changed files with 121 additions and 48 deletions

View File

@@ -48,7 +48,11 @@
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-jsqlparser -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-jsqlparser</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,9 +0,0 @@
package cn.nopj.chaos_api.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan("cn.nopj.chaos_api.mapper")
public class MyBatisPlusConfig {
}

View File

@@ -3,6 +3,8 @@ package cn.nopj.chaos_api.mapper;
import cn.nopj.chaos_api.domain.entity.Role;
import cn.nopj.chaos_api.domain.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;
@@ -99,4 +101,30 @@ public interface UserMapper extends BaseMapper<User> {
many = @Many(select = "findRolesByUserId"))
})
User findUserWithRolesByUsername(String username);
/**
* 分页查询用户,并携带角色信息
* MyBatis-Plus 会自动处理 Page 参数进行物理分页
* @param page 分页对象
* @param keyword 搜索关键词 (可选)
* @return 分页后的用户列表 (包含角色)
*/
@Select("""
<script>
SELECT * FROM t_user
<where>
<if test='keyword != null and keyword != ""'>
AND (username LIKE CONCAT('%', #{keyword}, '%') OR nickname LIKE CONCAT('%', #{keyword}, '%'))
</if>
</where>
ORDER BY id ASC
</script>
""")
@Results({
@Result(id = true, property = "id", column = "id"),
@Result(property = "username", column = "username"),
@Result(property = "nickname", column = "nickname"),
@Result(property = "roles", column = "id",
many = @Many(select = "findRolesByUserId"))
})
IPage<User> selectPageWithRoles(Page<User> page, @Param("keyword") String keyword);
}