-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[39] - Añadir endpoint create users a main
- Loading branch information
1 parent
df3eed1
commit c24ee1d
Showing
4 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/Infrastructure/CreateUser/AnalyticsCreateUserController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Infrastructure\CreateUser; | ||
|
||
use App\Exceptions\ConflictException; | ||
use App\Exceptions\InternalServerErrorException; | ||
use App\Infrastructure\Controllers\Controller; | ||
use App\Services\CreateUserManager; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class AnalyticsCreateUserController extends Controller | ||
{ | ||
private CreateUserManager $createUserManager; | ||
|
||
public function __construct(CreateUserManager $createUserManager) | ||
{ | ||
$this->createUserManager = $createUserManager; | ||
} | ||
public function __invoke(Request $request): JsonResponse | ||
{ | ||
$username = $request->input('username'); | ||
$password = $request->input('password'); | ||
|
||
if (empty($username) || empty($password)) { | ||
return response()->json( | ||
['error' => 'Los parámetros (username y password) no fueron proporcionados.'], | ||
Response::HTTP_BAD_REQUEST | ||
); | ||
} | ||
|
||
try { | ||
$createUserMessage = $this->createUserManager->getCreateUserMessage($username, $password); | ||
return response()->json($createUserMessage, Response::HTTP_CREATED); | ||
} catch (ConflictException $e) { | ||
return response()->json(['error' => $e->getMessage()], Response::HTTP_CONFLICT); | ||
} catch (InternalServerErrorException $e) { | ||
return response()->json(['error' => $e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters