mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge branch 'develop' of github.com:invoiceninja/invoiceninja into develop
This commit is contained in:
commit
7b2f46b087
@ -38,11 +38,12 @@ use Utils;
|
||||
* description="Find out more about Invoice Ninja",
|
||||
* url="https://www.invoiceninja.com"
|
||||
* ),
|
||||
* security={"api_key": {}},
|
||||
* @SWG\SecurityScheme(
|
||||
* securityDefinition="api_key",
|
||||
* type="apiKey",
|
||||
* in="header",
|
||||
* name="TOKEN"
|
||||
* name="X-Ninja-Token"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
179
app/Http/Controllers/ContactApiController.php
Normal file
179
app/Http/Controllers/ContactApiController.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ContactRequest;
|
||||
use App\Http\Requests\CreateContactRequest;
|
||||
use App\Http\Requests\UpdateContactRequest;
|
||||
use App\Models\Contact;
|
||||
use App\Ninja\Repositories\ContactRepository;
|
||||
use Input;
|
||||
use Response;
|
||||
use Utils;
|
||||
|
||||
class ContactApiController extends BaseAPIController
|
||||
{
|
||||
protected $contactRepo;
|
||||
|
||||
protected $entityType = ENTITY_CONTACT;
|
||||
|
||||
public function __construct(ContactRepository $contactRepo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->contactRepo = $contactRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Get(
|
||||
* path="/contacts",
|
||||
* summary="List contacts",
|
||||
* tags={"contact"},
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="A list of contacts",
|
||||
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Contact"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$contacts = Contact::scope()
|
||||
->withTrashed()
|
||||
->orderBy('created_at', 'desc');
|
||||
|
||||
return $this->listResponse($contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Get(
|
||||
* path="/contacts/{contact_id}",
|
||||
* summary="Retrieve a contact",
|
||||
* tags={"contact"},
|
||||
* @SWG\Parameter(
|
||||
* in="path",
|
||||
* name="contact_id",
|
||||
* type="integer",
|
||||
* required=true
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="A single contact",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Contact"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function show(ContactRequest $request)
|
||||
{
|
||||
return $this->itemResponse($request->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Post(
|
||||
* path="/contacts",
|
||||
* tags={"contact"},
|
||||
* summary="Create a contact",
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="contact",
|
||||
* @SWG\Schema(ref="#/definitions/Contact")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="New contact",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Contact"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function store(CreateContactRequest $request)
|
||||
{
|
||||
$contact = $this->contactRepo->save($request->input());
|
||||
|
||||
return $this->itemResponse($contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Put(
|
||||
* path="/contacts/{contact_id}",
|
||||
* tags={"contact"},
|
||||
* summary="Update a contact",
|
||||
* @SWG\Parameter(
|
||||
* in="path",
|
||||
* name="contact_id",
|
||||
* type="integer",
|
||||
* required=true
|
||||
* ),
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="contact",
|
||||
* @SWG\Schema(ref="#/definitions/Contact")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Updated contact",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Contact"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @param mixed $publicId
|
||||
*/
|
||||
public function update(UpdateContactRequest $request, $publicId)
|
||||
{
|
||||
if ($request->action) {
|
||||
return $this->handleAction($request);
|
||||
}
|
||||
|
||||
$data = $request->input();
|
||||
$data['public_id'] = $publicId;
|
||||
$expense = $this->contactRepo->save($data, $request->entity());
|
||||
|
||||
return $this->itemResponse($contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Delete(
|
||||
* path="/contacts/{contact_id}",
|
||||
* tags={"contact"},
|
||||
* summary="Delete a contact",
|
||||
* @SWG\Parameter(
|
||||
* in="path",
|
||||
* name="contact_id",
|
||||
* type="integer",
|
||||
* required=true
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Deleted contact",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Contact"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function destroy(UpdateContactRequest $request)
|
||||
{
|
||||
$contact = $request->entity();
|
||||
|
||||
$this->contactRepo->delete($contact);
|
||||
|
||||
return $this->itemResponse($contact);
|
||||
}
|
||||
}
|
8
app/Http/Requests/ContactRequest.php
Normal file
8
app/Http/Requests/ContactRequest.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class ContactRequest extends EntityRequest
|
||||
{
|
||||
protected $entityType = ENTITY_CONTACT;
|
||||
}
|
30
app/Http/Requests/CreateContactRequest.php
Normal file
30
app/Http/Requests/CreateContactRequest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class CreateContactRequest extends ContactRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->user()->can('create', ENTITY_CONTACT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
30
app/Http/Requests/UpdateContactRequest.php
Normal file
30
app/Http/Requests/UpdateContactRequest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class UpdateContactRequest extends ContactRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->user()->can('edit', $this->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
@ -307,6 +307,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function () {
|
||||
Route::get('accounts', 'AccountApiController@show');
|
||||
Route::put('accounts', 'AccountApiController@update');
|
||||
Route::resource('clients', 'ClientApiController');
|
||||
Route::resource('contacts', 'ContactApiController');
|
||||
Route::get('quotes', 'QuoteApiController@index');
|
||||
Route::get('download/{invoice_id}', 'InvoiceApiController@download');
|
||||
Route::resource('invoices', 'InvoiceApiController');
|
||||
|
@ -6,6 +6,8 @@ use App\Models\Contact;
|
||||
|
||||
/**
|
||||
* Class ContactTransformer.
|
||||
*
|
||||
* @SWG\Definition(definition="Contact", @SWG\Xml(name="Contact"))
|
||||
*/
|
||||
class ContactTransformer extends EntityTransformer
|
||||
{
|
||||
@ -13,6 +15,17 @@ class ContactTransformer extends EntityTransformer
|
||||
* @param Contact $contact
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
||||
* @SWG\Property(property="first_name", type="string", example="John")
|
||||
* @SWG\Property(property="last_name", type="string", example="Doe")
|
||||
* @SWG\Property(property="email", type="string", example="john.doe@company.com")
|
||||
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
|
||||
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
|
||||
* @SWG\Property(property="is_primary", type="boolean", example=false)
|
||||
* @SWG\Property(property="phone", type="string", example="(212) 555-1212")
|
||||
* @SWG\Property(property="last_login", type="string", format="date-time", example="2016-01-01 12:10:00")
|
||||
* @SWG\Property(property="send_invoice", type="boolean", example=false)
|
||||
*/
|
||||
public function transform(Contact $contact)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user