Version 0.7.0 #1
15
app/ServiceResults/ServiceResultSuccess.php
Normal file
15
app/ServiceResults/ServiceResultSuccess.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\ServiceResults;
|
||||||
|
|
||||||
|
final class ServiceResultSuccess extends ServiceResult
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly string $message
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getMessage(): string
|
||||||
|
{
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
}
|
@ -4,8 +4,8 @@ namespace App\Services;
|
|||||||
|
|
||||||
use App\Dto\Request\Authorization;
|
use App\Dto\Request\Authorization;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\ServiceResults\ServiceResultArray;
|
|
||||||
use App\ServiceResults\ServiceResultError;
|
use App\ServiceResults\ServiceResultError;
|
||||||
|
use App\ServiceResults\ServiceResultSuccess;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ final class AuthService extends Service
|
|||||||
private readonly UserRepository $userRepository
|
private readonly UserRepository $userRepository
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function authorization(Authorization $authorization): ServiceResultError | ServiceResultArray
|
public function authorization(Authorization $authorization): ServiceResultError | ServiceResultSuccess
|
||||||
{
|
{
|
||||||
$user = $this->userRepository->getUserByEmail($authorization->getEmail());
|
$user = $this->userRepository->getUserByEmail($authorization->getEmail());
|
||||||
if (is_null($user)) {
|
if (is_null($user)) {
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Services;
|
|||||||
|
|
||||||
use App\ServiceResults\ServiceResultArray;
|
use App\ServiceResults\ServiceResultArray;
|
||||||
use App\ServiceResults\ServiceResultError;
|
use App\ServiceResults\ServiceResultError;
|
||||||
|
use App\ServiceResults\ServiceResultSuccess;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
abstract class Service
|
abstract class Service
|
||||||
@ -39,9 +40,9 @@ abstract class Service
|
|||||||
return $this->error(Response::HTTP_UNAUTHORIZED, $message);
|
return $this->error(Response::HTTP_UNAUTHORIZED, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function ok(string $message = 'OK'): ServiceResultArray
|
final protected function ok(string $message = 'OK'): ServiceResultSuccess
|
||||||
{
|
{
|
||||||
return $this->result(['message' => $message]);
|
return new ServiceResultSuccess($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function result(array $data = []): ServiceResultArray
|
final protected function result(array $data = []): ServiceResultArray
|
||||||
|
Loading…
Reference in New Issue
Block a user