Skip to content

Commit 0854cbb

Browse files
committed
feat: add new generic get services endpoint
GET api/public/v1/marketplace/services Change-Id: I152f2dfc72b5c3672d4be4a70c83563a11204c11
1 parent 109040f commit 0854cbb

18 files changed

+234
-95
lines changed

app/Http/Controllers/Apis/Marketplace/AbstractCompanyServiceApiController.php

Lines changed: 45 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@
1212
* limitations under the License.
1313
**/
1414

15-
use libs\utils\PaginationValidationRules;
15+
use models\oauth2\IResourceServerContext;
1616
use models\utils\IBaseRepository;
17-
use models\exceptions\EntityNotFoundException;
18-
use models\exceptions\ValidationException;
19-
use Illuminate\Support\Facades\Validator;
20-
use utils\Filter;
21-
use utils\FilterParser;
22-
use utils\OrderParser;
23-
use Illuminate\Support\Facades\Request;
24-
use Illuminate\Support\Facades\Log;
25-
use utils\PagingInfo;
17+
use ModelSerializers\SerializerRegistry;
18+
2619
/**
2720
* Class AbstractCompanyServiceApiController
2821
* @package App\Http\Controllers
@@ -35,90 +28,63 @@ abstract class AbstractCompanyServiceApiController extends JsonController
3528
protected $repository;
3629

3730
/**
38-
* AppliancesApiController constructor.
31+
* @var IResourceServerContext
32+
*/
33+
protected $resource_server_context;
34+
35+
/**
3936
* @param IBaseRepository $repository
37+
* @param IResourceServerContext $resource_server_context
4038
*/
41-
public function __construct(IBaseRepository $repository)
39+
public function __construct(IBaseRepository $repository, IResourceServerContext $resource_server_context)
4240
{
41+
parent::__construct();
4342
$this->repository = $repository;
43+
$this->resource_server_context = $resource_server_context;
4444
}
4545

46+
47+
protected function getResourceServerContext(): IResourceServerContext
48+
{
49+
return $this->resource_server_context;
50+
}
51+
52+
protected function getRepository(): IBaseRepository
53+
{
54+
return $this->repository;
55+
}
56+
57+
use ParametrizedGetAll;
4658
/**
4759
* @return mixed
4860
*/
4961
public function getAll(){
50-
$values = Request::all();
51-
52-
$rules = PaginationValidationRules::get();
53-
54-
try {
55-
56-
$validation = Validator::make($values, $rules);
57-
58-
if ($validation->fails()) {
59-
$ex = new ValidationException();
60-
throw $ex->setMessages($validation->messages()->toArray());
61-
}
62-
63-
// default values
64-
$page = 1;
65-
$per_page = PaginationValidationRules::PerPageMin;
66-
67-
if (Request::has('page')) {
68-
$page = intval(Request::input('page'));
69-
$per_page = intval(Request::input('per_page'));
70-
}
71-
72-
$filter = null;
73-
74-
if (Request::has('filter')) {
75-
$filter = FilterParser::parse(Request::input('filter'), array
76-
(
62+
return $this->_getAll(
63+
function () {
64+
return [
7765
'name' => ['=@', '=='],
7866
'company' => ['=@', '=='],
79-
));
80-
}
81-
82-
$order = null;
83-
84-
if (Request::has('order'))
85-
{
86-
$order = OrderParser::parse(Request::input('order'), array
87-
(
67+
];
68+
},
69+
function () {
70+
return [
71+
'name' => 'sometimes|string',
72+
'company' => 'sometimes|string',
73+
];
74+
},
75+
function () {
76+
return [
8877
'name',
8978
'company',
9079
'id',
91-
));
80+
];
81+
},
82+
function ($filter) {
83+
return $filter;
84+
},
85+
function () {
86+
return SerializerRegistry::SerializerType_Public;
9287
}
93-
94-
if(is_null($filter)) $filter = new Filter();
95-
96-
$data = $this->repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order);
97-
$fields = Request::input('fields', '');
98-
$fields = !empty($fields) ? explode(',', $fields) : [];
99-
$relations = Request::input('relations', '');
100-
$relations = !empty($relations) ? explode(',', $relations) : [];
101-
return $this->ok
102-
(
103-
$data->toArray
104-
(
105-
Request::input('expand', ''),
106-
$fields,
107-
$relations
108-
)
109-
);
110-
}
111-
catch (EntityNotFoundException $ex1) {
112-
Log::warning($ex1);
113-
return $this->error404();
114-
}
115-
catch (ValidationException $ex2) {
116-
Log::warning($ex2);
117-
return $this->error412($ex2->getMessages());
118-
}
119-
catch (\Exception $ex) {
120-
Log::error($ex);
121-
return $this->error500($ex);
122-
}
88+
);
12389
}
12490
}

