client api
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\Client\ClientAuthRequest;
|
||||
use App\Http\Requests\Api\Client\ClientRegisterRequest;
|
||||
use App\Http\Resources\Api\Client\ClientResource;
|
||||
use App\Services\Api\Client\ClientAuthService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
protected $authService;
|
||||
|
||||
public function __construct(ClientAuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lấy thông tin khách hàng hiện tại
|
||||
*/
|
||||
public function me()
|
||||
{
|
||||
return new ClientResource(auth('sanctum')->user());
|
||||
}
|
||||
|
||||
/**
|
||||
* Đăng nhập khách hàng
|
||||
*/
|
||||
public function login(ClientAuthRequest $request)
|
||||
{
|
||||
$result = $this->authService->authenticateClient($request->validated());
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'client' => new ClientResource($result['client']),
|
||||
'token' => $result['token'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Đăng ký khách hàng mới
|
||||
*/
|
||||
public function register(ClientRegisterRequest $request)
|
||||
{
|
||||
$result = $this->authService->registerClient($request->validated());
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'client' => new ClientResource($result['client']),
|
||||
'token' => $result['token'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Đăng xuất khách hàng
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
auth('sanctum')->user()->currentAccessToken()->delete();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã đăng xuất thành công.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user