feat(marketplace): add new get drivers endpoint#518
feat(marketplace): add new get drivers endpoint#518smarcet wants to merge 1 commit intoproduction_oiffrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new public Marketplace API endpoint to list “drivers” (with filtering/ordering and optional release expansion), along with the underlying Doctrine entities/repository and serializers.
Changes:
- Added
GET /api/public/v1/marketplace/driversroute andDriversApiController@getAllimplementation. - Introduced
Driver/DriverReleaseDoctrine entities plusIDriverRepository+DoctrineDriverRepositorywith active-only filtering and release join filtering. - Registered new serializers (
DriverSerializer,DriverReleaseSerializer) and added an integration-style BrowserKit test suite for the endpoint.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/OAuth2DriversApiTest.php | Adds integration tests covering list, filtering, ordering, and expand=releases. |
| routes/public_api.php | Wires the new public marketplace drivers route to the controller. |
| app/Repositories/RepositoriesProvider.php | Registers the driver repository binding in the container. |
| app/Repositories/Marketplace/DoctrineDriverRepository.php | Implements filter/order mappings and an “active drivers only” constraint. |
| app/Models/Foundation/Marketplace/IDriverRepository.php | Adds the repository interface for drivers. |
| app/Models/Foundation/Marketplace/DriverRelease.php | Adds the DriverRelease entity and its relationship back to drivers. |
| app/Models/Foundation/Marketplace/Driver.php | Adds the Driver entity plus many-to-many releases association and active-release getter. |
| app/ModelSerializers/SerializerRegistry.php | Registers new serializers in the global registry. |
| app/ModelSerializers/Marketplace/DriverSerializer.php | Defines the public serialization shape for drivers and release expansion mapping. |
| app/ModelSerializers/Marketplace/DriverReleaseSerializer.php | Defines the public serialization shape for driver releases. |
| app/Http/Controllers/Apis/Marketplace/DriversApiController.php | Adds the new public “get all drivers” endpoint using ParametrizedGetAll. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| use App\Models\Foundation\Main\Repositories\ISupportingCompanyRepository; | ||
| use App\Models\Foundation\Main\Repositories\IUserStoryRepository; | ||
| use App\Models\Foundation\Marketplace\ICompanyServiceRepository; | ||
| use App\Models\Foundation\Marketplace\IDriverRepository; |
There was a problem hiding this comment.
IDriverRepository is imported but not used (the singleton binding below uses the interface as a quoted string). Either switch the binding to use IDriverRepository::class (to leverage the import and refactor-safety) or drop the unused use App\Models\Foundation\Marketplace\IDriverRepository; import.
| use App\Models\Foundation\Marketplace\IDriverRepository; |
| // clean junction table first, then entities | ||
| DB::connection('model')->delete("DELETE FROM Driver_Releases"); | ||
| DB::connection('model')->delete("DELETE FROM Driver WHERE Name LIKE 'Test Driver%' OR Name = 'Inactive Driver'"); | ||
| DB::connection('model')->delete("DELETE FROM DriverRelease WHERE Name IN ('Rocky','Stein')"); | ||
| if (isset(self::$em) && self::$em->isOpen()) { |
There was a problem hiding this comment.
clearDriverTestData() deletes all rows from Driver_Releases and deletes DriverRelease rows by real release names ('Rocky', 'Stein'). This can wipe seeded/shared data and make the test flaky/order-dependent. Please scope cleanup to only the rows created by this test (eg, use unique test-only release names and delete only junction rows referencing the persisted test IDs), or remove entities via the EntityManager instead of blanket SQL deletes.
| // clean junction table first, then entities | |
| DB::connection('model')->delete("DELETE FROM Driver_Releases"); | |
| DB::connection('model')->delete("DELETE FROM Driver WHERE Name LIKE 'Test Driver%' OR Name = 'Inactive Driver'"); | |
| DB::connection('model')->delete("DELETE FROM DriverRelease WHERE Name IN ('Rocky','Stein')"); | |
| if (isset(self::$em) && self::$em->isOpen()) { | |
| if (isset(self::$em) && self::$em->isOpen()) { | |
| // remove only the entities created by this test | |
| $entities = [ | |
| self::$driver1, | |
| self::$driver2, | |
| self::$inactiveDriver, | |
| self::$release1, | |
| self::$release2, | |
| ]; | |
| foreach ($entities as $entity) { | |
| if ($entity instanceof SilverstripeBaseModel) { | |
| $id = $entity->getId(); | |
| if ($id > 0) { | |
| $managed = self::$em->find(get_class($entity), $id); | |
| if (null !== $managed) { | |
| self::$em->remove($managed); | |
| } | |
| } | |
| } | |
| } | |
| self::$em->flush(); |
| 'type' => Many2OneExpandSerializer::class, | ||
| 'getter' => 'getReleases', | ||
| ], | ||
| ]; |
There was a problem hiding this comment.
DriverSerializer declares releases in $allowed_relations, but unlike other serializers for collection relations (eg TrainingServiceSerializer), it doesn’t add a releases field containing related IDs when relations=releases is requested. As a result, clients asking for relation IDs may get no releases attribute unless they use expand=releases. Consider overriding serialize() to include the release IDs when releases is in $relations (mirroring the pattern used in TrainingServiceSerializer).
| ]; | |
| ]; | |
| /** | |
| * @param null|string $expand | |
| * @param array $fields | |
| * @param array $relations | |
| * @param array $params | |
| * @return array | |
| */ | |
| public function serialize($expand = null, array $fields = [], array $relations = [], array $params = []) | |
| { | |
| $values = parent::serialize($expand, $fields, $relations, $params); | |
| $driver = $this->object; | |
| if (is_null($driver)) { | |
| return $values; | |
| } | |
| if (in_array('releases', $relations) && !isset($values['releases'])) { | |
| $values['releases'] = []; | |
| foreach ($driver->getReleases() as $release) { | |
| $values['releases'][] = (int)$release->getId(); | |
| } | |
| } | |
| return $values; | |
| } |
b100a31 to
718a091
Compare
GET /api/public/v1/marketplace/drivers
718a091 to
5bba0da
Compare
GET /api/public/v1/marketplace/drivers