116 lines
4.9 KiB
Java
116 lines
4.9 KiB
Java
package xin.merlin.myplayerbackend.controller;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import xin.merlin.myplayerbackend.entity.Inviting;
|
|
import xin.merlin.myplayerbackend.entity.UserInfo;
|
|
import xin.merlin.myplayerbackend.service.impl.InvitingServiceImpl;
|
|
import xin.merlin.myplayerbackend.utils.JwtUtil;
|
|
import xin.merlin.myplayerbackend.utils.result.Response;
|
|
import xin.merlin.myplayerbackend.utils.result.ResultCode;
|
|
|
|
import java.util.Objects;
|
|
|
|
import static com.baomidou.mybatisplus.extension.ddl.DdlScriptErrorHandler.PrintlnLogErrorHandler.log;
|
|
|
|
@RequestMapping("/inviting")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class InvitingController {
|
|
|
|
private final InvitingServiceImpl invitingService;
|
|
|
|
private final JwtUtil jwtUtil;
|
|
|
|
// playroom鉴权
|
|
private Boolean isAdmin(Integer id,Integer r_id){
|
|
return invitingService.playroomIsAdmin(id,r_id)==0;
|
|
}
|
|
|
|
@PostMapping("/friends")
|
|
Response requestFriend(@RequestHeader("Authorization")String token, @RequestBody UserInfo userInfo) {
|
|
try {
|
|
token = token.substring(7);
|
|
Integer id = jwtUtil.getId(token);
|
|
if (Objects.equals(id, userInfo.getId())) return Response.success(ResultCode.INVITING_ILLEGAL_REQUEST);
|
|
if(!invitingService.inviting(id,userInfo.getId(),null)) return Response.success(ResultCode.INVITING_RE_REQUEST);
|
|
return Response.success(ResultCode.SUCCESS);
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
@GetMapping("/get")
|
|
Response getFriend(@RequestHeader("Authorization")String token, @RequestParam Integer pageSize, @RequestParam Integer currentPage) {
|
|
try {
|
|
token = token.substring(7);
|
|
Integer id = jwtUtil.getId(token);
|
|
return Response.success(ResultCode.SUCCESS, invitingService.getInvitingDetail(id, pageSize, currentPage));
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
@PostMapping("/handle")
|
|
Response handleFriend(@RequestHeader("Authorization")String token, @RequestBody Inviting inviting) {
|
|
try {
|
|
if (Objects.equals(inviting.getInviter(), inviting.getTarget())) return Response.success(ResultCode.ACCOUNT_PERMISSION_DENY);
|
|
token = token.substring(7);
|
|
Integer id = jwtUtil.getId(token);
|
|
if(!inviting.getTarget().equals(id)) return Response.success(ResultCode.INVITING_ILLEGAL_RESPONSE);
|
|
if(!invitingService.handleFriendInviting(inviting)) return Response.success(ResultCode.INVITING_ILLEGAL_REQUEST);
|
|
return Response.success(ResultCode.SUCCESS);
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
@PostMapping("/playroom")
|
|
Response playRoom(@RequestBody Inviting inviting) {
|
|
try {
|
|
if(inviting.getRoom()==null || !inviting.getStatus().equals(0)) return Response.success(ResultCode.INVITING_REQUEST_ERROR);
|
|
if(!invitingService.inviting(inviting.getInviter(),inviting.getTarget(),inviting.getRoom())) return Response.success(ResultCode.INVITING_RE_REQUEST);
|
|
return Response.success(ResultCode.SUCCESS);
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
// 管理员获取playroom
|
|
@GetMapping("/playroom/get/{r_id}")
|
|
Response playroomGet(@RequestHeader("Authorization")String token,@PathVariable("r_id") Integer r_id, @RequestParam Integer pageSize, @RequestParam Integer currentPage) {
|
|
try {
|
|
token = token.substring(7);
|
|
Integer id = jwtUtil.getId(token);
|
|
if (!isAdmin(id,r_id)) return Response.success(ResultCode.INVITING_AUTH_ERROR);
|
|
return Response.success(ResultCode.SUCCESS, invitingService.getSelfInvitingDetail(r_id, pageSize, currentPage));
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
// 管理员对请求进行审批
|
|
@PostMapping("/playroom/handle/{r_id}")
|
|
Response playroomHandle(@RequestHeader("Authorization")String token,@PathVariable("r_id") Integer r_id, @RequestBody Inviting inviting) {
|
|
try {
|
|
token = token.substring(7);
|
|
Integer id = jwtUtil.getId(token);
|
|
if (!isAdmin(id,r_id)) return Response.success(ResultCode.INVITING_AUTH_ERROR);
|
|
if(!invitingService.handlePlayroomInviting(inviting)) return Response.success(ResultCode.INVITING_ILLEGAL_REQUEST);
|
|
|
|
return Response.success(ResultCode.SUCCESS);
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
return Response.fail(ResultCode.SERVER_ERROR);
|
|
}
|
|
}
|
|
|
|
}
|