-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/api endpoints refactor (#1203)
* working groups mostly * groups fully working * cleaning up * feat: add update function to GroupController * feat: add updateGroup method to ConfigData model * passing tests * working updates * update group test * lint fixes * thorough group page testing * check for an empty dropdown * service body call handling * lint fix * cypress tests for call handling * wip * lint fixes * wip * update servicebody call handling tests * update service body call handling test * adding volunteer api tests * adding group volunteer tests * configure volunteers for groups * reset primary key ids between tests * lint fix * volunteers cypress tests * updating release notes * fixing issue with group name in volunteer list * reset database capability after each cypress test file * using seeders * silence logs from webserver * try again to run database reset * make tests pass for now
- Loading branch information
Showing
45 changed files
with
1,421 additions
and
302 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
.DS_Store | ||
.aider* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\ConfigData; | ||
use App\Services\VolunteerService; | ||
use App\Structures\Group; | ||
use Illuminate\Http\Request; | ||
use stdClass; | ||
|
||
class GroupController extends Controller | ||
{ | ||
protected VolunteerService $volunteerService; | ||
|
||
public function __construct(VolunteerService $volunteerService) | ||
{ | ||
$this->volunteerService = $volunteerService; | ||
} | ||
|
||
private function getGroupsData(int $serviceBodyId, bool $manage = false) | ||
{ | ||
$data = $this->volunteerService->getGroupsForServiceBody( | ||
$serviceBodyId, | ||
$manage | ||
); | ||
|
||
$results = []; | ||
|
||
foreach ($data as $item) { | ||
$results[] = [ | ||
'service_body_id' => $item->service_body_id, | ||
'id' => $item->id, | ||
'parent_id' => null, | ||
'data' => json_decode($item->data) | ||
]; | ||
} | ||
|
||
return $results; | ||
} | ||
|
||
public function index(Request $request) | ||
{ | ||
$groupsData = $this | ||
->getGroupsData(intval($request->get("serviceBodyId")), boolval($request->get("manage") ?? false)); | ||
return response()->json($groupsData)->header("Content-Type", "application/json"); | ||
} | ||
|
||
public function update(Request $request, $id) | ||
{ | ||
$decodedData = json_decode($request->getContent()); | ||
$groupData = new Group($decodedData); | ||
|
||
$group = ConfigData::updateGroup( | ||
$id, | ||
$groupData | ||
); | ||
|
||
$groupsData = $this->getGroupsData(intval($group->service_body_id)); | ||
return response()->json($groupsData)->header("Content-Type", "application/json"); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$decodedData = json_decode($request->getContent()); | ||
$groupData = new Group($decodedData); | ||
|
||
ConfigData::createGroup( | ||
$request->get('serviceBodyId'), | ||
$groupData | ||
); | ||
|
||
return self::index($request); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
$response = ConfigData::deleteGroup($id); | ||
if ($response === 1) { | ||
return response()->json(['message' => sprintf('Group %s deleted successfully', $id)]); | ||
} | ||
|
||
return response()->json(['message' => 'Not found'], 404); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/app/Http/Controllers/Api/V1/Admin/GroupVolunteerController.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,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\Admin; | ||
|
||
use App\Constants\DataType; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\ConfigData; | ||
use App\Services\VolunteerService; | ||
use Illuminate\Http\Request; | ||
use stdClass; | ||
|
||
class GroupVolunteerController extends Controller | ||
{ | ||
protected VolunteerService $volunteerService; | ||
|
||
public function __construct(VolunteerService $volunteerService) | ||
{ | ||
$this->volunteerService = $volunteerService; | ||
} | ||
|
||
public function index(Request $request) | ||
{ | ||
$data = ConfigData::getGroupVolunteers($request->get("groupId")); | ||
|
||
if (count($data) > 0) { | ||
return response()->json([ | ||
'service_body_id' => $data[0]->service_body_id, | ||
'id' => $data[0]->id, | ||
'parent_id' => $data[0]->parent_id ?? null, | ||
'data' => json_decode($data[0]->data) | ||
])->header("Content-Type", "application/json"); | ||
} else { | ||
return response()->json(new stdClass())->header("Content-Type", "application/json"); | ||
} | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$volunteers = json_decode($request->getContent()); | ||
$groupId = $request->get('groupId'); | ||
$serviceBodyId = $request->get('serviceBodyId') ?? null; | ||
|
||
$existingRecord = ConfigData::where('parent_id', $groupId) | ||
->where('data_type', DataType::YAP_GROUP_VOLUNTEERS_V2) | ||
->first(); | ||
|
||
if ($existingRecord) { | ||
// If the record exists, update it | ||
ConfigData::updateGroupVolunteers($groupId, $volunteers); | ||
} else { | ||
// Otherwise, create a new record | ||
ConfigData::createGroupVolunteers($serviceBodyId, $groupId, $volunteers); | ||
} | ||
|
||
return self::index($request); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/app/Http/Controllers/Api/V1/Admin/ServiceBodyCallHandlingController.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,59 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1\Admin; | ||
|
||
use App\Constants\DataType; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\ConfigData; | ||
use App\Structures\ServiceBodyCallHandling; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use stdClass; | ||
|
||
class ServiceBodyCallHandlingController extends Controller | ||
{ | ||
protected ConfigData $configData; | ||
|
||
public function __construct(ConfigData $configData) | ||
{ | ||
$this->configData = $configData; | ||
} | ||
|
||
public function index(Request $request): JsonResponse | ||
{ | ||
$data = ConfigData::getCallHandling($request->get("serviceBodyId")); | ||
|
||
if (count($data) > 0) { | ||
return response()->json([ | ||
'service_body_id' => $data[0]->service_body_id, | ||
'id' => $data[0]->id, | ||
'parent_id' => null, | ||
'data' => json_decode($data[0]->data) | ||
])->header("Content-Type", "application/json"); | ||
} else { | ||
return response()->json(new stdClass())->header("Content-Type", "application/json"); | ||
} | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$decodedData = json_decode($request->getContent()); | ||
$serviceBodyCallHandling = new ServiceBodyCallHandling($decodedData); | ||
|
||
$serviceBodyId = $request->get('serviceBodyId'); | ||
|
||
$existingRecord = ConfigData::where('service_body_id', $serviceBodyId) | ||
->where('data_type', DataType::YAP_CALL_HANDLING_V2) | ||
->first(); | ||
|
||
if ($existingRecord) { | ||
// If the record exists, update it | ||
ConfigData::updateServiceBodyCallHandling($request->get('serviceBodyId'), $serviceBodyCallHandling); | ||
} else { | ||
// Otherwise, create a new record | ||
ConfigData::createServiceBodyCallHandling($request->get('serviceBodyId'), $serviceBodyCallHandling); | ||
} | ||
|
||
return self::index($request); | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/app/Http/Controllers/Api/V1/Admin/VolunteerGroupsController.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.