diff --git a/.env b/.env old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.phpunit.result.cache b/.phpunit.result.cache old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/nginx/default.conf b/nginx/default.conf old mode 100644 new mode 100755 diff --git a/src/.editorconfig b/src/.editorconfig old mode 100644 new mode 100755 diff --git a/src/.env.example b/src/.env.example old mode 100644 new mode 100755 diff --git a/src/.gitattributes b/src/.gitattributes old mode 100644 new mode 100755 diff --git a/src/.gitignore b/src/.gitignore old mode 100644 new mode 100755 diff --git a/src/.styleci.yml b/src/.styleci.yml old mode 100644 new mode 100755 diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/src/README.md b/src/README.md old mode 100644 new mode 100755 diff --git a/src/app/Application/CoinDataSource/CoinDataSource.php b/src/app/Application/CoinDataSource/CoinDataSource.php new file mode 100755 index 00000000..2969dea2 --- /dev/null +++ b/src/app/Application/CoinDataSource/CoinDataSource.php @@ -0,0 +1,11 @@ +name; + $symbol = $data->symbol; + $amount = 0; + $value_usd = floatval($data->price_usd); + $name_id = $data->nameid; + $rank = $data->rank; + + $Coin = new Coin($amount,$coin_id,$name,$name_id,$rank,$symbol,$value_usd); + + return $Coin; + } +} diff --git a/src/app/Application/CoinService/CoinService.php b/src/app/Application/CoinService/CoinService.php new file mode 100755 index 00000000..80b8d826 --- /dev/null +++ b/src/app/Application/CoinService/CoinService.php @@ -0,0 +1,36 @@ +coinDataSource = $coinDataSource; + } + + /**use App\Domain\Coin; + * @param string $coin_id + * @return Coin|Exception + * @throws Exception + */ + public function execute(string $coin_id) + { + $coin = $this->coinDataSource->findByCoinId($coin_id); + return $coin; + } +} diff --git a/src/app/Application/EarlyAdopter/IsEarlyAdopterService.php b/src/app/Application/EarlyAdopter/IsEarlyAdopterService.php deleted file mode 100644 index 49132e1c..00000000 --- a/src/app/Application/EarlyAdopter/IsEarlyAdopterService.php +++ /dev/null @@ -1,40 +0,0 @@ -userDataSource = $userDataSource; - } - - /** - * @param string $email - * @return bool - * @throws Exception - */ - public function execute(string $email): bool - { - $user = $this->userDataSource->findByEmail($email); - $isEarlyAdopter = false; - - if ($user->getId() < 1000) { - $isEarlyAdopter = true; - } - - return $isEarlyAdopter; - } -} diff --git a/src/app/Application/UserDataSource/UserDataSource.php b/src/app/Application/UserDataSource/UserDataSource.php deleted file mode 100644 index ba6bd39b..00000000 --- a/src/app/Application/UserDataSource/UserDataSource.php +++ /dev/null @@ -1,10 +0,0 @@ -amount = $amount; + $this->coin_id = $coin_id; + $this->name = $name; + $this->name_id = $name_id; + $this->rank = $rank; + $this->symbol = $symbol; + $this->value_usd = $value_usd; + } + + + /** + * @return string + */ + public function getNameId(): string + { + return $this->name_id; + } + + /** + * @param string $name_id + */ + public function setNameId(string $name_id): void + { + $this->name_id = $name_id; + } + + /** + * @return int + */ + public function getRank(): int + { + return $this->rank; + } + + /** + * @param int $rank + */ + public function setRank(int $rank): void + { + $this->rank = $rank; + } + + + + + /** + * @return string + */ + public function getCoinId(): string + { + return $this->coin_id; + } + + /** + * @param string $coin_id + */ + public function setCoinId(string $coin_id): void + { + $this->coin_id = $coin_id; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName(string $name): void + { + $this->name = $name; + } + + /** + * @return string + */ + public function getSymbol(): string + { + return $this->symbol; + } + + /** + * @param string $symbol + */ + public function setSymbol(string $symbol): void + { + $this->symbol = $symbol; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @param float $amount + */ + public function setAmount(float $amount): void + { + $this->amount = $amount; + } + + /** + * @return float + */ + public function getValueUsd(): float + { + return $this->value_usd; + } + + /** + * @param float $value_usd + */ + public function setValueUsd(float $value_usd): void + { + $this->value_usd = $value_usd; + } + + +} diff --git a/src/app/Domain/User.php b/src/app/Domain/User.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Controllers/CacheController.php b/src/app/Infrastructure/Controllers/CacheController.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Controllers/GetCoinController.php b/src/app/Infrastructure/Controllers/GetCoinController.php new file mode 100755 index 00000000..0ccfc159 --- /dev/null +++ b/src/app/Infrastructure/Controllers/GetCoinController.php @@ -0,0 +1,43 @@ +CoinService = $CoinService; + } + + public function __invoke(int $id): JsonResponse + { + try { + $CoinService = $this->CoinService->execute($id); + } catch (Exception $exception) { + if ($exception->getMessage() == "A coin with the specified ID was not found.") { + return response()->json([ + 'error' => $exception->getMessage() + ], Response::HTTP_NOT_FOUND); + }else{ + return response()->json([ + 'error' => 'Service Unavailible' + ], Response::HTTP_SERVICE_UNAVAILABLE); + } + } + + return response()->json([ + $CoinService + ], Response::HTTP_OK); + } +} diff --git a/src/app/Infrastructure/Controllers/GetUserController.php b/src/app/Infrastructure/Controllers/GetUserController.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Controllers/IsEarlyAdopterUserController.php b/src/app/Infrastructure/Controllers/IsEarlyAdopterUserController.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Controllers/StatusController.php b/src/app/Infrastructure/Controllers/StatusController.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Controllers/testController.php b/src/app/Infrastructure/Controllers/testController.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Exceptions/Handler.php b/src/app/Infrastructure/Exceptions/Handler.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/FakeUserDataSource.php b/src/app/Infrastructure/FakeUserDataSource.php deleted file mode 100644 index fe59068d..00000000 --- a/src/app/Infrastructure/FakeUserDataSource.php +++ /dev/null @@ -1,19 +0,0 @@ -app->bind(UserDataSource::class, function () { -// return new EloquentUserDataSource(); -// }); + $this->app->bind(CoinDataSource::class, function () { + return new CryptoCoinDataSource(); + }); } } diff --git a/src/app/Infrastructure/Providers/AuthServiceProvider.php b/src/app/Infrastructure/Providers/AuthServiceProvider.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Providers/BroadcastServiceProvider.php b/src/app/Infrastructure/Providers/BroadcastServiceProvider.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Providers/EventServiceProvider.php b/src/app/Infrastructure/Providers/EventServiceProvider.php old mode 100644 new mode 100755 diff --git a/src/app/Infrastructure/Providers/RouteServiceProvider.php b/src/app/Infrastructure/Providers/RouteServiceProvider.php old mode 100644 new mode 100755 diff --git a/src/bootstrap/app.php b/src/bootstrap/app.php old mode 100644 new mode 100755 diff --git a/src/bootstrap/cache/.gitignore b/src/bootstrap/cache/.gitignore old mode 100644 new mode 100755 diff --git a/src/composer.json b/src/composer.json old mode 100644 new mode 100755 diff --git a/src/composer.lock b/src/composer.lock old mode 100644 new mode 100755 diff --git a/src/config/app.php b/src/config/app.php old mode 100644 new mode 100755 diff --git a/src/config/auth.php b/src/config/auth.php old mode 100644 new mode 100755 diff --git a/src/config/broadcasting.php b/src/config/broadcasting.php old mode 100644 new mode 100755 diff --git a/src/config/cache.php b/src/config/cache.php old mode 100644 new mode 100755 diff --git a/src/config/cors.php b/src/config/cors.php old mode 100644 new mode 100755 diff --git a/src/config/database.php b/src/config/database.php old mode 100644 new mode 100755 diff --git a/src/config/debugbar.php b/src/config/debugbar.php old mode 100644 new mode 100755 diff --git a/src/config/filesystems.php b/src/config/filesystems.php old mode 100644 new mode 100755 diff --git a/src/config/hashing.php b/src/config/hashing.php old mode 100644 new mode 100755 diff --git a/src/config/logging.php b/src/config/logging.php old mode 100644 new mode 100755 diff --git a/src/config/mail.php b/src/config/mail.php old mode 100644 new mode 100755 diff --git a/src/config/queue.php b/src/config/queue.php old mode 100644 new mode 100755 diff --git a/src/config/services.php b/src/config/services.php old mode 100644 new mode 100755 diff --git a/src/config/session.php b/src/config/session.php old mode 100644 new mode 100755 diff --git a/src/config/view.php b/src/config/view.php old mode 100644 new mode 100755 diff --git a/src/package.json b/src/package.json old mode 100644 new mode 100755 diff --git a/src/phpunit.xml b/src/phpunit.xml old mode 100644 new mode 100755 diff --git a/src/postman/base_postman_collection.json b/src/postman/base_postman_collection.json old mode 100644 new mode 100755 diff --git a/src/public/.htaccess b/src/public/.htaccess old mode 100644 new mode 100755 diff --git a/src/public/favicon.ico b/src/public/favicon.ico old mode 100644 new mode 100755 diff --git a/src/public/index.php b/src/public/index.php old mode 100644 new mode 100755 diff --git a/src/public/robots.txt b/src/public/robots.txt old mode 100644 new mode 100755 diff --git a/src/public/web.config b/src/public/web.config old mode 100644 new mode 100755 diff --git a/src/resources/css/app.css b/src/resources/css/app.css old mode 100644 new mode 100755 diff --git a/src/resources/js/app.js b/src/resources/js/app.js old mode 100644 new mode 100755 diff --git a/src/resources/js/bootstrap.js b/src/resources/js/bootstrap.js old mode 100644 new mode 100755 diff --git a/src/resources/lang/en/auth.php b/src/resources/lang/en/auth.php old mode 100644 new mode 100755 diff --git a/src/resources/lang/en/pagination.php b/src/resources/lang/en/pagination.php old mode 100644 new mode 100755 diff --git a/src/resources/lang/en/passwords.php b/src/resources/lang/en/passwords.php old mode 100644 new mode 100755 diff --git a/src/resources/lang/en/validation.php b/src/resources/lang/en/validation.php old mode 100644 new mode 100755 diff --git a/src/resources/views/welcome.blade.php b/src/resources/views/welcome.blade.php old mode 100644 new mode 100755 diff --git a/src/routes/api.php b/src/routes/api.php old mode 100644 new mode 100755 index fdeab5ce..857ccfdf --- a/src/routes/api.php +++ b/src/routes/api.php @@ -1,5 +1,6 @@ coin_id = $coin_id; + $this->name = $name; + $this->symbol = $symbol; + $this->amount = $amount; + $this->name_id = $name_id; + } + + +} diff --git a/src/tests/CreatesApplication.php b/src/tests/CreatesApplication.php old mode 100644 new mode 100755 diff --git a/src/tests/TestCase.php b/src/tests/TestCase.php old mode 100644 new mode 100755 diff --git a/src/tests/app/Application/CoinService/CoinServiceTest.php b/src/tests/app/Application/CoinService/CoinServiceTest.php new file mode 100755 index 00000000..5b5bbde0 --- /dev/null +++ b/src/tests/app/Application/CoinService/CoinServiceTest.php @@ -0,0 +1,69 @@ +coinDataSource = Mockery::mock(CoinDataSource::class); + + $this->coinService = new CoinService($this->coinDataSource); + } + + /** + * @test + */ + public function validIdReturnACoin() + { + $coin = new Coin(0,"10","BlackCoin","blackcoin",1,"BLK",1); + + $this->coinDataSource + ->expects('findByCoinId') + ->with('10') + ->once() + ->andReturn($coin); + + $response = $this->coinService->execute('10'); + + $c1 = new CoinTest("10","BlackCoin","BLK",0,"blackcoin"); + $c2 = new CoinTest($response->getCoinId(),$response->getName(),$response->getSymbol(),0,$response->getNameId()); + + $this->assertEquals($c1,$c2); + } + + /** + * @test + */ + public function coinNotFoundReturnError() + { + $id = '2000'; + + $this->coinDataSource + ->expects('findByCoinId') + ->with($id) + ->once() + ->andThrow(new Exception("A coin with the specified ID was not found.")); + + $this->expectException(Exception::class); + + $this->coinService->execute($id); + } +} diff --git a/src/tests/app/Application/EarlyAdopter/IsEarlyAdopterServiceTest.php b/src/tests/app/Application/EarlyAdopter/IsEarlyAdopterServiceTest.php deleted file mode 100644 index df2adc48..00000000 --- a/src/tests/app/Application/EarlyAdopter/IsEarlyAdopterServiceTest.php +++ /dev/null @@ -1,88 +0,0 @@ -userDataSource = Mockery::mock(UserDataSource::class); - - $this->isEarlyAdopterService = new IsEarlyAdopterService($this->userDataSource); - } - - /** - * @test - */ - public function userNotFound() - { - $email = 'not_existing_email@email.com'; - - $user = new User(9999, $email); - - $this->userDataSource - ->expects('findByEmail') - ->with($email) - ->once() - ->andThrow(new Exception('User not found')); - - $this->expectException(Exception::class); - - $this->isEarlyAdopterService->execute($email); - } - - /** - * @test - */ - public function userIsNotEarlyAdopter() - { - $email = 'not_early_adopter@email.com'; - - $user = new User(9999, $email); - - $this->userDataSource - ->expects('findByEmail') - ->with($email) - ->once() - ->andReturn($user); - - $isUserEarlyAdopter = $this->isEarlyAdopterService->execute($email); - - $this->assertFalse($isUserEarlyAdopter); - } - - /** - * @test - */ - public function userIsAnEarlyAdopter() - { - $email = 'not_early_adopter@email.com'; - - $user = new User(300, $email); - - $this->userDataSource - ->expects('findByEmail') - ->with($email) - ->once() - ->andReturn($user); - - $isUserEarlyAdopter = $this->isEarlyAdopterService->execute($email); - - $this->assertTrue($isUserEarlyAdopter); - } -} diff --git a/src/tests/app/Infrastructure/Controller/GetCoinControllerTest.php b/src/tests/app/Infrastructure/Controller/GetCoinControllerTest.php new file mode 100755 index 00000000..c6b75da0 --- /dev/null +++ b/src/tests/app/Infrastructure/Controller/GetCoinControllerTest.php @@ -0,0 +1,80 @@ +coinDataSource = Mockery::mock(coinDataSource::class); + $this->app->bind(coinDataSource::class, fn() => $this->coinDataSource); + } + + /** + * @test + */ + public function coinWithGivenIdDoesNotExist() + { + $id = '2000'; + $this->coinDataSource + ->expects('findByCoinId') + ->with($id) + ->once() + ->andThrow(new Exception('A coin with the specified ID was not found.')); + + $response = $this->get('/api/coin/status/2000'); + + $response->assertStatus(Response::HTTP_NOT_FOUND)->assertExactJson(['error' => 'A coin with the specified ID was not found.']); + } + + + /** + * @test + */ + public function errorInServer() + { + $id = '200'; + $this->coinDataSource + ->expects('findByCoinId') + ->with($id) + ->once() + ->andThrow(new Exception('Service Unavailible')); + + $response = $this->get('/api/coin/status/200'); + + $response->assertStatus(Response::HTTP_SERVICE_UNAVAILABLE)->assertExactJson(['error' => 'Service Unavailible']); + } + + /** + * @test + */ + public function coinWithValidIdReturnJsonCoin() + { + $id = '10'; + $coin = new Coin(0,"10","BlackCoin","blackcoin",1,"BLK",1); + + $this->coinDataSource + ->expects('findByCoinId') + ->with($id) + ->once() + ->andReturn($coin); + + $response = $this->get('/api/coin/status/10'); + + $response->assertStatus(Response::HTTP_OK)->assertExactJson([$coin]); + } +} diff --git a/src/tests/app/Infrastructure/Controller/GetUserControllerTest.php b/src/tests/app/Infrastructure/Controller/GetUserControllerTest.php old mode 100644 new mode 100755 diff --git a/src/tests/app/Infrastructure/Controller/IsEarlyAdopterUserControllerTest.php b/src/tests/app/Infrastructure/Controller/IsEarlyAdopterUserControllerTest.php old mode 100644 new mode 100755 diff --git a/src/webpack.mix.js b/src/webpack.mix.js old mode 100644 new mode 100755