|
|
|
@ -1,114 +0,0 @@
|
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.service.FriendService;
|
|
|
|
|
import com.luoo.user.service.UserInfoService;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import controller.BaseController;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import dto.UserMessageDto;
|
|
|
|
|
import enums.MessageTypeEnum;
|
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/friend")
|
|
|
|
|
@Api(tags = "FriendController")
|
|
|
|
|
public class FriendController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private FriendService friendService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加好友或者添加非好友(关注还是拉黑) 1是关注,2是拉黑
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "关注好友",notes = "friendid为关注好友的ID,type为1时是关注操作,type为2时是接黑名单操作,不是取关操作")
|
|
|
|
|
@PutMapping("/like/{friendid}/{type}")
|
|
|
|
|
public Result<Void> addFriend(@PathVariable String friendid, @PathVariable String type,@RequestHeader(value = "Authorization", required = true) String authorization) {
|
|
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
String userid = userLoginDto.getUserId();
|
|
|
|
|
//判断是添加好友还是非好友(判断是关注操作还是拉黑操作)
|
|
|
|
|
if (type != null) {
|
|
|
|
|
if (type.equals("1")) {
|
|
|
|
|
//添加好友
|
|
|
|
|
int flag = friendService.addFriend(userid,friendid);
|
|
|
|
|
if (flag == 0) {
|
|
|
|
|
return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_FRIEND); // 不能重复添加好友
|
|
|
|
|
}
|
|
|
|
|
if (flag == 1) {
|
|
|
|
|
userInfoService.updatefanscountandfollowcount(1,userid,friendid);
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo =userInfoService.findById(userid);
|
|
|
|
|
/**
|
|
|
|
|
* 向friend发送消息
|
|
|
|
|
*/
|
|
|
|
|
UserMessageDto userMessageDto = new UserMessageDto();
|
|
|
|
|
userMessageDto.setType(MessageTypeEnum.FOLLOW.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息
|
|
|
|
|
userMessageDto.setUserId(friendid);
|
|
|
|
|
userMessageDto.setContent(userInfo.getNickName()+" 关注了你");
|
|
|
|
|
userMessageDto.setTitle("您有新的粉丝");
|
|
|
|
|
userMessageDto.setSendUserAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar());
|
|
|
|
|
userMessageDto.setSendUserId(userid);
|
|
|
|
|
userMessageDto.setSendUserNickName(userInfo.getNickName());
|
|
|
|
|
rabbitTemplate.convertAndSend("userMessage",userMessageDto);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (type.equals("2")) {
|
|
|
|
|
//添加非好友
|
|
|
|
|
int flag = friendService.addNoFriend(userid,friendid);
|
|
|
|
|
if (flag == 0) {
|
|
|
|
|
return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND);
|
|
|
|
|
}
|
|
|
|
|
if (flag == 1) {
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result.failed(StatusCode.VALIDATE_FAILED);
|
|
|
|
|
} else {
|
|
|
|
|
return Result.failed(StatusCode.VALIDATE_FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "取消关注好友")
|
|
|
|
|
@DeleteMapping("/{friendid}")
|
|
|
|
|
public Result<Void> deleteFriend(@PathVariable String friendid,@RequestHeader(value = "Authorization", required = true) String authorization){
|
|
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
String userid = userLoginDto.getUserId();
|
|
|
|
|
friendService.deleteFriend(userid,friendid);
|
|
|
|
|
userInfoService.updatefanscountandfollowcount(-1,userid,friendid);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|