diff --git a/backend/_ide_helper_models.php b/backend/_ide_helper_models.php index 968ee2c..e027a56 100644 --- a/backend/_ide_helper_models.php +++ b/backend/_ide_helper_models.php @@ -46,7 +46,7 @@ class IdeHelperAddress {} /** * @property int $id * @property int $user_id - * @property \App\Enums\CartStatus $status + * @property \App\Enums\Cart\CartStatus $status * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property-read \App\Models\Order|null $order @@ -87,6 +87,7 @@ class IdeHelperCart {} * @property-read \Illuminate\Database\Eloquent\Collection $payments * @property-read int|null $payments_count * @property-read \App\Models\StripeSession|null $stripeSession + * @property-read mixed $total_amount * @property-read \App\Models\User $user * @method static \Illuminate\Database\Eloquent\Builder|Order newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Order newQuery() @@ -272,7 +273,7 @@ class IdeHelperStripeSession {} * @property \Illuminate\Support\Carbon|null $updated_at * @property string $mobile_number * @property string $city - * @property \App\Enums\UserRoles $role + * @property \App\Enums\User\UserRoles $role * @property-read \Illuminate\Database\Eloquent\Collection $addresses * @property-read int|null $addresses_count * @property-read \Illuminate\Database\Eloquent\Collection $carts diff --git a/backend/app/Actions/DeleteUserAddressAction.php b/backend/app/Actions/Address/DeleteUserAddressAction.php similarity index 90% rename from backend/app/Actions/DeleteUserAddressAction.php rename to backend/app/Actions/Address/DeleteUserAddressAction.php index 40e0239..e9d28b5 100644 --- a/backend/app/Actions/DeleteUserAddressAction.php +++ b/backend/app/Actions/Address/DeleteUserAddressAction.php @@ -1,6 +1,6 @@ firstName, + lastName: $request->lastName, + street: $request->street, + city: $request->city, + state: $request->state, + pinCode: $request->pinCode + ); + } + /** * @return array */ @@ -30,16 +42,4 @@ public function toArray(): array '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 - ); - } } diff --git a/backend/app/Data/UpdateUserAddressRequestDTO.php b/backend/app/Data/Address/UpdateUserAddressRequestDTO.php similarity index 97% rename from backend/app/Data/UpdateUserAddressRequestDTO.php rename to backend/app/Data/Address/UpdateUserAddressRequestDTO.php index 5817b4f..612bf5b 100644 --- a/backend/app/Data/UpdateUserAddressRequestDTO.php +++ b/backend/app/Data/Address/UpdateUserAddressRequestDTO.php @@ -1,6 +1,6 @@ input('firstName'), + lastName: $request->input('lastName'), + street: $request->input('street'), + city: $request->input('city'), + state: $request->input('state'), + pinCode: $request->input('pinCode'), + ); + } + /** * @return array */ @@ -32,16 +44,4 @@ public function toArray(): array 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'), - ); - } } diff --git a/backend/app/Data/UserAddressResponseDTO.php b/backend/app/Data/Address/UserAddressResponseDTO.php similarity index 97% rename from backend/app/Data/UserAddressResponseDTO.php rename to backend/app/Data/Address/UserAddressResponseDTO.php index cb23fa0..25393e5 100644 --- a/backend/app/Data/UserAddressResponseDTO.php +++ b/backend/app/Data/Address/UserAddressResponseDTO.php @@ -1,6 +1,6 @@ id, + firstName: $address->first_name, + lastName: $address->last_name, + street: $address->street, + city: $address->city, + state: $address->state, + pinCode: $address->pin + ); + } + /** * @return array */ @@ -32,17 +45,4 @@ public function toArray(): array '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 - ); - } } diff --git a/backend/app/Data/AddToCartDTO.php b/backend/app/Data/Cart/AddToCartDTO.php similarity index 96% rename from backend/app/Data/AddToCartDTO.php rename to backend/app/Data/Cart/AddToCartDTO.php index 2035573..4226c5a 100644 --- a/backend/app/Data/AddToCartDTO.php +++ b/backend/app/Data/Cart/AddToCartDTO.php @@ -1,6 +1,6 @@ productId, + quantity: $request->quantity + ); + } + /** * @return array */ @@ -22,12 +30,4 @@ public function toArray(): array 'quantity' => $this->quantity, ]; } - - public static function fromRequest(FormRequest $request): InputDataTransferObject - { - return new self( - productId: $request->productId, - quantity: $request->quantity - ); - } } diff --git a/backend/app/Data/CartDTO.php b/backend/app/Data/Cart/CartDTO.php similarity index 98% rename from backend/app/Data/CartDTO.php rename to backend/app/Data/Cart/CartDTO.php index f618ccd..7a47f97 100644 --- a/backend/app/Data/CartDTO.php +++ b/backend/app/Data/Cart/CartDTO.php @@ -1,6 +1,6 @@ - */ - public function toArray(): array - { - return [ - 'id' => $this->id, - 'itemsCount' => $this->itemsCount, - 'totalPrice' => $this->totalPrice, - 'items' => $this->items, - ]; - } - public static function fromModel(Cart $cart) { return new self( @@ -46,4 +33,17 @@ public static function fromModel(Cart $cart) ))->toArray() ); } + + /** + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'itemsCount' => $this->itemsCount, + 'totalPrice' => $this->totalPrice, + 'items' => $this->items, + ]; + } } diff --git a/backend/app/Data/CartItemDTO.php b/backend/app/Data/Cart/CartItemDTO.php similarity index 96% rename from backend/app/Data/CartItemDTO.php rename to backend/app/Data/Cart/CartItemDTO.php index 8e024ff..72d0f9c 100644 --- a/backend/app/Data/CartItemDTO.php +++ b/backend/app/Data/Cart/CartItemDTO.php @@ -1,6 +1,6 @@ */ @@ -20,10 +26,4 @@ public function toArray(): array // TODO: Map properties to array ]; } - - public static function fromModel(Model $model): OutputDataTransferObject - { - return new self; - // TODO: Map model data to properties - } } diff --git a/backend/app/Data/OrderRequestDTO.php b/backend/app/Data/Order/OrderRequestDTO.php similarity index 96% rename from backend/app/Data/OrderRequestDTO.php rename to backend/app/Data/Order/OrderRequestDTO.php index 0855509..9dbe7a1 100644 --- a/backend/app/Data/OrderRequestDTO.php +++ b/backend/app/Data/Order/OrderRequestDTO.php @@ -1,6 +1,6 @@ cartId, + addressId: $request->addressId, + ); + } + /** * @return array */ @@ -22,12 +30,4 @@ public function toArray(): array 'address_id' => $this->addressId, ]; } - - public static function fromRequest(FormRequest $request): OrderRequestDTO - { - return new self( - cartId: $request->cartId, - addressId: $request->addressId, - ); - } } diff --git a/backend/app/Data/PaymentResponseDTO.php b/backend/app/Data/Payment/PaymentResponseDTO.php similarity index 96% rename from backend/app/Data/PaymentResponseDTO.php rename to backend/app/Data/Payment/PaymentResponseDTO.php index fe48fea..c1605fa 100644 --- a/backend/app/Data/PaymentResponseDTO.php +++ b/backend/app/Data/Payment/PaymentResponseDTO.php @@ -1,9 +1,9 @@ id, + name: $category->name, + slug: $category->slug, + ); + } + /** * @return array */ @@ -24,13 +33,4 @@ public function toArray(): array 'slug' => $this->slug, ]; } - - public static function fromModel(ProductCategory $category): self - { - return new self( - id: $category->id, - name: $category->name, - slug: $category->slug, - ); - } } diff --git a/backend/app/Data/ProductDTO.php b/backend/app/Data/Product/ProductDTO.php similarity index 98% rename from backend/app/Data/ProductDTO.php rename to backend/app/Data/Product/ProductDTO.php index 4190d09..721131c 100644 --- a/backend/app/Data/ProductDTO.php +++ b/backend/app/Data/Product/ProductDTO.php @@ -1,6 +1,6 @@ id, + title: $product->title, + slug: $product->slug, + description: $product->description, + actualPrice: $product->actual_price, + listPrice: $product->list_price, + category: ProductCategoryDTO::fromModel($product->category), + productImages: $product->images->map(fn (ProductImage $productImage) => ProductImageDTO::fromModel($productImage))->all(), + updatedAt: $product->updated_at, + createdAt: $product->created_at, + // this column is added by where exists query + isFavorite: $product->favorited_by_exists, + ); + } + /** * @return array */ @@ -45,22 +63,4 @@ public function toArray(): array 'isFavorite' => $this->isFavorite, ]; } - - public static function fromModel(Product $product): self - { - return new self( - id: $product->id, - title: $product->title, - slug: $product->slug, - description: $product->description, - actualPrice: $product->actual_price, - listPrice: $product->list_price, - category: ProductCategoryDTO::fromModel($product->category), - productImages: $product->images->map(fn (ProductImage $productImage) => ProductImageDTO::fromModel($productImage))->all(), - updatedAt: $product->updated_at, - createdAt: $product->created_at, - // this column is added by where exists query - isFavorite: $product->favorited_by_exists, - ); - } } diff --git a/backend/app/Data/ProductImageDTO.php b/backend/app/Data/Product/ProductImageDTO.php similarity index 96% rename from backend/app/Data/ProductImageDTO.php rename to backend/app/Data/Product/ProductImageDTO.php index 0736274..f218f60 100644 --- a/backend/app/Data/ProductImageDTO.php +++ b/backend/app/Data/Product/ProductImageDTO.php @@ -1,6 +1,6 @@ id, + $productImage->path, + $productImage->product_id + ); + } + /** * @return array */ @@ -24,13 +33,4 @@ public function toArray(): array 'productId' => $this->productId, ]; } - - public static function fromModel(ProductImage $productImage): self - { - return new self( - $productImage->id, - $productImage->path, - $productImage->product_id - ); - } } diff --git a/backend/app/Data/StripeLineItemDTO.php b/backend/app/Data/Stripe/StripeLineItemDTO.php similarity index 92% rename from backend/app/Data/StripeLineItemDTO.php rename to backend/app/Data/Stripe/StripeLineItemDTO.php index 112dbc9..b2ab270 100644 --- a/backend/app/Data/StripeLineItemDTO.php +++ b/backend/app/Data/Stripe/StripeLineItemDTO.php @@ -1,9 +1,9 @@ The order was placed or created. There is work to do for the order, which can include processing payment, fulfilling, or processing returns. diff --git a/backend/app/Enums/PaymentModes.php b/backend/app/Enums/Payment/PaymentModes.php similarity index 81% rename from backend/app/Enums/PaymentModes.php rename to backend/app/Enums/Payment/PaymentModes.php index 4bd844d..744e520 100644 --- a/backend/app/Enums/PaymentModes.php +++ b/backend/app/Enums/Payment/PaymentModes.php @@ -1,6 +1,6 @@ - */ - protected function casts(): array - { - return [ - 'status' => CartStatus::class, - ]; - } - public function products(): BelongsToMany { return $this->belongsToMany(Product::class) @@ -43,6 +33,16 @@ public function order(): BelongsTo return $this->belongsTo(Order::class); } + /** + * @return array + */ + protected function casts(): array + { + return [ + 'status' => CartStatus::class, + ]; + } + #[Scope] protected function active(Builder $query) { diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php index 4445f3b..1391f8c 100644 --- a/backend/app/Models/User.php +++ b/backend/app/Models/User.php @@ -3,7 +3,7 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; -use App\Enums\UserRoles; +use App\Enums\User\UserRoles; use Database\Factories\UserFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -45,18 +45,9 @@ class User extends Authenticatable 'remember_token', ]; - /** - * Get the attributes that should be cast. - * - * @return array - */ - protected function casts(): array + public function hasFavorited(Product $product): bool { - return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - 'role' => UserRoles::class, - ]; + return $this->favoriteProducts()->where('product_id', $product->id)->exists(); } public function favoriteProducts(): BelongsToMany @@ -64,11 +55,6 @@ public function favoriteProducts(): BelongsToMany return $this->belongsToMany(Product::class, 'favorite_products', 'user_id', 'product_id'); } - public function hasFavorited(Product $product): bool - { - return $this->favoriteProducts()->where('product_id', $product->id)->exists(); - } - /** * @return HasMany */ @@ -92,4 +78,18 @@ public function orders(): HasMany { return $this->hasMany(Order::class); } + + /** + * Get the attributes that should be cast. + * + * @return array + */ + protected function casts(): array + { + return [ + 'email_verified_at' => 'datetime', + 'password' => 'hashed', + 'role' => UserRoles::class, + ]; + } } diff --git a/backend/app/Services/Payment/PaymentGatewayFactory.php b/backend/app/Services/Payment/PaymentGatewayFactory.php index b75dba8..4d645db 100644 --- a/backend/app/Services/Payment/PaymentGatewayFactory.php +++ b/backend/app/Services/Payment/PaymentGatewayFactory.php @@ -2,7 +2,7 @@ namespace App\Services\Payment; -use App\Enums\PaymentModes; +use App\Enums\Payment\PaymentModes; class PaymentGatewayFactory { diff --git a/backend/app/Services/Payment/StripePaymentGateway.php b/backend/app/Services/Payment/StripePaymentGateway.php index a352a42..11688d6 100644 --- a/backend/app/Services/Payment/StripePaymentGateway.php +++ b/backend/app/Services/Payment/StripePaymentGateway.php @@ -3,12 +3,12 @@ namespace App\Services\Payment; use App\Contracts\PaymentGateway; -use App\Data\PaymentResponseDTO; -use App\Data\StripeLineItemDTO; -use App\Data\StripeSessionDataDTO; -use App\Enums\PaymentModes; -use App\Enums\StripeCurrency; -use App\Enums\StripePaymentMode; +use App\Data\Payment\PaymentResponseDTO; +use App\Data\Stripe\StripeLineItemDTO; +use App\Data\Stripe\StripeSessionDataDTO; +use App\Enums\Payment\PaymentModes; +use App\Enums\Stripe\StripeCurrency; +use App\Enums\Stripe\StripePaymentMode; use App\Models\Order; use Exception; use Illuminate\Support\Facades\Log; diff --git a/backend/database/migrations/2026_02_27_044159_add_role_to_users.php b/backend/database/migrations/2026_02_27_044159_add_role_to_users.php index 7158dc2..3a8567b 100644 --- a/backend/database/migrations/2026_02_27_044159_add_role_to_users.php +++ b/backend/database/migrations/2026_02_27_044159_add_role_to_users.php @@ -1,6 +1,6 @@