212 lines
5.9 KiB
PHP
212 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Access;
|
|
|
|
use App\Constant\Constant;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Api\ApiController;
|
|
use App\Http\Requests\Api\FriendRequest\StoreFriendRequest;
|
|
use App\Http\Requests\Api\FriendRequest\UpdateFriendRequest;
|
|
use App\Models\User;
|
|
use App\Repositories\Api\Access\Request\RequestInterface as RequestRepository;
|
|
|
|
class RequestController extends ApiController
|
|
{
|
|
/**
|
|
* @param RequestRepository $requestRepository
|
|
* RequestController constructor.
|
|
*/
|
|
public function __construct(RequestRepository $requestRepository)
|
|
{
|
|
$this->requestRepository = $requestRepository;
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function sendFriendRequest(StoreFriendRequest $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->sendFriendRequest($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function acceptFriendRequest(UpdateFriendRequest $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->acceptFriendRequest($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function listFriendRequest()
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->listFriendRequest();
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function myListFriendRequest(Request $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->myListFriendRequest($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function sentRequestList()
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->sentRequestList();
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function mySentRequestList(Request $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->mySentRequestList($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function friendList(Request $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->friendList($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function myFriendList(Request $request)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->myFriendList($request->all());
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* @return json
|
|
*/
|
|
public function userFriendList(Request $request, User $user)
|
|
{
|
|
$response = [];
|
|
|
|
try{
|
|
$response = $this->requestRepository->userFriendList($request, $user);
|
|
$this->setStatusCode($response['status']);
|
|
|
|
} catch (\Exception $ex) {
|
|
$response['message'] = $ex->getMessage();
|
|
$response['success'] = Constant::STATUS_FALSE;
|
|
$this->setStatusCode(Constant::CODE_403);
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
/**
|
|
* Get suuggestion sant.
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function friendSuggestion(Request $request)
|
|
{
|
|
try {
|
|
$response = $this->requestRepository->friendSuggestion($request->all());
|
|
$this->updateStatusCode($response);
|
|
|
|
return $this->respond($response);
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->respondInternalError(trans('api.something_went_wrong'));
|
|
}
|
|
}
|
|
}
|