增加我的好友列表和查找陌生人接口

master
pan 5 years ago
parent 0a00898ce0
commit bea12f27d8
  1. 7
      src/main/java/com/share/help/Constants.java
  2. 48
      src/main/java/com/share/help/controller/UserController.java
  3. 24
      src/main/java/com/share/help/dao/FriendMapper.java
  4. 4
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  5. 14
      src/main/java/com/share/help/dao/UserMapper.java
  6. 16
      src/main/java/com/share/help/entity/custorm/Friend.java
  7. 27
      src/main/java/com/share/help/form/ChatForm.java
  8. 10
      src/main/java/com/share/help/form/QueryUserForm.java
  9. 27
      src/main/java/com/share/help/form/SearchFrom.java
  10. 22
      src/main/java/com/share/help/form/UserLoginForm.java
  11. 12
      src/main/java/com/share/help/res/account/QueryRes.java
  12. 82
      src/main/java/com/share/help/service/UserService.java
  13. 2
      src/main/resources/application.yaml
  14. 21
      src/main/resources/mapping/FriendMapper.xml
  15. 21
      src/main/resources/mapping/LeaveWordMapper.xml
  16. 46
      src/main/resources/mapping/UserMapper.xml
  17. 53
      src/test/java/com/share/help/HelpApplicationTests.java