app/Http/Controllers/Apis/Marketplace/AppliancesApiController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IApplianceRepository;
15+
use models\oauth2\IResourceServerContext;
16+
1517
/**
1618
* Class AppliancesApiController
1719
* @package App\Http\Controllers
@@ -23,9 +25,9 @@ final class AppliancesApiController extends AbstractCompanyServiceApiController
2325
* AppliancesApiController constructor.
2426
* @param IApplianceRepository $repository
2527
*/
26-
public function __construct(IApplianceRepository $repository)
28+
public function __construct(IApplianceRepository $repository, IResourceServerContext $resource_server_context)
2729
{
28-
parent::__construct($repository);
30+
parent::__construct($repository, $resource_server_context);
2931
}
3032

3133
public function getAll()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php namespace App\Http\Controllers;
2+
/*
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use App\Models\Foundation\Marketplace\ICompanyServiceRepository;
16+
use models\oauth2\IResourceServerContext;
17+
18+
/**
19+
* Class CompanyServiceApiController
20+
* @package App\Http\Controllers
21+
*/
22+
final class CompanyServiceApiController extends AbstractCompanyServiceApiController
23+
{
24+
25+
/**
26+
* @param ICompanyServiceRepository $repository
27+
* @param IResourceServerContext $resource_server_context
28+
*/
29+
public function __construct(ICompanyServiceRepository $repository, IResourceServerContext$resource_server_context)
30+
{
31+
parent::__construct($repository, $resource_server_context);
32+
}
33+
34+
public function getAll()
35+
{
36+
return parent::getAll();
37+
}
38+
}

app/Http/Controllers/Apis/Marketplace/ConsultantsApiController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IConsultantRepository;
15+
use models\oauth2\IResourceServerContext;
1516

1617
/**
1718
* Class ConsultantsApiController
@@ -24,9 +25,9 @@ final class ConsultantsApiController extends AbstractCompanyServiceApiController
2425
* ConsultansApiController constructor.
2526
* @param IConsultantRepository $repository
2627
*/
27-
public function __construct(IConsultantRepository $repository)
28+
public function __construct(IConsultantRepository $repository, IResourceServerContext $resource_server_context)
2829
{
29-
parent::__construct($repository);
30+
parent::__construct($repository, $resource_server_context);
3031
}
3132

3233
public function getAll()

app/Http/Controllers/Apis/Marketplace/DistributionsApiController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IDistributionRepository;
15+
use models\oauth2\IResourceServerContext;
16+
1517
/**
1618
* Class DistributionsApiController
1719
* @package App\Http\Controllers\Apis\Marketplace
@@ -23,9 +25,9 @@ final class DistributionsApiController extends AbstractCompanyServiceApiControll
2325
* DistributionsApiController constructor.
2426
* @param IDistributionRepository $repository
2527
*/
26-
public function __construct(IDistributionRepository $repository)
28+
public function __construct(IDistributionRepository $repository, IResourceServerContext $resource_server_context)
2729
{
28-
parent::__construct($repository);
30+
parent::__construct($repository, $resource_server_context);
2931
}
3032

3133
public function getAll()

app/Http/Controllers/Apis/Marketplace/PrivateCloudsApiController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IPrivateCloudServiceRepository;
15+
use models\oauth2\IResourceServerContext;
16+
1517
/**
1618
* Class PrivateCloudsApiController
1719
* @package App\Http\Controllers
@@ -22,9 +24,9 @@ final class PrivateCloudsApiController extends AbstractCompanyServiceApiControll
2224
* PrivateCloudsApiController constructor.
2325
* @param IPrivateCloudServiceRepository $repository
2426
*/
25-
public function __construct(IPrivateCloudServiceRepository $repository)
27+
public function __construct(IPrivateCloudServiceRepository $repository, IResourceServerContext $resource_server_context)
2628
{
27-
parent::__construct($repository);
29+
parent::__construct($repository, $resource_server_context);
2830
}
2931

