|
|
@ -3,14 +3,11 @@ package com.luoo.friend.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.friend.client.UserClient;
|
|
|
|
import com.luoo.friend.client.UserClient;
|
|
|
|
import com.luoo.friend.service.FriendService;
|
|
|
|
import com.luoo.friend.service.FriendService;
|
|
|
|
import entity.Result;
|
|
|
|
import api.Result;
|
|
|
|
import entity.StatusCode;
|
|
|
|
import api.StatusCode;
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
|
@ -32,13 +29,13 @@ public class FriendController {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/like/{friendid}/{type}", method = RequestMethod.PUT)
|
|
|
|
@PutMapping("/like/{friendid}/{type}")
|
|
|
|
public Result addFriend(@PathVariable String friendid, @PathVariable String type) {
|
|
|
|
public Result<Void> addFriend(@PathVariable String friendid, @PathVariable String type) {
|
|
|
|
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
Claims claims = (Claims) request.getAttribute("claims_user");
|
|
|
|
Claims claims = (Claims) request.getAttribute("claims_user");
|
|
|
|
if (claims == null) {
|
|
|
|
if (claims == null) {
|
|
|
|
return new Result(false, StatusCode.LOGINERROR, "权限不足");
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String userid = claims.getId();
|
|
|
|
String userid = claims.getId();
|
|
|
|
//判断是添加好友还是非好友
|
|
|
|
//判断是添加好友还是非好友
|
|
|
@ -47,41 +44,41 @@ public class FriendController {
|
|
|
|
//添加好友
|
|
|
|
//添加好友
|
|
|
|
int flag = friendService.addFriend(userid,friendid);
|
|
|
|
int flag = friendService.addFriend(userid,friendid);
|
|
|
|
if (flag == 0) {
|
|
|
|
if (flag == 0) {
|
|
|
|
return new Result(false, StatusCode.ERROR, "不能重复添加好友");
|
|
|
|
return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_FRIEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flag == 1) {
|
|
|
|
if (flag == 1) {
|
|
|
|
userClient.updatefanscountandfollowcount(userid,friendid,1);
|
|
|
|
userClient.updatefanscountandfollowcount(userid,friendid,1);
|
|
|
|
return new Result(true, StatusCode.OK, "添加成功");
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (type.equals("2")) {
|
|
|
|
} else if (type.equals("2")) {
|
|
|
|
//添加非好友
|
|
|
|
//添加非好友
|
|
|
|
int flag = friendService.addNoFriend(userid,friendid);
|
|
|
|
int flag = friendService.addNoFriend(userid,friendid);
|
|
|
|
if (flag == 0) {
|
|
|
|
if (flag == 0) {
|
|
|
|
return new Result(false, StatusCode.ERROR, "不能重复添加非好友");
|
|
|
|
return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flag == 1) {
|
|
|
|
if (flag == 1) {
|
|
|
|
return new Result(true, StatusCode.OK, "添加成功");
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new Result(false, StatusCode.ERROR, "参数异常");
|
|
|
|
return Result.failed(StatusCode.VALIDATE_FAILED);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return new Result(false, StatusCode.ERROR, "参数异常");
|
|
|
|
return Result.failed(StatusCode.VALIDATE_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/{friendid}", method = RequestMethod.DELETE)
|
|
|
|
@DeleteMapping("/{friendid}")
|
|
|
|
public Result deleteFriend(@PathVariable String friendid){
|
|
|
|
public Result<Void> deleteFriend(@PathVariable String friendid){
|
|
|
|
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
Claims claims = (Claims) request.getAttribute("claims_user");
|
|
|
|
Claims claims = (Claims) request.getAttribute("claims_user");
|
|
|
|
if (claims == null) {
|
|
|
|
if (claims == null) {
|
|
|
|
return new Result(false, StatusCode.LOGINERROR, "权限不足");
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String userid = claims.getId();
|
|
|
|
String userid = claims.getId();
|
|
|
|
friendService.deleteFriend(userid,friendid);
|
|
|
|
friendService.deleteFriend(userid,friendid);
|
|
|
|
userClient.updatefanscountandfollowcount(userid,friendid,-1);
|
|
|
|
userClient.updatefanscountandfollowcount(userid,friendid,-1);
|
|
|
|
return new Result(true,StatusCode.OK,"删除成功");
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|