@ -35,7 +35,7 @@ public class Constants {
public static final String ACTIVITY_INTERFACE_APPLY = "/apply";
//用户查询信息接口
public static final String USER_INTERFACE_FIND_ID = USER_INTERFACE_FIND+"/{userId}";
public static final String USER_INTERFACE_FIND_ID = USER_INTERFACE_FIND+"/{targetUserId}";
//用户信息更新接口
public static final String USER_INTERFACE_UPDATE = "/update";
@ -59,4 +59,9 @@ public class Constants {
public static final String USER_INTERFACE_REFUSE_FRIEND = "/refuse/{id}";
//同意好友邀请
public static final String USER_INTERFACE_AGREE_FRIEND = "/agree";
// 好友列表
public static final String USER_INTERFACE_FRIEND_LIST = "/friend/list";
// 刷新聊天室状态
public static final String USER_INTERFACE_CHAT_STATUS = "/chat/status";
}

@ -2,6 +2,7 @@ package com.share.help.controller;
import com.share.help.Constants;
import com.share.help.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.Friend;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.form.*;
@ -88,9 +89,9 @@ public class UserController {
* @return 返回用户信息
*/
@GetMapping(Constants.USER_INTERFACE_FIND_ID)
public JSONResponse<DefaultRes, QueryRes> find(@PathVariable String userId){
if(userId!=null){
return userService.find(userId);
public JSONResponse<DefaultRes, QueryRes> find(@PathVariable String targetUserId,@CookieValue(Constants.USER_COOKIE) String userId){
if(!StringUtils.isAllEmpty(targetUserId,userId)){
return userService.find(targetUserId,userId);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
@ -136,8 +137,9 @@ public class UserController {
* @return 返回查询结果
*/
@GetMapping(Constants.USER_INTERFACE_FIND_NAME)
public JSONResponse<DefaultRes, List<UserWithName>> queryUser(QueryUserForm queryUserForm){
if(StringUtils.isNoneEmpty(queryUserForm.getUserName(),queryUserForm.getInfo())){
public JSONResponse<DefaultRes, Page<List<UserWithName>>> queryUser(QueryUserForm queryUserForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){
queryUserForm.setUserId(userId);
return userService.queryUser(queryUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
@ -186,6 +188,12 @@ public class UserController {
}
}
/**
* 同意好友邀请
* @param agreeFriendForm 邀请表单
* @param userId 邀请用户
* @return 返回同意结果
*/
@PostMapping(Constants.USER_INTERFACE_AGREE_FRIEND)
public JSONResponse<DefaultRes,Void> agreeFriend(AgreeFriendForm agreeFriendForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(agreeFriendForm.getSourceUserId(),userId,agreeFriendForm.getLeaveWordId())){
@ -196,4 +204,34 @@ public class UserController {
}
}
/**
* 检索好友
* @param searchFrom 检索好友表单
* @return 返回检索结果
*/
@GetMapping(Constants.USER_INTERFACE_FRIEND_LIST)
public JSONResponse<DefaultRes,Page<List<Friend>>> searchFriend(SearchFrom searchFrom, @CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.isNotEmpty(searchFrom.getCurrentPage())&&StringUtils.isNotEmpty(userId)){
searchFrom.setUserId(userId);
return userService.searchFriend(searchFrom);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 刷新用户的聊天状态
* @param chatForm 刷新表单
* @param userId 用户id
* @return 返回刷新结果
*/
@PostMapping(Constants.USER_INTERFACE_CHAT_STATUS)
public JSONResponse<DefaultRes,Void> changeChat(ChatForm chatForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.allNotNull(chatForm.getChatStatus(),userId)){
chatForm.setUserId(userId);
return userService.changeChat(chatForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -1,13 +1,37 @@
package com.share.help.dao;
import com.share.help.entity.FriendEntity;
import com.share.help.entity.custorm.Friend;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 添加好友
*/
public interface FriendMapper {
/**
* 添加好友邀请
* @param friendEntity 好友邀请
* @return 返回添加结果
*/
@Insert("insert into friend(source_user_id,target_user_id) value(#{sourceUserId},#{targetUserId})")
boolean addFriend(FriendEntity friendEntity);
/**
* 获取好友邀请
* @param userId 目标用户
* @return 返回好友id
*/
List<Friend> getFriend(@Param("userId") String userId, @Param("start") long start, @Param("count") long count);
/**
* 统计好友分页数
* @param userId 目标用户
* @return 返回分页数
*/
Page<List<Friend>> count(@Param("userId") String userId,@Param("pageSize") Integer pageSize);
}

@ -21,9 +21,7 @@ public interface LeaveWordMapper {
boolean insert(LeaveWordEntity leaveWordEntity);
// 查询留言列表
@Select("select leave_word.source_user_id as userId,user.name,user.head_img as headImg,user.info,leave_word.type,activity_id as activityId,leave_word_id as leaveWordId from leave_word,user\n" +
"where leave_word.target_user_id=#{userId} and leave_word.target_user_id=user.user_id order by create_time desc limit #{start},#{count}")
List<LeaveWordRes> select(@Param("start") long start,@Param("count") long count,@Param("userId") String userId);
List<LeaveWordRes> select(@Param("start") long start,@Param("count") long count,@Param("userId") String userId);
// 统计留言列表分页数
@Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from leave_word where target_user_id=#{userId}")

@ -3,6 +3,8 @@ package com.share.help.dao;
import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.res.Page;
import com.share.help.res.account.QueryRes;
import org.apache.ibatis.annotations.*;
import java.util.List;
@ -89,5 +91,15 @@ public interface UserMapper {
/**
* 查找用户
*/
List<UserWithName> queryUser(@Param("name") String name,@Param("info") String info);
List<UserWithName> queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId);
Page<List<UserWithName>> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize);
/**
* 查看用户信息
* @param targetUserId 被查看用户id
* @param userId 查看用户id
* @return 返回用户信息
*/
QueryRes findInfo(@Param("targetUserId") String targetUserId,@Param("userId") String userId);
}

@ -0,0 +1,16 @@
package com.share.help.entity.custorm;
/**
* 我的好友信息
*/
public class Friend extends UserWithName{
private Boolean chatStatus;
public Boolean getChatStatus() {
return chatStatus;
}
public void setChatStatus(Boolean chatStatus) {
this.chatStatus = chatStatus;
}
}

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 刷新我在聊天室的状态
*/
public class ChatForm {
private String userId;
private Boolean chatStatus;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Boolean getChatStatus() {
return chatStatus;
}
public void setChatStatus(Boolean chatStatus) {
this.chatStatus = chatStatus;
}
}

@ -7,7 +7,7 @@ public class QueryUserForm {
//用户id
private String userId;
//用户名
private String userName;
private String name;
//简介信息
private String info;
@ -19,12 +19,12 @@ public class QueryUserForm {
this.userId = userId;
}
public String getUserName() {
return userName;
public String getName() {
return name;
}
public void setUserName(String userName) {
this.userName = userName;
public void setName(String name) {
this.name = name;
}
public String getInfo() {

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 检索好友表单
*/
public class SearchFrom {
// 用户id
private String userId;
//分页数
private Integer currentPage;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}

@ -1,7 +1,25 @@
package com.share.help.form;
import com.share.help.entity.UserEntity;
/**
* 登陆表单
*/
public class UserLoginForm{
private String userId;
private String password;
public class UserLoginForm extends UserEntity {
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -1,5 +1,7 @@
package com.share.help.res.account;
import com.fasterxml.jackson.annotation.JsonProperty;
public class QueryRes {
private String userId;
private String name;
@ -12,6 +14,16 @@ public class QueryRes {
private String email;
private String info;
private Integer age;
private boolean isMyFriend;
@JsonProperty("isMyFriend")
public boolean isMyFriend() {
return isMyFriend;
}
public void setMyFriend(boolean myFriend) {
isMyFriend = myFriend;
}
public String getUserId() {
return userId;

@ -1,18 +1,23 @@
package com.share.help.service;
import com.share.help.Util;
import com.share.help.dao.FriendMapper;
import com.share.help.dao.UserMapper;
import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.FindUserRes;
import com.share.help.entity.custorm.Friend;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.form.*;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Page;
import com.share.help.res.Result;
import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -34,14 +39,22 @@ public class UserService{
//用户分页配置
@Value("${page-size.user.page-size}")
private int pageSize;
private int userPageSize;
@Value("${page-size.user.row-size}")
private int rowSize;
private int userRowSize;
@Autowired
private ImageService imageService;
@Autowired
private FriendMapper friendMapper;
@Value("${page-size.friend}")
private int friendSize;
private Logger logger= LoggerFactory.getLogger(UserService.class);
/**
* 注册
* @param userRegisterForm 注册表单
@ -64,6 +77,7 @@ public class UserService{
//保存头像
String imageName=imageService.saveImg(userRegisterForm.getImgFile());
if(imageName==null){
logger.error("保存头像失败");
return new JSONResponse<>(RegisterRes.fail, Result.FAIL);
}
userEntity.setHeadImg(imageName);
@ -96,13 +110,13 @@ public class UserService{
* @return 返回志愿者列表
*/
public JSONResponse<FindUserRes.Res,FindUserRes> find(FindUserForm findUserForm){
FindUserRes findUserRes=userMapper.count(pageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress());
findUserRes.setPageSize(pageSize);
FindUserRes findUserRes=userMapper.count(userPageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress());
findUserRes.setPageSize(userPageSize);
findUserRes.setCurrentPage(findUserForm.getCurrentPage());
List<UserEntity> userEntityList=userMapper.getPage((findUserForm.getCurrentPage()-1)*pageSize,pageSize,findUserForm.getUserTypes(),
List<UserEntity> userEntityList=userMapper.getPage((findUserForm.getCurrentPage()-1)* userPageSize, userPageSize,findUserForm.getUserTypes(),
findUserForm.getInfo(),findUserForm.getServiceAddress());
if(!userEntityList.isEmpty()){
findUserRes.setBody(Util.splitList(UserEntity.class,userEntityList,rowSize));
findUserRes.setBody(Util.splitList(UserEntity.class,userEntityList, userRowSize));
return new JSONResponse<FindUserRes.Res,FindUserRes>(FindUserRes.Res.ok,Result.OK).setBody(findUserRes);
}else{
return new JSONResponse<>(FindUserRes.Res.empty, Result.OK);
@ -111,23 +125,14 @@ public class UserService{
/**
* 获取用户个人信息
*
* @param targetUserId 目标用户
* @param userId 用户id
* @return 返回用户信息
*/
public JSONResponse<DefaultRes, QueryRes> find(String userId){
UserEntity userEntity= userMapper.findOne(userId);
if(userEntity!=null){
QueryRes queryRes=new QueryRes();
queryRes.setUserId(userEntity.getUserId());
queryRes.setHeadImg(userEntity.getHeadImg());
queryRes.setName(userEntity.getName());
queryRes.setAge(userEntity.getAge());
queryRes.setMobile(userEntity.getMobile());
queryRes.setEmail(userEntity.getEmail());
queryRes.setServiceAddress(userEntity.getServiceAddress());
queryRes.setInfo(userEntity.getInfo());
queryRes.setUserType(userEntity.getUserType());
queryRes.setSex(userEntity.getSex());
public JSONResponse<DefaultRes, QueryRes> find(String targetUserId, String userId){
QueryRes queryRes= userMapper.findInfo(targetUserId,userId);
if(queryRes!=null){
return new JSONResponse<DefaultRes, QueryRes>(DefaultRes.ok,Result.OK).setBody(queryRes);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
@ -187,9 +192,40 @@ public class UserService{
* @param queryUserForm 搜索条件
* @return 返回查询结果
*/
public JSONResponse<DefaultRes, List<UserWithName>> queryUser(QueryUserForm queryUserForm){
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getUserName(),queryUserForm.getInfo());
return new JSONResponse<DefaultRes, List<UserWithName>>(DefaultRes.ok,Result.OK).setBody(userWithNameList);
public JSONResponse<DefaultRes, Page<List<UserWithName>>> queryUser(QueryUserForm queryUserForm){
Page<List<UserWithName>> page=userMapper.countUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),userPageSize);
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId());
page.setBody(userWithNameList);
return new JSONResponse<DefaultRes,Page<List<UserWithName>>>(DefaultRes.ok,Result.OK).setBody(page);
}
/**
* 检索好友表单
* @param searchFrom 检索条件
* @return 返回好友列表
*/
public JSONResponse<DefaultRes, Page<List<Friend>>> searchFriend(SearchFrom searchFrom) {
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),friendSize);
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
page.setBody(list);
return new JSONResponse<DefaultRes,Page<List<Friend>>>(DefaultRes.ok,Result.OK).setBody(page);
}
/**
* 刷新聊天状态
* @param chatForm 表单
* @return 返回刷新结果
*/
public JSONResponse<DefaultRes, Void> changeChat(ChatForm chatForm) {
UserEntity userEntity=userMapper.findOne(chatForm.getUserId());
if(userEntity==null){
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
userEntity.setChatStatus(chatForm.getChatStatus());
if(userMapper.update(userEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -44,4 +44,6 @@ page-size:
page-size: 6
# 前端一行显示数量
row-size: 3
#好友列表
friend: 3

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.share.help.dao.FriendMapper">
<!-- 获取好友列表-->
<select id="getFriend" resultType="com.share.help.entity.custorm.Friend">
select user_id as userId,name,chat_status as chatStatus from user where user_id in (
select source_user_id as userId from friend where source_user_id!=#{userId} and target_user_id=#{userId}
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
limit #{start},#{count}
</select>
<select id="count" resultType="com.share.help.res.Page">
select count,ceil(count/#{pageSize}) as totalPage from(
(select (select count(*) from friend where source_user_id!=#{userId})+
(select count(*) from friend where target_user_id!=#{userId}) as count)) as c
</select>
</mapper>

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.share.help.dao.LeaveWordMapper">
<select id="select" resultType="com.share.help.entity.custorm.LeaveWordRes">
select leave_word.source_user_id as userId,
user.name,
user.head_img as headImg,
user.info,
leave_word.type,
activity_id
as activityId,
leave_word_id as leaveWordId
from leave_word,
user
where leave_word.target_user_id = #{userId}
and leave_word.source_user_id = user.user_id
order by create_time desc
</select>
</mapper>

@ -5,7 +5,6 @@
<mapper namespace="com.share.help.dao.UserMapper">
<resultMap id="userMap" type="com.share.help.entity.UserEntity">
<id property="userId" column="user_id"/>
<result property="userId" column="user_id"/>
<result property="headImg" column="head_img"/>
<result property="serviceAddress" column="service_address"/>
<result property="userType" column="user_type"/>
@ -13,6 +12,21 @@
<result property="chatStatus" column="chat_status"/>
</resultMap>
<resultMap id="queryRes" type="com.share.help.res.account.QueryRes">
<id property="userId" column="user_id"/>
<result property="headImg" column="head_img"/>
<result property="serviceAddress" column="service_address"/>
<result property="userType" column="user_type"/>
</resultMap>
<!-- 查找用户信息-->
<select id="findInfo" resultMap="queryRes">
select user_id,head_img,name,age,mobile,email,service_address,info,user_type,sex,(select count(*)=1 from(
select source_user_id,target_user_id from friend where source_user_id=#{userId} and target_user_id=#{targetUserId}
union all
select source_user_id,target_user_id from friend where source_user_id=#{targetUserId} and target_user_id=#{userId})a)
as isMyFriend from user where user_id=#{targetUserId}
</select>
<!-- 统计用户分页数-->
<select id="count" resultType="com.share.help.entity.custorm.FindUserRes">
@ -88,22 +102,42 @@
sex=#{sex},
</if>
<if test="password!=null and password!=''">
password=#{password}
password=#{password},
</if>
<if test="chatStatus!=null">
chat_status=#{chatStatus}
</if>
</set>
where user_id=#{userId}
</update>
<!-- 查找用户-->
<select id="queryUser" resultType="com.share.help.entity.custorm.UserWithName">
select user_id as userId,name from user
<!-- 用户检索条件-->
<sql id="where_query_user">
<where>
user_id not in(
select user_id from user where user_id in (
select source_user_id as userId from friend where source_user_id!=#{userId} and target_user_id=#{userId}
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
)
<if test="name!=null and name!=''">
name like '%${name}%'
and name like '%${name}%'
</if>
<if test="info!=null and info!=''">
and info like '%${info}%'
</if>
</where>
</sql>
<!-- 查找用户-->
<select id="queryUser" resultType="com.share.help.entity.custorm.UserWithName">
select user_id as userId,name from user
<include refid="where_query_user"/>
</select>
<select id="countUser" resultType="com.share.help.res.Page">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from user
<include refid="where_query_user"/>
</select>
</mapper>

@ -1,14 +1,12 @@
package com.share.help;
import com.share.help.dao.ActivityHistoryMapper;
import com.share.help.dao.ActivityMapper;
import com.share.help.dao.LeaveWordMapper;
import com.share.help.dao.UserMapper;
import com.share.help.dao.*;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.*;
import com.share.help.form.ActivityStatus;
import com.share.help.res.Page;
import com.share.help.res.account.QueryRes;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -26,6 +24,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.http.Cookie;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@ -53,6 +52,9 @@ class HelpApplicationTests {
@Autowired
private LeaveWordMapper leaveWordMapper;
@Autowired
private FriendMapper friendMapper;
private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class);
@BeforeEach
@ -190,19 +192,22 @@ class HelpApplicationTests {
//查询用户列表
@Test
public void queryUser(){
List<UserWithName> userWithNames =userMapper.queryUser("6",null);
Page<List<UserWithName>> count=userMapper.countUser("6",null,"123",10);
Assertions.assertTrue(count.getCount()>0);
List<UserWithName> userWithNames =userMapper.queryUser("2",null,"123");
Assertions.assertFalse(userWithNames.isEmpty());
userWithNames =userMapper.queryUser("6","2");
userWithNames =userMapper.queryUser("2","2", "123");
Assertions.assertFalse(userWithNames.isEmpty());
}
//留言列表
@Test
public void queryLeaveWord(){
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(10,"222");
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(10,"777");
Assertions.assertNotNull(listPage);
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"222");
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"777");
Assertions.assertFalse(leaveWordRes.isEmpty());
}
@ -214,4 +219,36 @@ class HelpApplicationTests {
List<HelpRes> list= activityHistoryMapper.queryMyHelp(0,2,"123");
Assertions.assertFalse(list.isEmpty());
}
/**
* 查找好友
*/
@Test
public void queryFriend(){
Page<List<Friend>> page=friendMapper.count("123",3);
Assertions.assertEquals(1, (long) page.getCount());
List<Friend> user=friendMapper.getFriend("123",0,3);
Assertions.assertTrue(!user.isEmpty()&&"222".equals(user.get(0).getUserId()));
}
/**
* 查找用户信息
*/
@Test
public void queryUserInfo(){
QueryRes queryRes= userMapper.findInfo("123","222");
Assertions.assertTrue(queryRes.isMyFriend());
queryRes= userMapper.findInfo("123","777");
Assertions.assertFalse(queryRes.isMyFriend());
}
@Test
public void testQueryUserCtrl() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.USER_INTERFACE+
Constants.USER_INTERFACE_FIND_ID.replace("{targetUserId}","123")).cookie(new Cookie("user_cookie","777"));
mvc.perform(builder).andDo(MockMvcResultHandlers.print());
}
}

Loading…
Cancel
Save