-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow customization of life event types (#4243)
- Loading branch information
Showing
26 changed files
with
899 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
### New features: | ||
|
||
* | ||
* Allow customization of life event types | ||
|
||
### Enhancements: | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
app/Http/Controllers/Account/LifeEvent/LifeEventCategoriesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Account\LifeEvent; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Traits\JsonRespondController; | ||
|
||
class LifeEventCategoriesController extends Controller | ||
{ | ||
use JsonRespondController; | ||
|
||
/** | ||
* Get all the life event categories. | ||
*/ | ||
public function index() | ||
{ | ||
$lifeEventCategoriesData = collect([]); | ||
$lifeEventCategories = auth()->user()->account->lifeEventCategories; | ||
|
||
foreach ($lifeEventCategories as $lifeEventCategory) { | ||
$lifeEventTypesData = collect([]); | ||
$lifeEventTypes = $lifeEventCategory->lifeEventTypes; | ||
|
||
foreach ($lifeEventTypes as $lifeEventType) { | ||
$dataLifeEventType = [ | ||
'id' => $lifeEventType->id, | ||
'name' => $lifeEventType->name, | ||
'default_life_event_type_key' => $lifeEventType->default_life_event_type_key, | ||
]; | ||
$lifeEventTypesData->push($dataLifeEventType); | ||
} | ||
|
||
$data = [ | ||
'id' => $lifeEventCategory->id, | ||
'name' => $lifeEventCategory->name, | ||
'default_life_event_category_key' => $lifeEventCategory->default_life_event_category_key, | ||
'lifeEventTypes' => $lifeEventTypesData, | ||
]; | ||
$lifeEventCategoriesData->push($data); | ||
} | ||
|
||
return $lifeEventCategoriesData; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
app/Http/Controllers/Account/LifeEvent/LifeEventTypesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Account\LifeEvent; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Traits\JsonRespondController; | ||
use App\Services\Account\LifeEvent\LifeEventType\CreateLifeEventType; | ||
use App\Services\Account\LifeEvent\LifeEventType\UpdateLifeEventType; | ||
use App\Services\Account\LifeEvent\LifeEventType\DestroyLifeEventType; | ||
use App\Http\Resources\LifeEvent\LifeEventType as LifeEventTypeResource; | ||
|
||
class LifeEventTypesController extends Controller | ||
{ | ||
use JsonRespondController; | ||
|
||
/** | ||
* Store a life event type. | ||
* | ||
* @param Request $request | ||
* @return LifeEventTypeResource | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$type = app(CreateLifeEventType::class)->execute([ | ||
'account_id' => auth()->user()->account_id, | ||
'life_event_category_id' => $request->input('life_event_category_id'), | ||
'name' => $request->input('name'), | ||
]); | ||
|
||
return new LifeEventTypeResource($type); | ||
} | ||
|
||
/** | ||
* Update a life event type. | ||
* | ||
* @param Request $request | ||
* @param int $liveEventTypeId | ||
* @return LifeEventTypeResource | ||
*/ | ||
public function update(Request $request, $liveEventTypeId) | ||
{ | ||
$data = [ | ||
'account_id' => auth()->user()->account_id, | ||
'life_event_type_id' => $liveEventTypeId, | ||
'life_event_category_id' => $request->input('life_event_category_id'), | ||
'name' => $request->input('name'), | ||
]; | ||
|
||
$type = app(UpdateLifeEventType::class)->execute($data); | ||
|
||
return new LifeEventTypeResource($type); | ||
} | ||
|
||
/** | ||
* Delete the life event type. | ||
* | ||
* @param Request $request | ||
* @param int $lifeEventTypeId | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function destroy(Request $request, $lifeEventTypeId) | ||
{ | ||
$data = [ | ||
'account_id' => auth()->user()->account_id, | ||
'life_event_type_id' => $lifeEventTypeId, | ||
]; | ||
|
||
try { | ||
app(DestroyLifeEventType::class)->execute($data); | ||
} catch (\Exception $e) { | ||
return $this->respondNotFound(); | ||
} | ||
|
||
return $this->respondObjectDeleted($lifeEventTypeId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/Services/Account/LifeEvent/LifeEventType/CreateLifeEventType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Services\Account\LifeEvent\LifeEventType; | ||
|
||
use App\Services\BaseService; | ||
use App\Models\Contact\LifeEventType; | ||
use App\Models\Contact\LifeEventCategory; | ||
|
||
class CreateLifeEventType extends BaseService | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'account_id' => 'required|integer|exists:accounts,id', | ||
'life_event_category_id' => 'required|integer|exists:life_event_categories,id', | ||
'name' => 'required|string|max:255', | ||
]; | ||
} | ||
|
||
/** | ||
* Create a life event type. | ||
* | ||
* @param array $data | ||
* @return LifeEventType | ||
*/ | ||
public function execute(array $data): LifeEventType | ||
{ | ||
$this->validate($data); | ||
|
||
LifeEventCategory::where('account_id', $data['account_id']) | ||
->findOrFail($data['life_event_category_id']); | ||
|
||
$lifeEventType = LifeEventType::create([ | ||
'account_id' => $data['account_id'], | ||
'life_event_category_id' => $data['life_event_category_id'], | ||
'name' => $data['name'], | ||
'default_life_event_type_key' => null, | ||
'core_monica_data' => false, | ||
'specific_information_structure' => null, | ||
]); | ||
|
||
return LifeEventType::find($lifeEventType->id); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/Services/Account/LifeEvent/LifeEventType/DestroyLifeEventType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Services\Account\LifeEvent\LifeEventType; | ||
|
||
use App\Services\BaseService; | ||
use App\Models\Contact\LifeEventType; | ||
|
||
class DestroyLifeEventType extends BaseService | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'account_id' => 'required|integer|exists:accounts,id', | ||
'life_event_type_id' => 'required|integer|exists:life_event_types,id', | ||
]; | ||
} | ||
|
||
/** | ||
* Destroy a life event type. | ||
* | ||
* @param array $data | ||
* @return bool | ||
*/ | ||
public function execute(array $data): bool | ||
{ | ||
$this->validate($data); | ||
|
||
$lifeEventType = LifeEventType::where('account_id', $data['account_id']) | ||
->findOrFail($data['life_event_type_id']); | ||
|
||
$lifeEventType->delete(); | ||
|
||
return true; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/Services/Account/LifeEvent/LifeEventType/UpdateLifeEventType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Services\Account\LifeEvent\LifeEventType; | ||
|
||
use App\Services\BaseService; | ||
use App\Models\Contact\LifeEventType; | ||
use App\Models\Contact\LifeEventCategory; | ||
|
||
class UpdateLifeEventType extends BaseService | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'account_id' => 'required|integer|exists:accounts,id', | ||
'life_event_category_id' => 'required|integer|exists:life_event_categories,id', | ||
'life_event_type_id' => 'required|integer|exists:life_event_types,id', | ||
'name' => 'required|string|max:255', | ||
]; | ||
} | ||
|
||
/** | ||
* Update a life event type. | ||
* | ||
* @param array $data | ||
* @return LifeEventType | ||
*/ | ||
public function execute(array $data): LifeEventType | ||
{ | ||
$this->validate($data); | ||
|
||
LifeEventCategory::where('account_id', $data['account_id']) | ||
->findOrFail($data['life_event_category_id']); | ||
|
||
$lifeEventType = LifeEventType::where('account_id', $data['account_id']) | ||
->findOrFail($data['life_event_type_id']); | ||
|
||
$lifeEventType->update([ | ||
'life_event_category_id' => $data['life_event_category_id'], | ||
'name' => $data['name'], | ||
]); | ||
|
||
return $lifeEventType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
database/migrations/2020_05_31_091556_custom_life_event_types.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CustomLifeEventTypes extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('life_event_types', function (Blueprint $table) { | ||
$table->string('name')->nullable()->change(); | ||
}); | ||
|
||
DB::table('life_event_types') | ||
->update(['name' => null]); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.