forked from eatvio/eatvio-infra
refactor code-style rector and php-insight
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Sentry\Laravel\Integration;
|
||||
use Throwable;
|
||||
|
||||
@@ -35,6 +38,14 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->renderable(static function (Exception $exception, Request $request) {
|
||||
if ($exception instanceof \DomainException && $request->expectsJson()) {
|
||||
return response()->json([
|
||||
'message' => $exception->getMessage(),
|
||||
], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
});
|
||||
|
||||
$this->reportable(function (Throwable $e) {
|
||||
Integration::captureUnhandledException($e);
|
||||
});
|
||||
|
||||
0
app/Http/Controllers/BlogPostController.php
Normal file → Executable file
0
app/Http/Controllers/BlogPostController.php
Normal file → Executable file
0
app/Http/Controllers/CalendarController.php
Normal file → Executable file
0
app/Http/Controllers/CalendarController.php
Normal file → Executable file
0
app/Http/Controllers/ChatController.php
Normal file → Executable file
0
app/Http/Controllers/ChatController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantDiaryCommentController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantDiaryCommentController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantRequestFormController.php
Normal file → Executable file
0
app/Http/Controllers/ConsultantRequestFormController.php
Normal file → Executable file
0
app/Http/Controllers/Controller.php
Normal file → Executable file
0
app/Http/Controllers/Controller.php
Normal file → Executable file
0
app/Http/Controllers/DiaryController.php
Normal file → Executable file
0
app/Http/Controllers/DiaryController.php
Normal file → Executable file
0
app/Http/Controllers/DietController.php
Normal file → Executable file
0
app/Http/Controllers/DietController.php
Normal file → Executable file
0
app/Http/Controllers/FeedController.php
Normal file → Executable file
0
app/Http/Controllers/FeedController.php
Normal file → Executable file
0
app/Http/Controllers/FinanceController.php
Normal file → Executable file
0
app/Http/Controllers/FinanceController.php
Normal file → Executable file
18
app/Http/Controllers/Mobile/MobileProfileController.php
Normal file → Executable file
18
app/Http/Controllers/Mobile/MobileProfileController.php
Normal file → Executable file
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Mobile;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Models\User;
|
||||
use App\Models\CircumferenceMeasure;
|
||||
use App\Models\Plan;
|
||||
use App\Models\WeightMeasure;
|
||||
use App\Models\CircumferenceMeasure;
|
||||
use Auth;
|
||||
class MobileProfileController {
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
public function index(Request $request)
|
||||
class MobileProfileController
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
@@ -34,7 +34,7 @@ class MobileProfileController {
|
||||
return response()->json(['user' => $user, 'chartPoints' => $chartPoints, 'userDetails' => $userDetails, 'circumferences' => $circumferences, 'plans' => $plans], 200);
|
||||
}
|
||||
|
||||
public function addWeight(Request $request)
|
||||
public function addWeight(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'weight' => 'required|int',
|
||||
@@ -54,7 +54,7 @@ class MobileProfileController {
|
||||
$newMeasure->save();
|
||||
return response()->json(200);
|
||||
}
|
||||
public function addCircumference(Request $request)
|
||||
public function addCircumference(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'chest_circumference' => 'required|int',
|
||||
|
||||
@@ -8,7 +8,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Fortify\Http\Requests\LoginRequest;
|
||||
use Laravel\Sanctum\NewAccessToken;
|
||||
|
||||
class MobileRegisterController
|
||||
{
|
||||
@@ -23,9 +22,11 @@ class MobileRegisterController
|
||||
{
|
||||
$this->service->registerCommand($request);
|
||||
|
||||
if (!$token = $this->attemptLoginAndCreateToken($request)) {
|
||||
return response()->json(['error' => 'Упс! Произошла ошибка при регистрации. Проверьте введенные данные'],
|
||||
Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
if (! $token = $this->attemptLoginAndCreateToken($request)) {
|
||||
return response()->json(
|
||||
['error' => 'Упс! Произошла ошибка при регистрации. Проверьте введенные данные'],
|
||||
Response::HTTP_UNPROCESSABLE_ENTITY
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json(['token' => $token], Response::HTTP_OK);
|
||||
@@ -35,9 +36,11 @@ class MobileRegisterController
|
||||
|
||||
public function login(LoginRequest $request): JsonResponse
|
||||
{
|
||||
if (!$token = $this->attemptLoginAndCreateToken($request)) {
|
||||
return response()->json(['error' => 'Упс! Произошла ошибка при аутентификации. Проверьте введенные данные'],
|
||||
Response::HTTP_UNAUTHORIZED);
|
||||
if (! $token = $this->attemptLoginAndCreateToken($request)) {
|
||||
return response()->json(
|
||||
['error' => 'Упс! Произошла ошибка при аутентификации. Проверьте введенные данные'],
|
||||
Response::HTTP_UNAUTHORIZED
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json(['token' => $token], Response::HTTP_OK);
|
||||
@@ -45,7 +48,7 @@ class MobileRegisterController
|
||||
|
||||
private function attemptLoginAndCreateToken(RegisterRequest|LoginRequest $request): ?string
|
||||
{
|
||||
if (Auth::attempt($request->only('email', 'password'))) {
|
||||
if (Auth::attempt($request->only(['email', 'password']))) {
|
||||
return $request->user()->createToken('mobile')->plainTextToken;
|
||||
}
|
||||
|
||||
@@ -59,5 +62,4 @@ class MobileRegisterController
|
||||
// 'message' => 'Logged out'
|
||||
// ];
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
0
app/Http/Controllers/PlanController.php
Normal file → Executable file
0
app/Http/Controllers/PlanController.php
Normal file → Executable file
0
app/Http/Controllers/ProductNutritionalValueController.php
Normal file → Executable file
0
app/Http/Controllers/ProductNutritionalValueController.php
Normal file → Executable file
0
app/Http/Controllers/ProfileController.php
Normal file → Executable file
0
app/Http/Controllers/ProfileController.php
Normal file → Executable file
0
app/Http/Controllers/RecipeController.php
Normal file → Executable file
0
app/Http/Controllers/RecipeController.php
Normal file → Executable file
0
app/Http/Controllers/RegistrationStartController.php
Normal file → Executable file
0
app/Http/Controllers/RegistrationStartController.php
Normal file → Executable file
0
app/Http/Controllers/UserController.php
Normal file → Executable file
0
app/Http/Controllers/UserController.php
Normal file → Executable file
0
app/Http/Controllers/UserDetailzController.php
Normal file → Executable file
0
app/Http/Controllers/UserDetailzController.php
Normal file → Executable file
0
app/Http/Kernel.php
Normal file → Executable file
0
app/Http/Kernel.php
Normal file → Executable file
0
app/Http/Middleware/Authenticate.php
Normal file → Executable file
0
app/Http/Middleware/Authenticate.php
Normal file → Executable file
0
app/Http/Middleware/EncryptCookies.php
Normal file → Executable file
0
app/Http/Middleware/EncryptCookies.php
Normal file → Executable file
0
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file → Executable file
0
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file → Executable file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file → Executable file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file → Executable file
0
app/Http/Middleware/TrimStrings.php
Normal file → Executable file
0
app/Http/Middleware/TrimStrings.php
Normal file → Executable file
0
app/Http/Middleware/TrustHosts.php
Normal file → Executable file
0
app/Http/Middleware/TrustHosts.php
Normal file → Executable file
0
app/Http/Middleware/TrustProxies.php
Normal file → Executable file
0
app/Http/Middleware/TrustProxies.php
Normal file → Executable file
0
app/Http/Middleware/VerifyCsrfToken.php
Normal file → Executable file
0
app/Http/Middleware/VerifyCsrfToken.php
Normal file → Executable file
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use App\Rules\MinWords;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Rules\MinWords;
|
||||
|
||||
class RegisterRequest extends FormRequest
|
||||
{
|
||||
@@ -39,7 +39,7 @@ class RegisterRequest extends FormRequest
|
||||
];
|
||||
|
||||
$defaults_values = [
|
||||
0, 0, 0, 0, 0, false, false, '', '', '', '', '', '', true, true
|
||||
0, 0, 0, 0, 0, false, false, '', '', '', '', '', '', true, true,
|
||||
];
|
||||
|
||||
foreach ($fields as $index => $field) {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Http\Requests\Auth\RegisterRequest;
|
||||
use App\Models\CircumferenceMeasure;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDetailz;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Http\Requests\Auth\RegisterRequest;
|
||||
|
||||
/**
|
||||
* Class RegisterService.
|
||||
@@ -21,20 +21,16 @@ class RegisterService
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
$token = $newUser->createToken('mobile');
|
||||
|
||||
UserDetailz::create($this->buildUserDetailz($request, $newUser));
|
||||
|
||||
CircumferenceMeasure::create([
|
||||
'user_id' => $newUser->id,
|
||||
'chest_circumference' => $request->chest_circumference,
|
||||
'waist_circumference' => $request->waist_circumference,
|
||||
'hip_circumference' => $request->hip_circumference
|
||||
'hip_circumference' => $request->hip_circumference,
|
||||
]);
|
||||
}
|
||||
|
||||
public function login(){}
|
||||
|
||||
private function buildUserDetailz(RegisterRequest $request, User $newUser): array
|
||||
{
|
||||
$userDetailzData = [];
|
||||
@@ -43,11 +39,10 @@ class RegisterService
|
||||
'first_name', 'last_name', 'birthdate', 'gender', 'country', 'city', 'lang', 'weight', 'height',
|
||||
'chest_circumference', 'waist_circumference', 'hip_circumference', 'blood_pressure_up', 'blood_pressure_down',
|
||||
'has_hypo', 'has_hyper', 'about_alergy', 'about_taking_pils', 'about_sport_hobbies', 'favorite_foods',
|
||||
'unfavorite_foods', 'additional_info', 'is_mood_fillable', 'is_bedtime_fillable'
|
||||
'unfavorite_foods', 'additional_info', 'is_mood_fillable', 'is_bedtime_fillable',
|
||||
];
|
||||
|
||||
foreach($fields as $index => $field)
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$userDetailzData[$field] = $request->{$field};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use App\Http\Controllers\Mobile\MobileProfileController;
|
||||
use App\Http\Controllers\Mobile\MobileRegisterController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
@@ -19,13 +18,13 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::group([
|
||||
[
|
||||
// 'namespace' => 'App\Http\Controllers\Mobile',
|
||||
]
|
||||
],
|
||||
], static function (): void {
|
||||
Route::post('/register', [MobileRegisterController::class, 'register'])->name('register');
|
||||
Route::post('/login', [MobileRegisterController::class, 'login'])->name('login');
|
||||
Route::group([
|
||||
'middleware' => ['auth:sanctum'],
|
||||
'prefix' => 'profile'
|
||||
'prefix' => 'profile',
|
||||
], static function () {
|
||||
Route::get('/index', [MobileProfileController::class, 'index']);
|
||||
Route::post('/addWeight', [MobileProfileController::class, 'addWeight']);
|
||||
|
||||
@@ -54,6 +54,7 @@ class RegisterTest extends TestCase
|
||||
public function test_register_failed_this_email_already_taken()
|
||||
{
|
||||
$user = User::factory()->create(['is_consultant' => true]);
|
||||
|
||||
$response = $this->postJson('/api/register', [
|
||||
'email' => $user->email,
|
||||
'password' => $this->user->password,
|
||||
@@ -80,7 +81,7 @@ class RegisterTest extends TestCase
|
||||
|
||||
public function test_register_failed_empty_data()
|
||||
{
|
||||
$user = User::factory()->create(['is_consultant' => true]);
|
||||
User::factory()->create(['is_consultant' => true]);
|
||||
$response = $this->postJson('/api/register', [
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
|
||||
Reference in New Issue
Block a user