Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactored the entire create products by organisations for admin #523

Merged
merged 16 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 232 additions & 204 deletions app/Http/Controllers/Api/V1/ProductController.php

Large diffs are not rendered by default.

113 changes: 0 additions & 113 deletions app/Http/Controllers/Api/V1/SuperAdmin/SuperAdminProductController.php

This file was deleted.

7 changes: 4 additions & 3 deletions app/Http/Requests/CreateProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public function rules(): array
return [
'name' => 'required|string|max:255',
'description' => 'required|string',
'category' => 'required|string',
'category' => 'required',
'price' => 'required|numeric',
'quantity' => 'required|integer',
'image_url' => 'required|image|mimes:jpeg,png,jpg,gif|max:1024',
'status' => 'required',
'quantity' => 'required',
'image_url' => 'required|file|mimes:jpeg,png,jpg,gif|max:2048',
];
}
}
25 changes: 7 additions & 18 deletions app/Http/Requests/UpdateProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ public function authorize(): bool
public function rules(): array
{
return [
'name' => 'nullable|string|max:255',
'description' => 'nullable|string',
'price' => 'nullable|numeric|min:0',
'stock' => 'nullable|integer|min:0',
'image' => 'nullable|url',
'is_archived' => 'sometimes|boolean',
'productsVariant' => 'required|array',
'productsVariant.*.size_id' => 'required|uuid|exists:sizes,id',
'productsVariant.*.stock' => 'required|integer|min:0',
'productsVariant.*.price' => 'required|numeric|min:0',
'name' => 'nullable',
'quantity' => 'nullable',
'price' => 'nullable',
'category' => 'nullable',
'description' => 'sometimes',


];
}

Expand All @@ -40,12 +37,4 @@ public function rules(): array
*
* @return array
*/
public function attributes()
{
return [
'productsVariant.*.size_id' => 'size ID',
'productsVariant.*.stock' => 'stock quantity',
'productsVariant.*.price' => 'price',
];
}
}
11 changes: 6 additions & 5 deletions app/Http/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class ProductResource extends JsonResource
public function toArray($request)
{
return [
'product_id' => $this->product_id,
'id' => $this->product_id,
'name' => $this->name,
'description' => $this->description,
'price' => $this->price,
'imageUrl' => $this->imageUrl,
'sock' => $this->quantity,
'date_added' => $this->created_at,
'category' => $this->categories->isNotEmpty() ? $this->categories->map->name : [],
'status' => $this->status,
'quantity' => $this->quantity,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,


];
}
Expand Down
10 changes: 0 additions & 10 deletions app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public function user()
return $this->belongsTo(User::class, 'user_id');
}

public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'category_product', 'product_id', 'category_id')->using(CategoryProduct::class);
}

//updated the product variant relationship
public function productsVariant()
{
return $this->hasMany(ProductVariant::class, 'product_id', 'product_id');
}
public function organisation()
{
return $this->belongsTo(Organisation::class);
Expand Down
4 changes: 1 addition & 3 deletions database/factories/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public function definition(): array
'user_id' => $newUser->id,
'name' => $productName,
'price' => $this->faker->randomFloat(2, 0, 1000),
'slug' => $this->faker->unique()->slug,
'tags' => $this->faker->word,
'imageUrl' => $this->faker->imageUrl(),
'status' => $this->faker->randomElement(['active', 'draft']),
'status' => $this->faker->randomElement(['in stock', 'out of stock',]),
'quantity' => $this->faker->numberBetween(1, 100),
'description' => $this->faker->text,
'org_id' => $newOrg->org_id
Expand Down
12 changes: 7 additions & 5 deletions database/migrations/2024_07_23_150138_alter_products_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public function up(): void
{
Schema::table('products', function (Blueprint $table) {
$table->decimal('price');
$table->string('slug')->unique();
$table->string('tags');
$table->decimal('cost_price')->nullable();
$table->enum('size', ['Small', 'Standard', 'Large'])->nullable();
$table->string('imageUrl')->nullable();
$table->enum('status', ['active', 'draft'])->nullable();
$table->enum('status', ['in stock', 'out of stock'])->nullable();
$table->integer('quantity')->default(5);
$table->string('category')->nullable();
});
}

Expand All @@ -28,11 +29,12 @@ public function down(): void
{
Schema::table('products', function (Blueprint $table) {
$table->dropColumn('price');
$table->dropColumn('slug')->unique();
$table->dropColumn('tags');
$table->dropColumn('cost_price');
$table->dropColumn('size');
$table->dropColumn('imageUrl');
$table->dropColumn('status');
$table->dropColumn('quantity');
$table->dropColumn('category');
});
}
};

This file was deleted.

Binary file added public/uploads/1724158752.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1724159454.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1724219479.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1724226709.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/1724228441.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724191282.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724191434.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724192878.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724192919.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724193022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220452.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220476.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220589.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220628.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220685.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724220790.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724223912.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724226700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724228045.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/uploads/product_images/1724228438.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading