Skip to content

Commit 74632a6

Browse files
committed
feat(marketplace): add public endpoint GET /api/public/v1/marketplace/trainings
1 parent bb342dd commit 74632a6

25 files changed

+1481
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ routes.txt
2929
/ss.sql
3030
phpunit.xml
3131
.phpunit.result.cache
32-
.phpunit.cache/
32+
.phpunit.cache/
33+
.claude
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace App\Http\Controllers;
2+
/**
3+
* Copyright 2026 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+
use App\Http\Controllers\AbstractCompanyServiceApiController;
15+
use App\Models\Foundation\Marketplace\ITrainingRepository;
16+
use models\oauth2\IResourceServerContext;
17+
18+
class TrainingApiController extends AbstractCompanyServiceApiController
19+
{
20+
/**
21+
* TrainingApiController constructor.
22+
* @param ITrainingRepository $repository
23+
*/
24+
public function __construct(ITrainingRepository $repository, IResourceServerContext $resource_server_context)
25+
{
26+
parent::__construct($repository, $resource_server_context);
27+
}
28+
29+
public function getAll()
30+
{
31+
return parent::getAll();
32+
}
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use ModelSerializers\SilverStripeSerializer;
15+
/**
16+
* Class ProjectSerializer
17+
* @package App\ModelSerializers\Marketplace
18+
*/
19+
final class ProjectSerializer extends SilverStripeSerializer
20+
{
21+
protected static $array_mappings = [
22+
'Name' => 'name:json_string',
23+
'Description' => 'description:json_string',
24+
'Codename' => 'codename:json_string',
25+
];
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use ModelSerializers\SilverStripeSerializer;
15+
/**
16+
* Class TrainingCourseLevelSerializer
17+
* @package App\ModelSerializers\Marketplace
18+
*/
19+
final class TrainingCourseLevelSerializer extends SilverStripeSerializer
20+
{
21+
protected static $array_mappings = [
22+
'Level' => 'level:json_string',
23+
'Order' => 'order:json_int',
24+
];
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use ModelSerializers\SilverStripeSerializer;
15+
/**
16+
* Class TrainingCoursePrerequisiteSerializer
17+
* @package App\ModelSerializers\Marketplace
18+
*/
19+
final class TrainingCoursePrerequisiteSerializer extends SilverStripeSerializer
20+
{
21+
protected static $array_mappings = [
22+
'Name' => 'name:json_string',
23+
];
24+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use App\Models\Foundation\Marketplace\TrainingCourseSchedule;
15+
use Libs\ModelSerializers\Many2OneExpandSerializer;
16+
use ModelSerializers\SilverStripeSerializer;
17+
/**
18+
* Class TrainingCourseScheduleSerializer
19+
* @package App\ModelSerializers\Marketplace
20+
*/
21+
final class TrainingCourseScheduleSerializer extends SilverStripeSerializer
22+
{
23+
protected static $array_mappings = [
24+
'City' => 'city:json_string',
25+
'State' => 'state:json_string',
26+
'Country' => 'country:json_string',
27+
];
28+
29+
protected static $allowed_relations = [
30+
'times',
31+
];
32+
33+
/**
34+
* @param null $expand
35+
* @param array $fields
36+
* @param array $relations
37+
* @param array $params
38+
* @return array
39+
*/
40+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
41+
{
42+
$schedule = $this->object;
43+
if (!$schedule instanceof TrainingCourseSchedule) return [];
44+
$values = parent::serialize($expand, $fields, $relations, $params);
45+
46+
if (in_array('times', $relations) && !isset($values['times'])) {
47+
$times = [];
48+
foreach ($schedule->getTimes() as $t) {
49+
$times[] = $t->getId();
50+
}
51+
$values['times'] = $times;
52+
}
53+
54+
return $values;
55+
}
56+
57+
protected static $expand_mappings = [
58+
'times' => [
59+
'type' => Many2OneExpandSerializer::class,
60+
'getter' => 'getTimes',
61+
],
62+
];
63+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use Libs\ModelSerializers\One2ManyExpandSerializer;
15+
use ModelSerializers\SilverStripeSerializer;
16+
/**
17+
* Class TrainingCourseScheduleTimeSerializer
18+
* @package App\ModelSerializers\Marketplace
19+
*/
20+
final class TrainingCourseScheduleTimeSerializer extends SilverStripeSerializer
21+
{
22+
protected static $array_mappings = [
23+
'StartDate' => 'start_date:datetime_epoch',
24+
'EndDate' => 'end_date:datetime_epoch',
25+
'Link' => 'link:json_string',
26+
'LocationId' => 'location_id:json_int',
27+
];
28+
29+
protected static $allowed_relations = [
30+
'location',
31+
];
32+
33+
protected static $expand_mappings = [
34+
'location' => [
35+
'type' => One2ManyExpandSerializer::class,
36+
'original_attribute' => 'location_id',
37+
'getter' => 'getLocation',
38+
'has' => 'hasLocation',
39+
],
40+
];
41+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use App\Models\Foundation\Marketplace\TrainingCourse;
15+
use Libs\ModelSerializers\Many2OneExpandSerializer;
16+
use Libs\ModelSerializers\One2ManyExpandSerializer;
17+
use ModelSerializers\SilverStripeSerializer;
18+
/**
19+
* Class TrainingCourseSerializer
20+
* @package App\ModelSerializers\Marketplace
21+
*/
22+
final class TrainingCourseSerializer extends SilverStripeSerializer
23+
{
24+
protected static $array_mappings = [
25+
'Name' => 'name:json_string',
26+
'Link' => 'link:json_string',
27+
'Description' => 'description:json_string',
28+
'Paid' => 'is_paid:json_boolean',
29+
'Online' => 'is_online:json_boolean',
30+
'TypeId' => 'type_id:json_int',
31+
'LevelId' => 'level_id:json_int',
32+
'TrainingServiceId' => 'training_service_id:json_int',
33+
];
34+
35+
protected static $allowed_relations = [
36+
'type',
37+
'level',
38+
'training_service',
39+
'schedules',
40+
'projects',
41+
'prerequisites',
42+
];
43+
44+
/**
45+
* @param null $expand
46+
* @param array $fields
47+
* @param array $relations
48+
* @param array $params
49+
* @return array
50+
*/
51+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
52+
{
53+
$course = $this->object;
54+
if (!$course instanceof TrainingCourse) return [];
55+
$values = parent::serialize($expand, $fields, $relations, $params);
56+
57+
if (in_array('schedules', $relations) && !isset($values['schedules'])) {
58+
$schedules = [];
59+
foreach ($course->getSchedules() as $s) {
60+
$schedules[] = $s->getId();
61+
}
62+
$values['schedules'] = $schedules;
63+
}
64+
65+
if (in_array('projects', $relations) && !isset($values['projects'])) {
66+
$projects = [];
67+
foreach ($course->getProjects() as $p) {
68+
$projects[] = $p->getId();
69+
}
70+
$values['projects'] = $projects;
71+
}
72+
73+
if (in_array('prerequisites', $relations) && !isset($values['prerequisites'])) {
74+
$prerequisites = [];
75+
foreach ($course->getPrerequisites() as $p) {
76+
$prerequisites[] = $p->getId();
77+
}
78+
$values['prerequisites'] = $prerequisites;
79+
}
80+
81+
return $values;
82+
}
83+
84+
protected static $expand_mappings = [
85+
'type' => [
86+
'type' => One2ManyExpandSerializer::class,
87+
'original_attribute' => 'type_id',
88+
'getter' => 'getType',
89+
'has' => 'hasType',
90+
],
91+
'level' => [
92+
'type' => One2ManyExpandSerializer::class,
93+
'original_attribute' => 'level_id',
94+
'getter' => 'getLevel',
95+
'has' => 'hasLevel',
96+
],
97+
'training_service' => [
98+
'type' => One2ManyExpandSerializer::class,
99+
'original_attribute' => 'training_service_id',
100+
'getter' => 'getTrainingService',
101+
'has' => 'hasTrainingService',
102+
],
103+
'schedules' => [
104+
'type' => Many2OneExpandSerializer::class,
105+
'getter' => 'getSchedules',
106+
],
107+
'projects' => [
108+
'type' => Many2OneExpandSerializer::class,
109+
'getter' => 'getProjects',
110+
],
111+
'prerequisites' => [
112+
'type' => Many2OneExpandSerializer::class,
113+
'getter' => 'getPrerequisites',
114+
],
115+
];
116+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php namespace App\ModelSerializers\Marketplace;
2+
/**
3+
* Copyright 2026 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+
use ModelSerializers\SilverStripeSerializer;
15+
/**
16+
* Class TrainingCourseTypeSerializer
17+
* @package App\ModelSerializers\Marketplace
18+
*/
19+
final class TrainingCourseTypeSerializer extends SilverStripeSerializer
20+
{
21+
protected static $array_mappings = [
22+
'Type' => 'type:json_string',
23+
];
24+
}

0 commit comments

Comments
 (0)