akaunting 3.0 (the last dance)
This commit is contained in:
@ -4,12 +4,12 @@ namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Contact as Request;
|
||||
use App\Http\Resources\Common\Contact as Resource;
|
||||
use App\Jobs\Common\CreateContact;
|
||||
use App\Jobs\Common\DeleteContact;
|
||||
use App\Jobs\Common\UpdateContact;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Traits\Uploads;
|
||||
use App\Transformers\Common\Contact as Transformer;
|
||||
|
||||
class Contacts extends ApiController
|
||||
{
|
||||
@ -18,20 +18,20 @@ class Contacts extends ApiController
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$contacts = Contact::collect();
|
||||
|
||||
return $this->response->paginator($contacts, new Transformer());
|
||||
return Resource::collection($contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
@ -42,20 +42,20 @@ class Contacts extends ApiController
|
||||
$contact = Contact::where('email', $id)->first();
|
||||
}
|
||||
|
||||
return $this->item($contact, new Transformer());
|
||||
return new Resource($contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$contact = $this->dispatch(new CreateContact($request));
|
||||
|
||||
return $this->response->created(route('api.contacts.show', $contact->id), $this->item($contact, new Transformer()));
|
||||
return $this->created(route('api.contacts.show', $contact->id), new Resource($contact));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,42 +63,42 @@ class Contacts extends ApiController
|
||||
*
|
||||
* @param $contact
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Contact $contact, Request $request)
|
||||
{
|
||||
$contact = $this->dispatch(new UpdateContact($contact, $request));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
return new Resource($contact->fresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function enable(Contact $contact)
|
||||
{
|
||||
$contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
return new Resource($contact->fresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function disable(Contact $contact)
|
||||
{
|
||||
try {
|
||||
$contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
return new Resource($contact->fresh());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,16 +106,16 @@ class Contacts extends ApiController
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Contact $contact)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteContact($contact));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
$this->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user