diff --git a/config/lists/locations.xml b/config/lists/locations.xml new file mode 100644 index 0000000..b72bc73 --- /dev/null +++ b/config/lists/locations.xml @@ -0,0 +1,41 @@ + + + locations + + + + id + App\Entity\Location + + + + name + App\Entity\Location + + + + street + App\Entity\Location + + + + number + App\Entity\Location + + + + postalCode + App\Entity\Location + + + + city + App\Entity\Location + + + + countryCode + App\Entity\Location + + + diff --git a/config/packages/sulu_admin.yaml b/config/packages/sulu_admin.yaml index 30c2925..f8caeb1 100644 --- a/config/packages/sulu_admin.yaml +++ b/config/packages/sulu_admin.yaml @@ -18,6 +18,10 @@ sulu_admin: routes: list: app.get_event_registrations + locations: + routes: + list: app.get_locations + # Registering Selection Field Types in this section field_type_options: selection: diff --git a/config/routes_admin.yaml b/config/routes_admin.yaml index 5923813..f4c319f 100644 --- a/config/routes_admin.yaml +++ b/config/routes_admin.yaml @@ -15,3 +15,11 @@ app_event_registrations: name_prefix: app. options: expose: true + +app_locations: + type: rest + resource: App\Controller\Admin\LocationController + prefix: /admin/api + name_prefix: app. + options: + expose: true diff --git a/src/Admin/LocationAdmin.php b/src/Admin/LocationAdmin.php new file mode 100644 index 0000000..f713a57 --- /dev/null +++ b/src/Admin/LocationAdmin.php @@ -0,0 +1,51 @@ +viewBuilderFactory = $viewBuilderFactory; + } + + public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void + { + $module = $navigationItemCollection->get('app.events'); + + $locations = new NavigationItem('app.locations'); + $locations->setPosition(10); + $locations->setView(static::LOCATION_LIST_VIEW); + + $module->addChild($locations); + } + + public function configureViews(ViewCollection $viewCollection): void + { + $listView = $this->viewBuilderFactory->createListViewBuilder(self::LOCATION_LIST_VIEW, '/locations') + ->setResourceKey(Location::RESOURCE_KEY) + ->setListKey(self::LOCATION_LIST_KEY) + ->setTitle('app.locations') + ->addListAdapters(['table']) + ->addToolbarActions([]); + $viewCollection->add($listView); + } +} diff --git a/src/Controller/Admin/LocationController.php b/src/Controller/Admin/LocationController.php new file mode 100644 index 0000000..e363610 --- /dev/null +++ b/src/Controller/Admin/LocationController.php @@ -0,0 +1,40 @@ +doctrineListRepresentationFactory = $doctrineListRepresentationFactory; + + parent::__construct($viewHandler, $tokenStorage); + } + + public function cgetAction(): Response + { + $listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation( + Location::RESOURCE_KEY + ); + + return $this->handleView($this->view($listRepresentation)); + } +} diff --git a/src/Entity/Location.php b/src/Entity/Location.php index 892f081..5c2f6d0 100644 --- a/src/Entity/Location.php +++ b/src/Entity/Location.php @@ -11,6 +11,8 @@ */ class Location { + const RESOURCE_KEY = 'locations'; + /** * @var int|null * diff --git a/tests/Functional/Controller/Admin/LocationControllerTest.php b/tests/Functional/Controller/Admin/LocationControllerTest.php new file mode 100644 index 0000000..24d494d --- /dev/null +++ b/tests/Functional/Controller/Admin/LocationControllerTest.php @@ -0,0 +1,49 @@ +client = $this->createAuthenticatedClient(); + $this->purgeDatabase(); + } + + public function testCGet(): void + { + $location1 = $this->createLocation('Sulu'); + $location2 = $this->createLocation('Symfony'); + + $this->client->request('GET', '/admin/api/locations'); + + $response = $this->client->getResponse(); + $this->assertInstanceOf(Response::class, $response); + $result = json_decode($response->getContent() ?: '', true); + $this->assertHttpStatusCode(200, $response); + + $this->assertSame(2, $result['total']); + $this->assertCount(2, $result['_embedded']['locations']); + $items = $result['_embedded']['locations']; + + $this->assertSame($location1->getId(), $items[0]['id']); + $this->assertSame($location2->getId(), $items[1]['id']); + + $this->assertSame($location1->getName(), $items[0]['name']); + $this->assertSame($location2->getName(), $items[1]['name']); + } +} diff --git a/tests/Functional/Traits/LocationTrait.php b/tests/Functional/Traits/LocationTrait.php new file mode 100644 index 0000000..bc8304c --- /dev/null +++ b/tests/Functional/Traits/LocationTrait.php @@ -0,0 +1,35 @@ +getLocationRepository()->create(); + $location->setName($name); + $location->setStreet(''); + $location->setNumber(''); + $location->setPostalCode(''); + $location->setCity(''); + $location->setCountryCode(''); + + $this->getEntityManager()->persist($location); + $this->getEntityManager()->flush(); + + return $location; + } + + protected function getLocationRepository(): LocationRepository + { + return $this->getEntityManager()->getRepository(Location::class); + } + + abstract protected function getEntityManager(): EntityManagerInterface; +} diff --git a/translations/admin.de.json b/translations/admin.de.json index 54fd06f..ac72ae7 100644 --- a/translations/admin.de.json +++ b/translations/admin.de.json @@ -7,5 +7,6 @@ "app.end_date": "Ende", "app.enable_event": "Veranstaltungen aktivieren", "app.enabled": "Aktiviert", - "app.location": "Standort" + "app.location": "Standort", + "app.locations": "Standorte" } diff --git a/translations/admin.en.json b/translations/admin.en.json index 293fa2d..b073ae1 100644 --- a/translations/admin.en.json +++ b/translations/admin.en.json @@ -7,5 +7,6 @@ "app.end_date": "Ende", "app.enable_event": "Enable event", "app.enabled": "Enabled", - "app.location": "Location" + "app.location": "Location", + "app.locations": "Locations" }