Skip to content

Commit

Permalink
[36] - Implementar endpoint Follow streamer (#44)
Browse files Browse the repository at this point in the history
* [36] - Arreglar conflictos

* [36] - Arreglar conflictos DBClient

* [0] - Refactorizar servicios con streamers

* [36] - Arreglar conflictos migraciones usuario

* [36] - Crear excepciones forbidden y unauthorized

* [36] - Implementado error get token

* [36] - Devolver mensajes excepcionesd desde controller

* [36] - Añadir follow a routes

* [36] - Modificar streamerId a string en usuario_streamers

* [36] - Añadir excepcion para manejar error not found

* [36] - Manejar errores desde controlador

* [36] - Eliminar metodo innecesario post en ApiClient

* [36] - Refactorizar DBClient

* [36] - Refactorizar follow streamer manager

* [36] - Implementar request con username y streamerId

* [36] - Implementar metodos database y devolver errores en excepciones

* [36] - Manejar mensajes excepciones desde fuera del controller

* [36] - Refactorizar FollowStreamerManager

* [36] - Implementar tests de integracion

* [36] - Implementar tests unitarios

* [36] - Eliminar endpoint desactualizado de /users en /follow

---------

Co-authored-by: Santi Ayechu <santiayechu@gmail.com>
  • Loading branch information
eduezponda and sayechu authored Jun 2, 2024
1 parent ee7ddd6 commit bd6297e
Show file tree
Hide file tree
Showing 19 changed files with 1,094 additions and 402 deletions.
11 changes: 11 additions & 0 deletions app/Exceptions/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Exceptions;

use Exception;

class ForbiddenException extends Exception
{

}

11 changes: 11 additions & 0 deletions app/Exceptions/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Exceptions;

use Exception;

class NotFoundException extends Exception
{

}

11 changes: 11 additions & 0 deletions app/Exceptions/UnauthorizedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Exceptions;

use Exception;

class UnauthorizedException extends Exception
{

}

42 changes: 0 additions & 42 deletions app/Infrastructure/CreateUser/AnalyticsCreateUserController.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
use App\Infrastructure\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Exceptions\ConflictException;
use App\Exceptions\ForbiddenException;
use App\Exceptions\InternalServerErrorException;
use App\Exceptions\NotFoundException;
use App\Exceptions\UnauthorizedException;
use Illuminate\Http\Response;

class AnalyticsFollowStreamerController extends Controller
{
Expand All @@ -15,12 +21,25 @@ public function __construct(FollowStreamerManager $followManager)
{
$this->followManager = $followManager;
}
public function __invoke(Request $request): JsonResponse

public function __invoke(AnalyticsFollowStreamerRequest $request): JsonResponse
{
$userId = $request->input('userId');
$username = $request->input('username');
$streamerId = $request->input('streamerId');

$followMessage = $this->followManager->getFollowMessage($userId, $streamerId);
return response()->json($followMessage);
try {
$followMessage = $this->followManager->getFollowMessage($username, $streamerId);
return response()->json($followMessage, Response::HTTP_OK);
} catch (ConflictException $e) {
return response()->json(['error' => $e->getMessage()], Response::HTTP_CONFLICT);
} catch (ForbiddenException $e) {
return response()->json(['error' => $e->getMessage()], Response::HTTP_FORBIDDEN);
} catch (NotFoundException $e) {
return response()->json(['error' => $e->getMessage()], Response::HTTP_NOT_FOUND);
} catch (UnauthorizedException $e) {
return response()->json(['error' => $e->getMessage()], Response::HTTP_UNAUTHORIZED);
} catch (InternalServerErrorException $e) {
return response()->json(['error' => $e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Infrastructure\FollowStreamer;

use Illuminate\Foundation\Http\FormRequest;

class AnalyticsFollowStreamerRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}

public function rules(): array
{
return [
'username' => 'required|string',
'streamerId' => 'required|numeric',
];
}

public function messages()
{
return [
'username.required' => 'El username es obligatorio',
'username.string' => 'El username debe ser una cadena de texto',
'streamerId.required' => 'El streamerId es obligatorio',
'streamerId.numeric' => 'El streamerId debe ser un número',
];
}
}
22 changes: 0 additions & 22 deletions app/Services/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,4 @@ public function makeCurlCall(string $apiUrl, array $apiHeaders): array
'http_code' => $httpCode
];
}

public function post(string $apiUrl, array $apiHeaders, $postData): array
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $apiUrl,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $apiHeaders
]);

$apiResponse = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

curl_close($curl);

return [
'response' => $apiResponse,
'http_code' => $httpCode
];
}
}
36 changes: 0 additions & 36 deletions app/Services/CreateUserManager.php

This file was deleted.

Loading

0 comments on commit bd6297e

Please sign in to comment.