api code global jain
This commit is contained in:
409
app/Http/Controllers/Api/V1/Access/SanghController.php
Normal file
409
app/Http/Controllers/Api/V1/Access/SanghController.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Access;
|
||||
|
||||
use App\Http\Requests\Api\Sangh\StoreSanghRequest;
|
||||
use App\Http\Requests\Sangh\CreateSanghMemberCard;
|
||||
use App\Models\Sangh;
|
||||
use App\Constant\Constant;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use App\Http\Requests\Api\Sangh\SanghFollowRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\Api\Sant\UpdateSantRequest;
|
||||
use App\Models\SanghMember;
|
||||
use App\Repositories\Api\Access\Sangh\SanghInterface as SanghRepository;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SanghController extends ApiController
|
||||
{
|
||||
|
||||
public function __construct(SanghRepository $sanghRepository)
|
||||
{
|
||||
$this->sanghRepository = $sanghRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getSanghList($request->all());
|
||||
$this->setStatusCode($response['status']);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
$response['message'] = $ex->getMessage();
|
||||
$this->setStatusCode(Constant::CODE_403);
|
||||
}
|
||||
|
||||
return $this->respond($response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreSanghRequest $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'avatar' => 'required',
|
||||
]);
|
||||
$response = $this->sanghRepository->createSangh($request);
|
||||
$this->setStatusCode($response['status']);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
$response['message'] = $ex->getMessage();
|
||||
$this->setStatusCode(Constant::CODE_403);
|
||||
}
|
||||
|
||||
return $this->respond($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Sangh $sangh
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Sangh $sangh)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->showSangh($sangh);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UpdateSantRequest $request
|
||||
* @param \App\Models\Sant $sant
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Sangh $sangh)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->updateSangh($sangh, $request);
|
||||
$this->setStatusCode($response['status']);
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
$response['message'] = $ex->getMessage();
|
||||
$this->setStatusCode(Constant::CODE_403);
|
||||
}
|
||||
|
||||
return $this->respond($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Sangh $sangh
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->deleteSangh($id);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get list of in review sant.
|
||||
*
|
||||
* @param \App\Models\Sant $sant
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function userSanghList(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->userSanghList($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
public function inReviewSangh(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->inReviewSangh($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Follow sant.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function sanghFollow(SanghFollowRequest $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->sanghFollow($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get suuggestion sant.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function sanghSuggestion(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->sanghSuggestion($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get suuggestion sangh.
|
||||
* @param \App\Models\Sant $sangh
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function sanghFollowers(Request $request,Sangh $sangh)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->sanghFollowers($request->all(), $sangh);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sangh member.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function addSanghMember(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->addSanghMember($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sangh member.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function updateSanghMember(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->updateSanghMember($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sangh member.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getSanghMembers(Request $request, Sangh $sangh)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getSanghMembers($request->all(), $sangh);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get committee sangh member.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getSanghCommitteeMembers(Request $request, Sangh $sangh)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getSanghCommitteeMembers($request->all(), $sangh);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete sangh member.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function deleteSanghMember(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->deleteSanghMember($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* user list.
|
||||
* @param SanghFollowRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getUserList(SanghFollowRequest $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getUserList($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept/Reject sangh member request.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function acceptMemberRequest(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->acceptMemberRequest($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invited sangh members list.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getInvitedSanghMembers()
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getInvitedSanghMembers();
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of sangh if logged in user is member of any sangh
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getSanghNames()
|
||||
{
|
||||
try {
|
||||
$response = $this->sanghRepository->getSanghNames();
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get member card data
|
||||
* @return void
|
||||
*/
|
||||
public function getMemberCard($id)
|
||||
{
|
||||
|
||||
try{
|
||||
$response = $this->sanghRepository->getMemberCard($id);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update member card data
|
||||
*/
|
||||
|
||||
public function createSanghMemberCard(CreateSanghMemberCard $request)
|
||||
{
|
||||
try{
|
||||
$response = $this->sanghRepository->createSanghMemberCard($request);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user