1+ <?php namespace App \Http \Controllers ;
2+
3+ /*
4+ * Copyright 2023 OpenStack Foundation
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ **/
15+
16+ use App \Models \Foundation \Summit \Repositories \ISummitSignRepository ;
17+ use App \Services \Model \ISummitSignService ;
18+ use models \oauth2 \IResourceServerContext ;
19+ use models \summit \ISummitRepository ;
20+ use models \summit \Summit ;
21+ use models \utils \IEntity ;
22+
23+ /**
24+ * Class OAuth2SummitSignApiController
25+ * @package App\Http\Controller
26+ */
27+ final class OAuth2SummitSignApiController extends OAuth2ProtectedController
28+ {
29+ private $ summit_repository ;
30+
31+ private $ service ;
32+
33+ /**
34+ * @param ISummitSignRepository $repository
35+ * @param ISummitRepository $summit_repository
36+ * @param ISummitSignService $service
37+ * @param IResourceServerContext $resource_server_context
38+ */
39+ public function __construct
40+ (
41+ ISummitSignRepository $ repository ,
42+ ISummitRepository $ summit_repository ,
43+ ISummitSignService $ service ,
44+ IResourceServerContext $ resource_server_context
45+ )
46+ {
47+ parent ::__construct ($ resource_server_context );
48+ $ this ->summit_repository = $ summit_repository ;
49+ $ this ->service = $ service ;
50+ $ this ->repository = $ repository ;
51+ }
52+
53+ use GetAllBySummit;
54+
55+ use GetSummitChildElementById;
56+
57+ use AddSummitChildElement;
58+
59+ use UpdateSummitChildElement;
60+
61+ protected function addChild (Summit $ summit , array $ payload ): IEntity
62+ {
63+ return $ this ->service ->add ($ summit , $ payload );
64+ }
65+
66+ function getAddValidationRules (array $ payload ): array
67+ {
68+ return [
69+ 'location_id ' => 'required|integer ' ,
70+ 'template ' => 'required|string '
71+ ];
72+ }
73+
74+ protected function getSummitRepository (): ISummitRepository
75+ {
76+ return $ this ->summit_repository ;
77+ }
78+
79+ protected function getChildFromSummit (Summit $ summit , $ child_id ): ?IEntity
80+ {
81+ return $ summit ->getSignById (intval ($ child_id ));
82+ }
83+
84+ function getUpdateValidationRules (array $ payload ): array
85+ {
86+ return [
87+ 'template ' => 'sometimes|string '
88+ ];
89+ }
90+
91+ protected function updateChild (Summit $ summit , int $ child_id , array $ payload ): IEntity
92+ {
93+ return $ this ->service ->update ($ summit , $ child_id , $ payload );
94+ }
95+
96+ protected function getFilterRules ():array {
97+ return [
98+ 'location_id ' => ['== ' ],
99+ ];
100+ }
101+
102+ /**
103+ * @return array
104+ */
105+ protected function getFilterValidatorRules ():array {
106+ return [
107+ 'location_id ' => 'sometimes|integer ' ,
108+ ];
109+ }
110+ /**
111+ * @return array
112+ */
113+ protected function getOrderRules ():array {
114+ return [
115+ 'id '
116+ ];
117+ }
118+ }
0 commit comments