3032
public function getAll()

app/Http/Controllers/Apis/Marketplace/PublicCloudsApiController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IPublicCloudServiceRepository;
15+
use models\oauth2\IResourceServerContext;
16+
1517
/**
1618
* Class PublicCloudsApiController
1719
* @package App\Http\Controllers
@@ -22,9 +24,9 @@ final class PublicCloudsApiController extends AbstractCompanyServiceApiControlle
2224
* PrivateCloudsApiController constructor.
2325
* @param IPublicCloudServiceRepository $repository
2426
*/
25-
public function __construct(IPublicCloudServiceRepository $repository)
27+
public function __construct(IPublicCloudServiceRepository $repository, IResourceServerContext $resource_server_context)
2628
{
27-
parent::__construct($repository);
29+
parent::__construct($repository, $resource_server_context);
2830
}
2931

3032
public function getAll()

app/Http/Controllers/Apis/Marketplace/RemoteCloudsApiController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\Models\Foundation\Marketplace\IRemoteCloudServiceRepository;
15+
use models\oauth2\IResourceServerContext;
16+
1517
/**
1618
* Class RemoteCloudsApiController
1719
* @package App\Http\Controllers
@@ -22,9 +24,9 @@ final class RemoteCloudsApiController extends AbstractCompanyServiceApiControlle
2224
* PrivateCloudsApiController constructor.
2325
* @param IRemoteCloudServiceRepository $repository
2426
*/
25-
public function __construct(IRemoteCloudServiceRepository $repository)
27+
public function __construct(IRemoteCloudServiceRepository $repository, IResourceServerContext $resource_server_context)
2628
{
27-
parent::__construct($repository);
29+
parent::__construct($repository, $resource_server_context);
2830
}
2931

3032
public function getAll()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/*
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
16+
/**
17+
* Class TrainingServiceSerializer
18+
* @package App\ModelSerializers\Marketplace
19+
*/
20+
final class TrainingServiceSerializer extends CompanyServiceSerializer
21+
{
22+
23+
}

app/ModelSerializers/SerializerRegistry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use App\ModelSerializers\Marketplace\ServiceOfferedTypeSerializer;
5454
use App\ModelSerializers\Marketplace\SpokenLanguageSerializer;
5555
use App\ModelSerializers\Marketplace\SupportChannelTypeSerializer;
56+
use App\ModelSerializers\Marketplace\TrainingServiceSerializer;
5657
use App\ModelSerializers\PushNotificationMessageSerializer;
5758
use App\ModelSerializers\ResourceServer\ApiEndpointAuthzGroupSerializer;
5859
use App\ModelSerializers\ResourceServer\ApiEndpointSerializer;
@@ -627,6 +628,7 @@ private function __construct()
627628
$this->registry['PublicCloudService'] = PublicCloudServiceSerializer::class;
628629
$this->registry['RemoteCloudService'] = RemoteCloudServiceSerializer::class;
629630
$this->registry['CloudServiceOffered'] = CloudServiceOfferedSerializer::class;
631+
$this->registry['TrainingService'] = TrainingServiceSerializer::class;
630632
// software
631633

632634
$this->registry['OpenStackComponent'] = OpenStackComponentSerializer::class;

app/Models/Foundation/Marketplace/CompanyService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use models\utils\SilverstripeBaseModel;
1919
use models\main\Company;
2020
/**
21-
* @ORM\Entity
21+
* @ORM\Entity(repositoryClass="App\Repositories\Marketplace\DoctrineCompanyServiceRepository")
2222
* @ORM\Table(name="CompanyService")
2323
* @ORM\InheritanceType("JOINED")
2424
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
@@ -32,7 +32,8 @@
3232
* "CloudService", "CloudService",
3333
* "PrivateCloudService" = "PrivateCloudService",
3434
* "PublicCloudService" = "PublicCloudService",
35-
* "RemoteCloudService" = "RemoteCloudService"
35+
* "RemoteCloudService" = "RemoteCloudService",
36+
* "TrainingService" ="TrainingService",
3637
* } )
3738
* Class CompanyService
3839
* @package App\Models\Foundation\Marketplace

0 commit comments

Comments
 (0)