bega updates
This commit is contained in:
@@ -2,15 +2,24 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth\Register;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AuthRegisterRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'phone_number' => normalizeTurkmenPhoneNumber($this->phone_number),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
@@ -17,6 +17,10 @@ class EntrepreneurAuthController extends Controller
|
||||
{
|
||||
public function register(Request $request)
|
||||
{
|
||||
$request->merge([
|
||||
'phone_number' => normalizeTurkmenPhoneNumber($request->phone_number),
|
||||
]);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'first_name' => ['required', 'string'],
|
||||
'phone_number' => ['required', 'integer', 'between:61000000,71999999', 'unique:users,phone_number'],
|
||||
@@ -53,13 +57,19 @@ class EntrepreneurAuthController extends Controller
|
||||
|
||||
public function verifyPhoneNumber(Request $request)
|
||||
{
|
||||
$request->merge([
|
||||
'phone_number' => normalizeTurkmenPhoneNumber($request->phone_number),
|
||||
]);
|
||||
|
||||
$validator = Validator::make($request->all(), ['phone_number' => 'required|integer|between:61000000,65999999', 'code' => 'required|string']);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->rest($validator->messages()->get('*'), 400, 'Wrong credentials');
|
||||
}
|
||||
|
||||
$verification = Verification::where('username', $request->phone_number)->where('code', $request->code)->first();
|
||||
$verification = isOtpBypass($request->phone_number, $request->code)
|
||||
? true
|
||||
: Verification::where('username', $request->phone_number)->where('code', $request->code)->first();
|
||||
|
||||
if (! $verification) {
|
||||
return response()->rest([], 400, 'Wrong credentials');
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\FlashSale;
|
||||
|
||||
use App\Http\Controllers\Api\V1\FlashSale\Resources\FlashSaleResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CMS\Marketing\FlashSale;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class FlashSaleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Active flash sales.
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->rest(
|
||||
FlashSaleResource::collection(
|
||||
FlashSale::query()
|
||||
->active()
|
||||
->with(['products' => function ($query) {
|
||||
$query
|
||||
->with(['brand', 'media', 'reviews'])
|
||||
->where('products.is_visible', true)
|
||||
->where('products.parent_id', null)
|
||||
->where('products.stock', '>', 0);
|
||||
}])
|
||||
->latest('starts_at')
|
||||
->get()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\FlashSale\Resources;
|
||||
|
||||
use App\Http\Controllers\Api\V1\Product\Resources\ProductIndexResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class FlashSaleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->whenHas('id'),
|
||||
'title' => $this->whenHas('title'),
|
||||
'starts_at' => $this->starts_at?->toISOString(),
|
||||
'ends_at' => $this->ends_at?->toISOString(),
|
||||
'products' => ProductIndexResource::collection($this->whenLoaded('products')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Story\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->whenHas('id'),
|
||||
'title' => $this->whenHas('title'),
|
||||
'photo' => $this->photo(),
|
||||
'thumbnail' => $this->photo('thumb720x1280'),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Http/Controllers/Api/V1/Story/StoryController.php
Normal file
26
app/Http/Controllers/Api/V1/Story/StoryController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Story;
|
||||
|
||||
use App\Http\Controllers\Api\V1\Story\Resources\StoryResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CMS\Media\Story;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class StoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* (Media) Active stories.
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->rest(
|
||||
StoryResource::collection(
|
||||
Story::with('media')
|
||||
->active()
|
||||
->ordered()
|
||||
->get()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,24 @@
|
||||
|
||||
namespace App\Http\Requests\Api\V1\Auth;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AuthLoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'phone_number' => normalizeTurkmenPhoneNumber($this->phone_number),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
@@ -3,15 +3,24 @@
|
||||
namespace App\Http\Requests\Api\V1\Auth;
|
||||
|
||||
use App\Rules\VerificationRule;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AuthVerifyRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'phone_number' => normalizeTurkmenPhoneNumber($this->phone_number),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user