用户查询个人信息功能
This commit is contained in:
@@ -2,7 +2,10 @@ package com.bao.dating.controller;
|
|||||||
|
|
||||||
import com.bao.dating.common.Result;
|
import com.bao.dating.common.Result;
|
||||||
import com.bao.dating.common.ResultCode;
|
import com.bao.dating.common.ResultCode;
|
||||||
|
import com.bao.dating.context.UserContext;
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||||
|
import com.bao.dating.pojo.entity.User;
|
||||||
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||||
import com.bao.dating.service.UserService;
|
import com.bao.dating.service.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -24,4 +27,11 @@ public class UserController {
|
|||||||
UserLoginVO userloginVO = userService.userLogin(userLoginDTO);
|
UserLoginVO userloginVO = userService.userLogin(userLoginDTO);
|
||||||
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/info")
|
||||||
|
public Result<UserInfoVO> getUserInfo() {
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
UserInfoVO userInfoVO = userService.getUserInfo(userId);
|
||||||
|
return Result.success(ResultCode.SUCCESS, "获取用户信息成功", userInfoVO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public interface PostMapper {
|
|||||||
*
|
*
|
||||||
* @param postIds 动态ID
|
* @param postIds 动态ID
|
||||||
*/
|
*/
|
||||||
int deletePostByIds(@Param("postIds") List<Long> postIds);
|
int deletePostByIds(List<Long> postIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询动态
|
* 根据ID查询动态
|
||||||
@@ -28,7 +28,7 @@ public interface PostMapper {
|
|||||||
* @param postId
|
* @param postId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Post selectById(@Param("postId") Long postId);
|
Post selectById(Long postId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID更新动态
|
* 根据ID更新动态
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.bao.dating.mapper;
|
|||||||
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
import com.bao.dating.pojo.entity.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
@@ -13,4 +14,12 @@ public interface UserMapper {
|
|||||||
* @return 用户
|
* @return 用户
|
||||||
*/
|
*/
|
||||||
User getByUsername(String username);
|
User getByUsername(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id查询用户信息
|
||||||
|
*
|
||||||
|
* @param userid 用户id
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
User selectByUserId(Long userid);
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main/java/com/bao/dating/pojo/vo/UserInfoVO.java
Normal file
23
src/main/java/com/bao/dating/pojo/vo/UserInfoVO.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.bao.dating.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息VO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserInfoVO {
|
||||||
|
private Long userId;
|
||||||
|
private String nickname;
|
||||||
|
private String avatarUrl;
|
||||||
|
private String backgroundUrl;
|
||||||
|
private Integer gender;
|
||||||
|
private LocalDate birthday;
|
||||||
|
private List<String> hobbies;
|
||||||
|
private String signature;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.bao.dating.service;
|
package com.bao.dating.service;
|
||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||||
|
import com.bao.dating.pojo.vo.PostEditVO;
|
||||||
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
@@ -10,4 +12,10 @@ public interface UserService {
|
|||||||
* @return 登录结果
|
* @return 登录结果
|
||||||
*/
|
*/
|
||||||
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询个人信息
|
||||||
|
* @param userId 动态ID
|
||||||
|
*/
|
||||||
|
UserInfoVO getUserInfo(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class PostServiceImpl implements PostService {
|
|||||||
* 查询动态详情(用于编辑)
|
* 查询动态详情(用于编辑)
|
||||||
*
|
*
|
||||||
* @param postId 动态ID
|
* @param postId 动态ID
|
||||||
* @return
|
* @return 动态详情
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PostEditVO getPostForEdit(Long postId) {
|
public PostEditVO getPostForEdit(Long postId) {
|
||||||
@@ -210,7 +210,7 @@ public class PostServiceImpl implements PostService {
|
|||||||
* 修改动态
|
* 修改动态
|
||||||
* @param postId 动态ID
|
* @param postId 动态ID
|
||||||
* @param postRequestDTO 修改的动态数据传输对象
|
* @param postRequestDTO 修改的动态数据传输对象
|
||||||
* @return
|
* @return 修改的动态对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO) {
|
public PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO) {
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package com.bao.dating.service.impl;
|
|||||||
import com.bao.dating.mapper.UserMapper;
|
import com.bao.dating.mapper.UserMapper;
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||||
import com.bao.dating.pojo.entity.User;
|
import com.bao.dating.pojo.entity.User;
|
||||||
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||||
import com.bao.dating.service.UserService;
|
import com.bao.dating.service.UserService;
|
||||||
import com.bao.dating.util.JwtUtil;
|
import com.bao.dating.util.JwtUtil;
|
||||||
import com.bao.dating.util.MD5Util;
|
import com.bao.dating.util.MD5Util;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -16,6 +18,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户登录
|
||||||
|
* @param userLoginDTO
|
||||||
|
* @return 登录信息
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserLoginVO userLogin(UserLoginDTO userLoginDTO) {
|
public UserLoginVO userLogin(UserLoginDTO userLoginDTO) {
|
||||||
// 参数校验
|
// 参数校验
|
||||||
@@ -45,4 +52,20 @@ public class UserServiceImpl implements UserService {
|
|||||||
userLoginVO.setToken(token);
|
userLoginVO.setToken(token);
|
||||||
return userLoginVO;
|
return userLoginVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
* @param userId
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public UserInfoVO getUserInfo(Long userId) {
|
||||||
|
User user = userMapper.selectByUserId(userId);
|
||||||
|
if (user == null){
|
||||||
|
throw new RuntimeException("用户不存在");
|
||||||
|
}
|
||||||
|
UserInfoVO userInfoVO = new UserInfoVO();
|
||||||
|
BeanUtils.copyProperties(user, userInfoVO);
|
||||||
|
return userInfoVO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,43 @@
|
|||||||
|
|
||||||
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
||||||
|
|
||||||
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
<!--根据用户名查询用户-->
|
||||||
SELECT * FROM user WHERE user_name = #{userName}
|
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
||||||
|
SELECT
|
||||||
|
user_id,
|
||||||
|
user_name,
|
||||||
|
password_hash,
|
||||||
|
salt,
|
||||||
|
nickname
|
||||||
|
FROM user WHERE user_name = #{userName}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!--根据用户id查询用户信息-->
|
||||||
|
<resultMap id="UserResultMap" type="com.bao.dating.pojo.entity.User">
|
||||||
|
<id property="userId" column="user_id"/>
|
||||||
|
<result property="nickname" column="nickname"/>
|
||||||
|
<result property="avatarUrl" column="avatar_url"/>
|
||||||
|
<result property="backgroundUrl" column="background_url"/>
|
||||||
|
<result property="gender" column="gender"/>
|
||||||
|
<result property="birthday" column="birthday"/>
|
||||||
|
<result property="hobbies" column="hobbies" typeHandler="com.bao.dating.handler.ListToVarcharTypeHandler"/>
|
||||||
|
<result property="signature" column="signature"/>
|
||||||
|
<result property="createdAt" column="created_at"/>
|
||||||
|
<result property="updatedAt" column="updated_at"/>
|
||||||
|
</resultMap>
|
||||||
|
<select id="selectByUserId" resultMap="UserResultMap">
|
||||||
|
SELECT
|
||||||
|
user_id,
|
||||||
|
nickname,
|
||||||
|
avatar_url,
|
||||||
|
background_url,
|
||||||
|
gender,
|
||||||
|
birthday,
|
||||||
|
hobbies,
|
||||||
|
signature,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM user WHERE user_id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user