refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
156
app/Http/Controllers/Api/Contact/ApiAddressController.php
Normal file
156
app/Http/Controllers/Api/Contact/ApiAddressController.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Address;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\Address\CreateAddress;
|
||||
use App\Services\Contact\Address\UpdateAddress;
|
||||
use App\Services\Contact\Address\DestroyAddress;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\Address\Address as AddressResource;
|
||||
|
||||
class ApiAddressController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of addresses.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$addresses = auth()->user()->account->addresses()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return AddressResource::collection($addresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return AddressResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$address = Address::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new AddressResource($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return AddressResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$address = app(CreateAddress::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new AddressResource($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $addressId
|
||||
* @return AddressResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $addressId)
|
||||
{
|
||||
try {
|
||||
$address = app(UpdateAddress::class)->execute(
|
||||
$request->except(['account_id', 'address_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'address_id' => $addressId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new AddressResource($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an address.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $addressId)
|
||||
{
|
||||
try {
|
||||
app(DestroyAddress::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'address_id' => $addressId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($addressId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of addresses for the given contact.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function addresses(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $contactId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
$addresses = $contact->addresses()
|
||||
->paginate($this->getLimitPerPage());
|
||||
|
||||
return AddressResource::collection($addresses);
|
||||
}
|
||||
}
|
||||
42
app/Http/Controllers/Api/Contact/ApiAuditLogController.php
Normal file
42
app/Http/Controllers/Api/Contact/ApiAuditLogController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\AuditLog\AuditLog as AuditLogResource;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
|
||||
class ApiAuditLogController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of the audit logs for the given contact.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $contactId
|
||||
* @return JsonResponse|AnonymousResourceCollection
|
||||
*/
|
||||
public function index(Request $request, int $contactId)
|
||||
{
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $contactId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$logs = $contact->logs()
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return AuditLogResource::collection($logs);
|
||||
}
|
||||
}
|
||||
43
app/Http/Controllers/Api/Contact/ApiAvatarController.php
Normal file
43
app/Http/Controllers/Api/Contact/ApiAvatarController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use App\Services\Contact\Avatar\UpdateAvatar;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\Contact\Contact as ContactResource;
|
||||
|
||||
class ApiAvatarController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Update a contact's avatar.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $contactId
|
||||
* @return ContactResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
$contact = app(UpdateAvatar::class)->execute(
|
||||
$request->except(['account_id', 'contact_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'contact_id' => $contactId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new ContactResource($contact);
|
||||
}
|
||||
}
|
||||
162
app/Http/Controllers/Api/Contact/ApiCallController.php
Normal file
162
app/Http/Controllers/Api/Contact/ApiCallController.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use App\Models\Contact\Call;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helpers\AccountHelper;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Services\Contact\Call\CreateCall;
|
||||
use App\Services\Contact\Call\UpdateCall;
|
||||
use App\Services\Contact\Call\DestroyCall;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Http\Resources\Call\Call as CallResource;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiCallController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of calls.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$calls = auth()->user()->account->calls()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return CallResource::collection($calls)->additional(['meta' => [
|
||||
'statistics' => AccountHelper::getYearlyCallStatistics(auth()->user()->account),
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given call.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return CallResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $callId)
|
||||
{
|
||||
try {
|
||||
$call = Call::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $callId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new CallResource($call);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the call.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return CallResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$call = app(CreateCall::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new CallResource($call);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a call.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $callId
|
||||
* @return CallResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $callId)
|
||||
{
|
||||
try {
|
||||
$call = app(UpdateCall::class)->execute(
|
||||
$request->except(['account_id', 'call_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'call_id' => $callId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new CallResource($call);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a call.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $callId)
|
||||
{
|
||||
try {
|
||||
app(DestroyCall::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'call_id' => $callId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($callId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of calls for a given contact.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function calls(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $contactId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
$calls = $contact->calls()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
|
||||
return CallResource::collection($calls)->additional(['meta' => [
|
||||
'statistics' => AccountHelper::getYearlyCallStatistics(auth()->user()->account),
|
||||
]]);
|
||||
}
|
||||
}
|
||||
162
app/Http/Controllers/Api/Contact/ApiConversationController.php
Normal file
162
app/Http/Controllers/Api/Contact/ApiConversationController.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Conversation;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Contact\Conversation\CreateConversation;
|
||||
use App\Services\Contact\Conversation\UpdateConversation;
|
||||
use App\Services\Contact\Conversation\DestroyConversation;
|
||||
use App\Http\Resources\Conversation\Conversation as ConversationResource;
|
||||
|
||||
class ApiConversationController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of conversations.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$conversations = auth()->user()->account->conversations()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return ConversationResource::collection($conversations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of conversations for a specific contact.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function conversations(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $contactId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$conversations = auth()->user()->account->conversations()
|
||||
->where('contact_id', $contactId)
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return ConversationResource::collection($conversations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given conversation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return ConversationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $conversationId)
|
||||
{
|
||||
try {
|
||||
$conversation = Conversation::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($conversationId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new ConversationResource($conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the conversation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return ConversationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$conversation = app(CreateConversation::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new ConversationResource($conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the conversation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $conversationId
|
||||
* @return ConversationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $conversationId)
|
||||
{
|
||||
try {
|
||||
$conversation = app(UpdateConversation::class)->execute(
|
||||
$request->except(['account_id', 'conversation_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'conversation_id' => $conversationId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new ConversationResource($conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the conversation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $conversationId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $conversationId)
|
||||
{
|
||||
try {
|
||||
app(DestroyConversation::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'conversation_id' => $conversationId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($conversationId);
|
||||
}
|
||||
}
|
||||
146
app/Http/Controllers/Api/Contact/ApiDocumentController.php
Normal file
146
app/Http/Controllers/Api/Contact/ApiDocumentController.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Document;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\Document\UploadDocument;
|
||||
use App\Services\Contact\Document\DestroyDocument;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\Document\Document as DocumentResource;
|
||||
|
||||
class ApiDocumentController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('limitations')->only('store');
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of documents.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$documents = auth()->user()->account->documents()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return DocumentResource::collection($documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of documents for a specific contact.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function contact(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
Contact::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($contactId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$documents = auth()->user()->account->documents()
|
||||
->where('contact_id', $contactId)
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return DocumentResource::collection($documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given document.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $documentId
|
||||
* @return DocumentResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $documentId)
|
||||
{
|
||||
try {
|
||||
$document = Document::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($documentId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new DocumentResource($document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a document.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return DocumentResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$document = app(UploadDocument::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new DocumentResource($document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a document.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $documentId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $documentId)
|
||||
{
|
||||
try {
|
||||
app(DestroyDocument::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'document_id' => $documentId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($documentId);
|
||||
}
|
||||
}
|
||||
121
app/Http/Controllers/Api/Contact/ApiLifeEventController.php
Normal file
121
app/Http/Controllers/Api/Contact/ApiLifeEventController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\LifeEvent;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\LifeEvent\CreateLifeEvent;
|
||||
use App\Services\Contact\LifeEvent\UpdateLifeEvent;
|
||||
use App\Services\Contact\LifeEvent\DestroyLifeEvent;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\LifeEvent\LifeEvent as LifeEventResource;
|
||||
|
||||
class ApiLifeEventController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of life events.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$lifeEvents = auth()->user()->account->lifeEvents()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
|
||||
return LifeEventResource::collection($lifeEvents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given life event.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return LifeEventResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $lifeEventId)
|
||||
{
|
||||
try {
|
||||
$lifeEvent = LifeEvent::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($lifeEventId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new LifeEventResource($lifeEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the life event.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return LifeEventResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$lifeEvent = app(CreateLifeEvent::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
}
|
||||
|
||||
return new LifeEventResource($lifeEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the life event.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $lifeEventId
|
||||
* @return LifeEventResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $lifeEventId)
|
||||
{
|
||||
try {
|
||||
$lifeEvent = app(UpdateLifeEvent::class)->execute(
|
||||
$request->except(['account_id', 'life_event_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'life_event_id' => $lifeEventId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
}
|
||||
|
||||
return new LifeEventResource($lifeEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the life event.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $lifeEventId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $lifeEventId)
|
||||
{
|
||||
try {
|
||||
app(DestroyLifeEvent::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'life_event_id' => $lifeEventId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($lifeEventId);
|
||||
}
|
||||
}
|
||||
126
app/Http/Controllers/Api/Contact/ApiMessageController.php
Normal file
126
app/Http/Controllers/Api/Contact/ApiMessageController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Message;
|
||||
use App\Models\Contact\Conversation;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\Conversation\UpdateMessage;
|
||||
use App\Services\Contact\Conversation\DestroyMessage;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Contact\Conversation\AddMessageToConversation;
|
||||
use App\Http\Resources\Conversation\Conversation as ConversationResource;
|
||||
|
||||
class ApiMessageController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Store the message.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return ConversationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request, int $conversationId)
|
||||
{
|
||||
try {
|
||||
$conversation = Conversation::findOrFail($conversationId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
app(AddMessageToConversation::class)->execute(
|
||||
$request->except(['account_id', 'conversation_id', 'contact_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'conversation_id' => $conversation->id,
|
||||
'contact_id' => $conversation->contact_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new ConversationResource($conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the message.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $conversationId
|
||||
* @param int $messageId
|
||||
* @return ConversationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, int $conversationId, int $messageId)
|
||||
{
|
||||
try {
|
||||
$conversation = Conversation::findOrFail($conversationId);
|
||||
$message = Message::findOrFail($messageId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
app(UpdateMessage::class)->execute(
|
||||
$request->except(['account_id', 'conversation_id', 'message_id', 'contact_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'conversation_id' => $conversationId,
|
||||
'message_id' => $message->id,
|
||||
'contact_id' => $conversation->contact_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new ConversationResource($conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the message.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $conversationId
|
||||
* @param int $messageId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $conversationId, int $messageId)
|
||||
{
|
||||
try {
|
||||
Conversation::findOrFail($conversationId);
|
||||
Message::findOrFail($messageId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
app(DestroyMessage::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'conversation_id' => $conversationId,
|
||||
'message_id' => $messageId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($messageId);
|
||||
}
|
||||
}
|
||||
134
app/Http/Controllers/Api/Contact/ApiOccupationController.php
Normal file
134
app/Http/Controllers/Api/Contact/ApiOccupationController.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contact\Occupation;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Services\Contact\Occupation\CreateOccupation;
|
||||
use App\Services\Contact\Occupation\UpdateOccupation;
|
||||
use App\Services\Contact\Occupation\DestroyOccupation;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Http\Resources\Occupation\Occupation as OccupationResource;
|
||||
|
||||
class ApiOccupationController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of occupations.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$occupations = auth()->user()->account->occupations()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return OccupationResource::collection($occupations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given occupation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return OccupationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $occupationId)
|
||||
{
|
||||
try {
|
||||
$occupation = Occupation::where('account_id', auth()->user()->account_id)
|
||||
->where('id', $occupationId)
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new OccupationResource($occupation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the occupation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return OccupationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$occupation = app(CreateOccupation::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new OccupationResource($occupation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an occupation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $occupationId
|
||||
* @return OccupationResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, $occupationId)
|
||||
{
|
||||
try {
|
||||
$occupation = app(UpdateOccupation::class)->execute(
|
||||
$request->except(['account_id', 'occupation_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'occupation_id' => $occupationId,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new OccupationResource($occupation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an occupation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $occupationId)
|
||||
{
|
||||
try {
|
||||
app(DestroyOccupation::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'occupation_id' => $occupationId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($occupationId);
|
||||
}
|
||||
}
|
||||
134
app/Http/Controllers/Api/Contact/ApiPhotoController.php
Normal file
134
app/Http/Controllers/Api/Contact/ApiPhotoController.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Contact;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Account\Photo;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
use App\Services\Account\Photo\UploadPhoto;
|
||||
use App\Services\Account\Photo\DestroyPhoto;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Http\Resources\Photo\Photo as PhotoResource;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiPhotoController extends ApiController
|
||||
{
|
||||
/**
|
||||
* Get the list of photos.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$photos = auth()->user()->account->photos()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return PhotoResource::collection($photos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of photos for a specific contact.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function contact(Request $request, $contactId)
|
||||
{
|
||||
try {
|
||||
$contact = Contact::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($contactId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$photos = $contact->photos()
|
||||
->orderBy($this->sort, $this->sortDirection)
|
||||
->paginate($this->getLimitPerPage());
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return PhotoResource::collection($photos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detail of a given photo.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $photoId
|
||||
* @return PhotoResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Request $request, $photoId)
|
||||
{
|
||||
try {
|
||||
$photo = Photo::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($photoId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
}
|
||||
|
||||
return new PhotoResource($photo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a photo.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return PhotoResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$photo = app(UploadPhoto::class)->execute(
|
||||
$request->except(['account_id'])
|
||||
+
|
||||
[
|
||||
'account_id' => auth()->user()->account_id,
|
||||
]
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return new PhotoResource($photo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a photo.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $photoId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(Request $request, int $photoId)
|
||||
{
|
||||
try {
|
||||
app(DestroyPhoto::class)->execute([
|
||||
'account_id' => auth()->user()->account_id,
|
||||
'photo_id' => $photoId,
|
||||
]);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->respondNotFound();
|
||||
} catch (ValidationException $e) {
|
||||
return $this->respondValidatorFailed($e->validator);
|
||||
} catch (QueryException $e) {
|
||||
return $this->respondInvalidQuery();
|
||||
}
|
||||
|
||||
return $this->respondObjectDeleted($photoId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user