Merge branch 'feature/address-api' into staging
This commit is contained in:
commit
11115c8dc0
2346
backend/.phpstorm.meta.php
Normal file
2346
backend/.phpstorm.meta.php
Normal file
File diff suppressed because it is too large
Load Diff
28541
backend/_ide_helper.php
Normal file
28541
backend/_ide_helper.php
Normal file
File diff suppressed because it is too large
Load Diff
19
backend/app/Actions/DeleteUserAddressAction.php
Normal file
19
backend/app/Actions/DeleteUserAddressAction.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Models\Address;
|
||||
|
||||
final readonly class DeleteUserAddressAction
|
||||
{
|
||||
/**
|
||||
* Execute the action.
|
||||
*/
|
||||
public function execute(Address $address)
|
||||
{
|
||||
$address->users()->detach();
|
||||
$address->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
22
backend/app/Actions/SaveUserAddressAction.php
Normal file
22
backend/app/Actions/SaveUserAddressAction.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Data\AddUserAddressRequestDTO;
|
||||
use App\Data\UserAddressResponseDTO;
|
||||
use App\Models\User;
|
||||
|
||||
final readonly class SaveUserAddressAction
|
||||
{
|
||||
/**
|
||||
* Execute the action.
|
||||
*/
|
||||
public function execute(AddUserAddressRequestDTO $data, User $user)
|
||||
{
|
||||
return UserAddressResponseDTO::fromModel(
|
||||
$user
|
||||
->addresses()
|
||||
->create($data->toArray())
|
||||
);
|
||||
}
|
||||
}
|
||||
21
backend/app/Actions/UpdateUserAddressAction.php
Normal file
21
backend/app/Actions/UpdateUserAddressAction.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Data\UpdateUserAddressRequestDTO;
|
||||
use App\Data\UserAddressResponseDTO;
|
||||
use App\Models\Address;
|
||||
|
||||
final readonly class UpdateUserAddressAction
|
||||
{
|
||||
/**
|
||||
* Execute the action.
|
||||
*/
|
||||
public function execute(UpdateUserAddressRequestDTO $data, Address $address)
|
||||
{
|
||||
$address->update($data->toArray());
|
||||
$address->refresh();
|
||||
|
||||
return UserAddressResponseDTO::fromModel($address);
|
||||
}
|
||||
}
|
||||
63
backend/app/Console/Commands/MakeDtoCommand.php
Normal file
63
backend/app/Console/Commands/MakeDtoCommand.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\GeneratorCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MakeDtoCommand extends GeneratorCommand
|
||||
{
|
||||
/**
|
||||
* The console command name and signature.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'make:dto';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new Data Transfer Object class';
|
||||
|
||||
/**
|
||||
* The type of class being generated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'DTO';
|
||||
|
||||
/**
|
||||
* Get the stub file for the generator.
|
||||
*/
|
||||
protected function getStub(): string
|
||||
{
|
||||
if ($this->option('output')) {
|
||||
return base_path('stubs/dto.output.stub');
|
||||
}
|
||||
|
||||
return base_path('stubs/dto.input.stub');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default namespace for the class.
|
||||
*
|
||||
* @param string $rootNamespace
|
||||
*/
|
||||
protected function getDefaultNamespace($rootNamespace): string
|
||||
{
|
||||
return $rootNamespace.'\Data';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
['input', 'i', InputOption::VALUE_NONE, 'Generate an Input DTO (default)'],
|
||||
['output', 'o', InputOption::VALUE_NONE, 'Generate an Output DTO'],
|
||||
];
|
||||
}
|
||||
}
|
||||
45
backend/app/Data/AddUserAddressRequestDTO.php
Normal file
45
backend/app/Data/AddUserAddressRequestDTO.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Contracts\InputDataTransferObject;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final readonly class AddUserAddressRequestDTO implements InputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
public string $firstName,
|
||||
public string $lastName,
|
||||
public string $street,
|
||||
public string $city,
|
||||
public string $state,
|
||||
public string $pinCode
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => $this->firstName,
|
||||
'last_name' => $this->lastName,
|
||||
'street' => $this->street,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'pin' => $this->pinCode,
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromRequest(FormRequest $request): InputDataTransferObject
|
||||
{
|
||||
return new self(
|
||||
firstName: $request->firstName,
|
||||
lastName: $request->lastName,
|
||||
street: $request->street,
|
||||
city: $request->city,
|
||||
state: $request->state,
|
||||
pinCode: $request->pinCode
|
||||
);
|
||||
}
|
||||
}
|
||||
47
backend/app/Data/UpdateUserAddressRequestDTO.php
Normal file
47
backend/app/Data/UpdateUserAddressRequestDTO.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Contracts\InputDataTransferObject;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final readonly class UpdateUserAddressRequestDTO implements InputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
public ?string $firstName = null,
|
||||
public ?string $lastName = null,
|
||||
public ?string $street = null,
|
||||
public ?string $city = null,
|
||||
public ?string $state = null,
|
||||
public ?string $pinCode = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string = null = null, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$data = [
|
||||
'first_name' => $this->firstName,
|
||||
'last_name' => $this->lastName,
|
||||
'street' => $this->street,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'pin' => $this->pinCode,
|
||||
];
|
||||
|
||||
return array_filter($data, fn ($value) => $value !== null);
|
||||
}
|
||||
|
||||
public static function fromRequest(FormRequest $request): InputDataTransferObject
|
||||
{
|
||||
return new self(
|
||||
firstName: $request->input('firstName'),
|
||||
lastName: $request->input('lastName'),
|
||||
street: $request->input('street'),
|
||||
city: $request->input('city'),
|
||||
state: $request->input('state'),
|
||||
pinCode: $request->input('pinCode'),
|
||||
);
|
||||
}
|
||||
}
|
||||
48
backend/app/Data/UserAddressResponseDTO.php
Normal file
48
backend/app/Data/UserAddressResponseDTO.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Contracts\OutputDataTransferObject;
|
||||
use App\Models\Address;
|
||||
|
||||
final readonly class UserAddressResponseDTO implements OutputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $firstName,
|
||||
public string $lastName,
|
||||
public string $street,
|
||||
public string $city,
|
||||
public string $state,
|
||||
public string $pinCode
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'firstName' => $this->firstName,
|
||||
'lastName' => $this->lastName,
|
||||
'street' => $this->street,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'pinCode' => $this->pinCode,
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromModel(Address $address): OutputDataTransferObject
|
||||
{
|
||||
return new self(
|
||||
id: $address->id,
|
||||
firstName: $address->first_name,
|
||||
lastName: $address->last_name,
|
||||
street: $address->street,
|
||||
city: $address->city,
|
||||
state: $address->state,
|
||||
pinCode: $address->pin
|
||||
);
|
||||
}
|
||||
}
|
||||
61
backend/app/Http/Controllers/UserAddressController.php
Normal file
61
backend/app/Http/Controllers/UserAddressController.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\DeleteUserAddressAction;
|
||||
use App\Actions\SaveUserAddressAction;
|
||||
use App\Actions\UpdateUserAddressAction;
|
||||
use App\Data\AddUserAddressRequestDTO;
|
||||
use App\Data\UpdateUserAddressRequestDTO;
|
||||
use App\Data\UserAddressResponseDTO;
|
||||
use App\Http\Requests\AddUserAddressRequest;
|
||||
use App\Http\Requests\UpdateUserAddressRequest;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Models\Address;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserAddressController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$addresses = $request->user()->addresses;
|
||||
$data = $addresses->map(fn ($address) => UserAddressResponseDTO::fromModel($address));
|
||||
|
||||
return AddressResource::collection($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(AddUserAddressRequest $request, SaveUserAddressAction $action)
|
||||
{
|
||||
return new AddressResource($action->execute(AddUserAddressRequestDTO::fromRequest($request), $request->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Address $address)
|
||||
{
|
||||
return new AddressResource(UserAddressResponseDTO::fromModel($address));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateUserAddressRequest $request, Address $address, UpdateUserAddressAction $action)
|
||||
{
|
||||
return new AddressResource($action->execute(UpdateUserAddressRequestDTO::fromRequest($request), $address));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Address $address, DeleteUserAddressAction $action)
|
||||
{
|
||||
return $action->execute($address);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AddProductToCartRequest extends FormRequest
|
||||
@ -17,7 +18,7 @@ public function authorize(): bool
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
34
backend/app/Http/Requests/AddUserAddressRequest.php
Normal file
34
backend/app/Http/Requests/AddUserAddressRequest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AddUserAddressRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'firstName' => 'required|string|min:3|max:50',
|
||||
'lastName' => 'required|string|min:3|max:50',
|
||||
'street' => 'required|string|min:3|max:100',
|
||||
'city' => 'required|string|min:3|max:20',
|
||||
'state' => 'required|string|min:3|max:40',
|
||||
'pinCode' => 'required|string|min:3|max:10',
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
@ -18,7 +19,7 @@ public function authorize(): bool
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RemoveProductFromCartRequest extends FormRequest
|
||||
@ -17,7 +18,7 @@ public function authorize(): bool
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateProductInCartRequest extends FormRequest
|
||||
@ -17,7 +18,7 @@ public function authorize(): bool
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
35
backend/app/Http/Requests/UpdateUserAddressRequest.php
Normal file
35
backend/app/Http/Requests/UpdateUserAddressRequest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateUserAddressRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'firstName' => 'sometimes|string|min:3|max:50',
|
||||
'lastName' => 'sometimes|string|min:3|max:50',
|
||||
'street' => 'sometimes|string|min:3|max:100',
|
||||
'city' => 'sometimes|string|min:3|max:20',
|
||||
'state' => 'sometimes|string|min:3|max:40',
|
||||
'pinCode' => 'sometimes|string|min:3|max:10',
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UploadImageRequest extends FormRequest
|
||||
@ -17,7 +18,7 @@ public function authorize(): bool
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
19
backend/app/Http/Resources/AddressCollection.php
Normal file
19
backend/app/Http/Resources/AddressCollection.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class AddressCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
32
backend/app/Http/Resources/AddressResource.php
Normal file
32
backend/app/Http/Resources/AddressResource.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Data\UserAddressResponseDTO;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @property UserAddressResponseDTO $resource
|
||||
*/
|
||||
class AddressResource extends JsonResource
|
||||
{
|
||||
public static $wrap = null;
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->resource->id,
|
||||
'firstName' => $this->resource->firstName,
|
||||
'lastName' => $this->resource->lastName,
|
||||
'street' => $this->resource->street,
|
||||
'city' => $this->resource->city,
|
||||
'state' => $this->resource->state,
|
||||
'pinCode' => $this->resource->pinCode,
|
||||
];
|
||||
}
|
||||
}
|
||||
49
backend/app/Models/Address.php
Normal file
49
backend/app/Models/Address.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property-read User|null $user
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address query()
|
||||
*
|
||||
* @property-read Collection<int, User> $users
|
||||
* @property-read int|null $users_count
|
||||
* @property int $id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $street
|
||||
* @property string $city
|
||||
* @property string $state
|
||||
* @property string $pin
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereCity($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereFirstName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereLastName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address wherePin($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereState($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereStreet($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Address whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Address extends Model
|
||||
{
|
||||
protected $fillable = ['first_name', 'last_name', 'street', 'city', 'state', 'pin'];
|
||||
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
}
|
||||
@ -5,8 +5,33 @@
|
||||
use App\Enums\CartStatus;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property CartStatus $status
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Collection<int, Product> $products
|
||||
* @property-read int|null $products_count
|
||||
* @property-read User|null $user
|
||||
*
|
||||
* @method static Builder<static>|Cart active()
|
||||
* @method static Builder<static>|Cart newModelQuery()
|
||||
* @method static Builder<static>|Cart newQuery()
|
||||
* @method static Builder<static>|Cart query()
|
||||
* @method static Builder<static>|Cart whereCreatedAt($value)
|
||||
* @method static Builder<static>|Cart whereId($value)
|
||||
* @method static Builder<static>|Cart whereStatus($value)
|
||||
* @method static Builder<static>|Cart whereUpdatedAt($value)
|
||||
* @method static Builder<static>|Cart whereUserId($value)
|
||||
* @method static Builder<static>|Cart withProducts()
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Cart extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'status'];
|
||||
|
||||
@ -4,12 +4,50 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property string|null $slug
|
||||
* @property string $description
|
||||
* @property numeric $actual_price
|
||||
* @property numeric $list_price
|
||||
* @property int $product_category_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property bool $is_active
|
||||
* @property-read Collection<int, Cart> $carts
|
||||
* @property-read int|null $carts_count
|
||||
* @property-read ProductCategory|null $category
|
||||
* @property-read Collection<int, User> $favoritedBy
|
||||
* @property-read int|null $favorited_by_count
|
||||
* @property-read Collection<int, ProductImage> $images
|
||||
* @property-read int|null $images_count
|
||||
*
|
||||
* @method static Builder<static>|Product active()
|
||||
* @method static Builder<static>|Product newModelQuery()
|
||||
* @method static Builder<static>|Product newQuery()
|
||||
* @method static Builder<static>|Product query()
|
||||
* @method static Builder<static>|Product whereActualPrice($value)
|
||||
* @method static Builder<static>|Product whereCreatedAt($value)
|
||||
* @method static Builder<static>|Product whereDescription($value)
|
||||
* @method static Builder<static>|Product whereId($value)
|
||||
* @method static Builder<static>|Product whereIsActive($value)
|
||||
* @method static Builder<static>|Product whereListPrice($value)
|
||||
* @method static Builder<static>|Product whereProductCategoryId($value)
|
||||
* @method static Builder<static>|Product whereSlug($value)
|
||||
* @method static Builder<static>|Product whereTitle($value)
|
||||
* @method static Builder<static>|Product whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
|
||||
@ -3,7 +3,26 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory whereSlug($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductCategory whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ProductCategory extends Model
|
||||
{
|
||||
//
|
||||
|
||||
@ -4,7 +4,27 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $path
|
||||
* @property int $product_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Product|null $product
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage wherePath($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage whereProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ProductImage whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ProductImage extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
|
||||
@ -4,13 +4,56 @@
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Enums\UserRoles;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Notifications\DatabaseNotificationCollection;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property Carbon|null $email_verified_at
|
||||
* @property string $password
|
||||
* @property string|null $remember_token
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property string $mobile_number
|
||||
* @property string $city
|
||||
* @property UserRoles $role
|
||||
* @property-read Collection<int, Cart> $carts
|
||||
* @property-read int|null $carts_count
|
||||
* @property-read Collection<int, Product> $favoriteProducts
|
||||
* @property-read int|null $favorite_products_count
|
||||
* @property-read DatabaseNotificationCollection<int, DatabaseNotification> $notifications
|
||||
* @property-read int|null $notifications_count
|
||||
*
|
||||
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereCity($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereEmail($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereEmailVerifiedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereMobileNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User wherePassword($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereRememberToken($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereRole($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|User whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory;
|
||||
|
||||
use Notifiable;
|
||||
@ -53,7 +96,7 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function favoriteProducts()
|
||||
public function favoriteProducts(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'favorite_products', 'user_id', 'product_id');
|
||||
}
|
||||
@ -67,4 +110,9 @@ public function carts()
|
||||
{
|
||||
return $this->hasMany(Cart::class);
|
||||
}
|
||||
|
||||
public function addresses(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Address::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Providers\AppServiceProvider;
|
||||
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
AppServiceProvider::class,
|
||||
];
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
"laravel/tinker": "^2.10.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-ide-helper": "^3.6",
|
||||
"fakerphp/faker": "^1.23",
|
||||
"laravel/pail": "^1.2.2",
|
||||
"laravel/pint": "^1.24",
|
||||
@ -55,7 +56,10 @@
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
|
||||
"@php artisan ide-helper:generate",
|
||||
"@php artisan ide-helper:meta"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
|
||||
679
backend/composer.lock
generated
679
backend/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
@ -62,7 +64,7 @@
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => env('AUTH_MODEL', App\Models\User::class),
|
||||
'model' => env('AUTH_MODEL', User::class),
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Pdo\Mysql;
|
||||
|
||||
return [
|
||||
|
||||
@ -59,7 +60,7 @@
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
@ -79,7 +80,7 @@
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
(PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
(PHP_VERSION_ID >= 80500 ? Mysql::ATTR_SSL_CA : PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
|
||||
use Laravel\Sanctum\Http\Middleware\AuthenticateSession;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
@ -76,9 +79,9 @@
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
|
||||
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
|
||||
'authenticate_session' => AuthenticateSession::class,
|
||||
'encrypt_cookies' => EncryptCookies::class,
|
||||
'validate_csrf_token' => ValidateCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@ -2,12 +2,13 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('addresses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('first_name');
|
||||
$table->string('last_name');
|
||||
$table->string('street');
|
||||
$table->string('city');
|
||||
$table->string('state');
|
||||
$table->string('pin');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('addresses');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('address_user', function (Blueprint $table) {
|
||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(Address::class)->constrained()->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('address_user');
|
||||
}
|
||||
};
|
||||
@ -7,6 +7,7 @@
|
||||
use App\Http\Controllers\ProductController;
|
||||
use App\Http\Controllers\ProductImagesController;
|
||||
use App\Http\Controllers\RegisteredUserController;
|
||||
use App\Http\Controllers\UserAddressController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware('guest')->group(function () {
|
||||
@ -24,6 +25,8 @@
|
||||
Route::apiSingleton('/cart', CartController::class)
|
||||
->creatable()
|
||||
->destroyable();
|
||||
|
||||
Route::apiResource('user.addresses', UserAddressController::class)->shallow();
|
||||
});
|
||||
Route::get('/categories', [ProductCategoryController::class, 'index']);
|
||||
Route::apiResource('products', ProductController::class);
|
||||
|
||||
30
backend/stubs/dto.input.stub
Normal file
30
backend/stubs/dto.input.stub
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace {{ namespace }};
|
||||
|
||||
use App\Contracts\InputDataTransferObject;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final readonly class {{ class }} implements InputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
// TODO: Define your properties here
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
// TODO: Map properties to array
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromRequest(FormRequest $request): InputDataTransferObject
|
||||
{
|
||||
return new self(
|
||||
// TODO: Map request data to properties
|
||||
);
|
||||
}
|
||||
}
|
||||
30
backend/stubs/dto.output.stub
Normal file
30
backend/stubs/dto.output.stub
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace {{ namespace }};
|
||||
|
||||
use App\Contracts\OutputDataTransferObject;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final readonly class {{ class }} implements OutputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
// TODO: Define your properties here
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
// TODO: Map properties to array
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromModel(Model $model): OutputDataTransferObject
|
||||
{
|
||||
return new self(
|
||||
// TODO: Map model data to properties
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
@ -11,7 +13,7 @@
|
||||
|
|
||||
*/
|
||||
|
||||
pest()->extend(Tests\TestCase::class)
|
||||
pest()->extend(TestCase::class)
|
||||
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||
->in('Feature');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user