diff --git a/Mapping/Apis/Users/User.php b/Mapping/Apis/Users/User.php index 5682f40..9111f4c 100644 --- a/Mapping/Apis/Users/User.php +++ b/Mapping/Apis/Users/User.php @@ -68,4 +68,16 @@ public function setFullname(mixed $fullname): static return $this; } + /** + * Gives a JSON representation of this user + * @return string + */ + public function toJson() { + return json_encode([ + 'fullname' => $this->fullname, + 'username' => $this->username + ]); + } + + } diff --git a/app/Http/Controllers/DataMapperController.php b/app/Http/Controllers/DataMapperController.php index aee9256..95f8992 100644 --- a/app/Http/Controllers/DataMapperController.php +++ b/app/Http/Controllers/DataMapperController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; +use Symfony\Component\HttpFoundation\Response; use Illuminate\Http\Request; use JetBrains\PhpStorm\NoReturn; @@ -21,6 +22,20 @@ class DataMapperController extends Controller * @return void */ public function mapping(ApiResponses $apiResponses, EntityInterface $entity, Request $request, string $type) + { + $file = 'api.' . $type; + $data = $apiResponses->getData($file, $type); + try { + $result = $this->startMapping($data, $entity, $type); + + return response($result->toJson(), 200); + + } catch (\Exception $e) { + return response($e->getMessage(), 500); + } + } + + public function test(ApiResponses $apiResponses, EntityInterface $entity, Request $request, string $type) { $file = 'api.'.$type; $data = $apiResponses->getData($file, $type); @@ -33,10 +48,9 @@ public function mapping(ApiResponses $apiResponses, EntityInterface $entity, Req dd($result); } catch (\Exception $e) { - echo "Error : ". $e->getMessage(); + echo "Error : ". $e->getMessage(); } - } } diff --git a/routes/web.php b/routes/web.php index 2c4df96..d6f2f2e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,5 +5,6 @@ use App\Http\Controllers\DataMapperController; Route::get("/data-mapping/{type}", [DataMapperController::class, 'mapping']); +Route::get("/data-mapping-show/{type}", [DataMapperController::class, 'test']); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 8364a84..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -}