Skip to content

Commit

Permalink
feat(contacts): contact groups api
Browse files Browse the repository at this point in the history
  • Loading branch information
virgiawanly committed Nov 9, 2024
1 parent 463964c commit 02d1a4c
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 3 deletions.
44 changes: 44 additions & 0 deletions app/Http/Controllers/WebApp/Contact/ContactGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers\WebApp\Contact;

use App\Http\Controllers\BaseResourceController;
use App\Http\Requests\WebApp\Contact\CreateContactGroupRequest;
use App\Http\Requests\WebApp\Contact\UpdateContactGroupRequest;
use App\Services\Contact\ContactGroupService;

class ContactGroupController extends BaseResourceController
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(protected ContactGroupService $contactGroupService)
{
parent::__construct($contactGroupService->repository);
}

/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\WebApp\Contact\CreateContactGroupRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function store(CreateContactGroupRequest $request)
{
return parent::save($request);
}

/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\WebApp\Contact\UpdateContactGroupRequest $request
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function update(UpdateContactGroupRequest $request, int $id)
{
return parent::patch($request, $id);
}
}
42 changes: 42 additions & 0 deletions app/Http/Requests/WebApp/Contact/CreateContactGroupRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Requests\WebApp\Contact;

use Illuminate\Foundation\Http\FormRequest;

class CreateContactGroupRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'business_entity_id' => ['required'],
'name' => ['required', 'max:255'],
];
}

/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'business_entity_id' => trans('validation.attributes.business_entity'),
'name' => trans('validation.attributes.name'),
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/WebApp/Contact/CreateContactRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function rules(): array
public function attributes(): array
{
return [
'business_entity_id' => 'business entity',
'contact_group_id' => 'contact group',
'business_entity_id' => trans('validation.attributes.business_entity'),
'contact_group_id' => trans('validation.attributes.contact_group'),
];
}
}
42 changes: 42 additions & 0 deletions app/Http/Requests/WebApp/Contact/UpdateContactGroupRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Requests\WebApp\Contact;

use Illuminate\Foundation\Http\FormRequest;

class UpdateContactGroupRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'business_entity_id' => ['required'],
'name' => ['required', 'max:255'],
];
}

/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'business_entity_id' => trans('validation.attributes.business_entity'),
'name' => trans('validation.attributes.name'),
];
}
}
13 changes: 13 additions & 0 deletions app/Http/Requests/WebApp/Contact/UpdateContactRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ public function rules(): array
'accounts_receivable_id' => ['nullable'],
];
}

/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'business_entity_id' => trans('validation.attributes.business_entity'),
'contact_group_id' => trans('validation.attributes.contact_group'),
];
}
}
8 changes: 8 additions & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace App\Providers;

use App\Repositories\BusinessRepository;
use App\Repositories\ContactGroupRepository;
use App\Repositories\ContactRepository;
use App\Repositories\Interfaces\BusinessRepositoryInterface;
use App\Repositories\Interfaces\ContactGroupRepositoryInterface;
use App\Repositories\Interfaces\ContactRepositoryInterface;
use App\Repositories\Interfaces\UserRepositoryInterface;
use App\Repositories\UserRepository;
use App\Services\Auth\LoginService;
use App\Services\Auth\RegistrationService;
use App\Services\Contact\ContactGroupService;
use App\Services\Contact\ContactService;
use Illuminate\Support\ServiceProvider;

Expand All @@ -34,6 +37,11 @@ public function register(): void
);
});

$this->app->bind(ContactGroupRepositoryInterface::class, ContactGroupRepository::class);
$this->app->bind(ContactGroupService::class, function ($app) {
return new ContactGroupService($app->make(ContactGroupRepositoryInterface::class));
});

$this->app->bind(ContactRepositoryInterface::class, ContactRepository::class);
$this->app->bind(ContactService::class, function ($app) {
return new ContactService($app->make(ContactRepositoryInterface::class));
Expand Down
19 changes: 19 additions & 0 deletions app/Repositories/ContactGroupRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Repositories;

use App\Models\ContactGroup;
use App\Repositories\Interfaces\ContactGroupRepositoryInterface;

class ContactGroupRepository extends BaseResourceRepository implements ContactGroupRepositoryInterface
{
/**
* Create a new repository instance.
*
* @return void
*/
public function __construct()
{
$this->model = new ContactGroup();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace App\Repositories\Interfaces;

interface ContactGroupRepositoryInterface extends BaseResourceRepositoryInterface {}
20 changes: 20 additions & 0 deletions app/Services/Contact/ContactGroupService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Services\Contact;

use App\Repositories\Interfaces\ContactGroupRepositoryInterface;
use App\Services\BaseResourceService;

class ContactGroupService extends BaseResourceService
{
/**
* Create a new service instance.
*
* @param \App\Repositories\Interfaces\ContactGroupRepositoryInterface $repository
* @return void
*/
public function __construct(ContactGroupRepositoryInterface $repository)
{
$this->repository = $repository;
}
}
6 changes: 5 additions & 1 deletion lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
|
*/

'attributes' => [],
'attributes' => [
'name' => 'name',
'business_entity' => 'business entity',
'contact_group' => 'contact group',
],

];
2 changes: 2 additions & 0 deletions routes/api/web-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Http\Controllers\WebApp\Auth\LoginController;
use App\Http\Controllers\WebApp\Auth\RegistrationController;
use App\Http\Controllers\WebApp\Contact\ContactController;
use App\Http\Controllers\WebApp\Contact\ContactGroupController;
use Illuminate\Support\Facades\Route;

Route::prefix('auth')->group(function () {
Expand All @@ -11,5 +12,6 @@
});

Route::middleware('auth:sanctum')->group(function () {
Route::apiResource('contact-groups', ContactGroupController::class);
Route::apiResource('contacts', ContactController::class);
});

0 comments on commit 02d1a4c

Please sign in to comment.