11<?php
22
3- <<<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
4- <<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
53namespace App \Http \Controllers \Api \V1 ;
64
75
1210use App \Models \PlatformConnection ;
1311use App \Http \Resources \PlatformConnectionResource ;
1412
15- =======
16- ========
17- namespace App \Http \Controllers \api \V1 ;
18-
19- >>>>>>>> b6e704f (move to namespace):middleware/app/Http/Controllers/api/V1 /PlatformConnectionController.php
20- use Illuminate\Http \Request ;
21- use App\Http \Controllers \Controller ;
22- use App\Models \PlatformConnection;
23- >>>>>>> 0 feb532 (fix items in review with nokie. PR closes UN -102 ):middleware/app/Http/Controllers/PlatformConnectionController.php
24-
2513class PlatformConnectionController extends Controller
2614{
2715
2816 /* Get all platform connections */
2917 //*************************************************************
30- <<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
31- // GET: /api/platform_connection/
18+ // GET: /api/v1/platform_connection/
3219 // Request $req example:
3320 // { "consumer_id": 1 }
3421 // *************************************************************
3522 public function index (): \Illuminate \Http \Resources \Json \AnonymousResourceCollection
3623 {
3724 return PlatformConnectionResource::collection (PlatformConnection::all ());
38- =======
39- //GET: /api/platform_connection/
40- // Request $req example:
41- // { "consumer_id": 1 }
42- // *************************************************************
43- public function index(): \Illuminate \Http \JsonResponse
44- {
45- try {
46- $ platform_connections = PlatformConnection::all(['*'])->toArray();
47- return response()->json($ platform_connections);
48- } catch (\Exception) {
49- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
50- }
51- >>>>>>> 0 feb532 (fix items in review with nokie. PR closes UN -102 ):middleware/app/Http/Controllers/PlatformConnectionController.php
5225 }
5326
5427 /* Create a new platform connection */
5528 //*************************************************************
56- <<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
5729 // POST: /api/v1/platform_connection/
5830 // PlatformConnectionRequest $req example:
5931 // { "consumer_id": 1, "provider_id": 1, "state": "enabled" }
@@ -70,36 +42,10 @@ public function store(StorePlatformConnectionRequest $req): PlatformConnectionRe
7042 return new PlatformConnectionResource ($ platform_connection );
7143 } catch (\Exception ) {
7244 return response ()->json (INVALID_REQUEST_BODY , 401 );
73- =======
74- //POST: /api/platform_connection/
75- // Request $req example:
76- // { "consumer_id": 1, "provider_id": 1, "state": "enabled" }
77- // *************************************************************
78- public function store (Request $ req ): \Illuminate \Http \JsonResponse
79- {
80- try {
81- $ consumer_id = $ req ->input ('consumer_id ' );
82- $ provider_id = $ req ->input ('provider_id ' );
83- $ state = $ req ->input ('state ' );
84- } catch (\Exception ) {
85- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
86- }
87- try {
88- $ platform_connection = PlatformConnection::create ([
89- 'consumer_id ' => $ consumer_id ,
90- 'provider_id ' => $ provider_id ,
91- 'state ' => $ state ,
92- ]);
93- return response ()->json ($ platform_connection );
94- } catch (\Exception ) {
95- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
96- >>>>>>> 0 feb532 (fix items in review with nokie. PR closes UN -102 ):middleware/app/Http/Controllers/PlatformConnectionController.php
9745 }
9846 }
99-
10047 // Get a specific platform connection by consumer or provider id
10148 // *************************************************************
102- <<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
10349 // GET: /api/v1/platform_connection/{id}
10450 // Request $req example:
10551 // "consumer_id": 1 || "provider_id": 1
@@ -125,56 +71,14 @@ public function update(UpdatePlatformConnectionRequest $req): PlatformConnection
12571 $ validated = $ req ->validated ();
12672 $ PlatformConnection = PlatformConnection::where ($ validated )->first ();
12773 $ PlatformConnection ->state = $ validated ['state ' ];
128- return new PlatformConnectionResource ($ PlatformConnection ->save ());
12974 if (!$ PlatformConnection ) {
13075 return response ()->json (['error ' => 'No matching platform connection found ' ], 401 );
131- =======
132- // GET: /api/platform_connection/{id}
133- // Request $req example:
134- // "consumer_id": 1 || "provider_id": 1
135- // *************************************************************
136- public function show (Request $ req ): \Illuminate \Http \JsonResponse
137- {
138- if ($ req ->input ('provider_id ' ) != null ) {
139- $ platform_connection = PlatformConnection::where ('platform_id ' , $ req ->input ('platform_id ' ))->first ();
140- } else {
141- $ platform_connection = PlatformConnection::where ('consumer_id ' , $ req ->input ('consumer_id ' ))->first ();
142- }
143- if (!$ platform_connection ) {
144- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
145- }
146- return response ()->json_encode ($ platform_connection , JSON_PRETTY_PRINT );
147- }
148-
149- // Update a platform connection
150- // *************************************************************
151- // PUT: /api/platform_connection/{request_body}
152- // Request $req example:
153- // { "consumer_id": 1, "provider_id": 1, "state": "enabled" }
154- // *************************************************************
155- public function update (Request $ req ): \Illuminate \Http \JsonResponse
156- {
157- try {
158- $ consumer_id = $ req ->input ('consumer_id ' );
159- $ provider_id = $ req ->input ('provider_id ' );
160- $ state = $ req ->input ('state ' );
161- } catch (\Exception ) {
162- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
163- }
164- try {
165- $ platform_connection = PlatformConnection::where ('consumer_id ' , $ consumer_id )->where ('provider_id ' , $ provider_id )->first ();
166- $ platform_connection ->state = $ state ;
167- $ platform_connection ->save ();
168- return response ()->json ($ platform_connection );
169- } catch (\Exception ) {
170- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
171- >>>>>>> 0 feb532 (fix items in review with nokie. PR closes UN -102 ):middleware/app/Http/Controllers/PlatformConnectionController.php
17276 }
77+ return new PlatformConnectionResource ($ PlatformConnection ->save ());
17378 }
17479
17580 // Delete a platform connection
17681 // *************************************************************
177- <<<<<<< HEAD :app/Http/Controllers/Api/V1 /PlatformConnectionController.php
17882 // DELETE: /api/v1/platform_connection/{request_body}
17983 // Request $req example:
18084 // { "consumer_id": 1, "provider_id": 1 }
@@ -186,26 +90,6 @@ public function delete(ShowPlatformConnectionRequest $req): \Illuminate\Http\Jso
18690 return response ()->json (['success ' => 'Platform connection deleted successfully ' ], 200 );
18791 } catch (\Exception ) {
18892 return response ()->json (INVALID_REQUEST_BODY , 401 );
189- =======
190- // DELETE: /api/platform_connection/{request_body}
191- // Request $req example:
192- // { "consumer_id": 1, "provider_id": 1 }
193- // *************************************************************
194- public function delete (Request $ req ): \Illuminate \Http \JsonResponse
195- {
196- try {
197- $ consumer_id = $ req ->input ('consumer_id ' );
198- $ provider_id = $ req ->input ('provider_id ' );
199- } catch (\Exception ) {
200- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
201- }
202- try {
203- $ platform_connection = PlatformConnection::where ('consumer_id ' , $ consumer_id )->where ('provider_id ' , $ provider_id )->first ();
204- $ platform_connection ->delete ();
205- return response ()->json (['status ' => 'success ' ]);
206- } catch (\Exception ) {
207- return response ()->json (['error ' => 'Invalid request body ' ], 401 );
208- >>>>>>> 0 feb532 (fix items in review with nokie. PR closes UN -102 ):middleware/app/Http/Controllers/PlatformConnectionController.php
20993 }
21094 }
21195}
0 commit comments