Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…php_laravel_web into feat/fetch-a-role-in-an-organisation-endpoint
  • Loading branch information
sparkybug committed Aug 10, 2024
2 parents f6c5e55 + 7688039 commit 05402a2
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ yarn-error.log
docker-compose.yml
/public/uploads
ResponseHTTP_OK,
can
can
22 changes: 10 additions & 12 deletions app/Http/Controllers/Api/V1/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use App\Http\Resources\ProductResource;
use App\Models\Order;


class ProductController extends Controller
{

public function search(Request $request)
{
$validator = Validator::make($request->all(), [
Expand Down Expand Up @@ -202,33 +204,29 @@ public function store(CreateProductRequest $request, $org_id)
}

$imageUrl = null;
if ($request->hasFile('image')) {
$imagePath = $request->file('image')->store('product_images', 'public');
if ($request->hasFile('image_url')) {
$imagePath = $request->file('image_url')->store('product_images', 'public');
$imageUrl = Storage::url($imagePath);
}

$product = Product::create([
'name' => $request->input('title'),
'name' => $request->input('name'),
'description' => $request->input('description'),
'slug' => Carbon::now(),
'tags' => $request->input('category'),
'category' => $request->input('category'),
'price' => $request->input('price'),
'imageUrl' => $imageUrl,
'user_id' => auth()->id(),
'org_id' => $org_id
]);

CategoryProduct::create([
'category_id' => $request->input('category'),
'product_id' => $product->product_id
]);

$standardSize = Size::where('size', 'standard')->first('id');

$standardSize = Size::where('size', 'standard')->value('id');
// dd($standardSize);
$productVariant = ProductVariant::create([
'product_id' => $product->product_id,
'stock' => $request->input('stock'),
'stock_status' => $request->input('stock') > 0 ? 'in_stock' : 'out_stock',
'stock' => $request->input('quantity'),
'stock_status' => $request->input('quantity') > 0 ? 'in_stock' : 'out_stock',
'price' => $request->input('price'),
'size_id' => $standardSize->id,
]);
Expand Down
71 changes: 71 additions & 0 deletions app/Http/Controllers/SqueezePageUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\SqueezePageUser;

class SqueezePageUserController extends Controller
{
public function store(Request $request)
{
$validatedData = $request->validate([
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'email' => 'required|string|email|max:255',
'title' => 'required|string|max:255',
]);

$squeezePageUser = SqueezePageUser::create([
'firstname' => $validatedData['firstname'],
'lastname' => $validatedData['lastname'],
'email' => $validatedData['email'],
'title' => $validatedData['title'],
]);

return response()->json([
'message' => 'User details successfully added to squeeze_pages_user.',
'data' => $squeezePageUser,
'status_code' => 201,
], 201);
}

public function index(Request $request)
{
if (auth()->user()->role !== 'admin') {
return response()->json([
'success' => false,
'message' => 'Only admin users can get users.',
], Response::HTTP_FORBIDDEN);
}

$request->validate([
'page' => 'integer|min:1',
'limit' => 'integer|min:1',
]);

$page = $request->input('page', 1);
$limit = $request->input('limit', 10);

$offset = ($page - 1) * $limit;

$squeezePageUsers = SqueezePageUser::select('firstname', 'lastname', 'email', 'title', 'created_at')
->offset($offset)
->limit($limit)
->get();

$totalItems = SqueezePageUser::count();
$totalPages = ceil($totalItems / $limit);

return response()->json([
'message' => 'User details retrieved successfully.',
'data' => $squeezePageUsers,
'pagination' => [
'totalItems' => $totalItems,
'totalPages' => $totalPages,
'currentPage' => $page,
],
'status_code' => 200,
], 200);
}
}
8 changes: 4 additions & 4 deletions app/Http/Requests/CreateProductRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function authorize(): bool
public function rules(): array
{
return [
'title' => 'required|string|max:255',
'name' => 'required|string|max:255',
'description' => 'required|string',
'category' => 'required|uuid|exists:categories,id',
'category' => 'required|string',
'price' => 'required|numeric',
'stock' => 'required|integer',
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:1024',
'quantity' => 'required|integer',
'image_url' => 'required|image|mimes:jpeg,png,jpg,gif|max:1024',
];
}
}
2 changes: 1 addition & 1 deletion app/Models/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function ProductVariant()
return $this->belongsTo(ProductVariant::class);
}

public function productVariantsSize(): HasMany
public function productVariantsSize()
{
return $this->hasMany(ProductVariantSize::class);
}
Expand Down
2 changes: 0 additions & 2 deletions app/Models/SqueezePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ class SqueezePage extends Model
'hero_image',
'content',
];


}
19 changes: 19 additions & 0 deletions app/Models/SqueezePageUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;

class SqueezePageUser extends Model
{
use HasFactory, HasUuids;

protected $table = 'squeeze_pages_user';

protected $guarded = [];

protected $keyType = 'string';

}
28 changes: 28 additions & 0 deletions database/factories/SqueezePageUserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\SqueezePageUser;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SqueezePageUser>
*/
class SqueezePageUserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
protected $model = SqueezePageUser::class;

public function definition(): array
{
return [
'firstname' => $this->faker->firstName,
'lastname' => $this->faker->lastName,
'email' => $this->faker->safeEmail,
'title' => $this->faker->sentence(3),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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('squeeze_pages_user', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('firstname');
$table->string('lastname');
$table->string('email');
$table->string('title');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('squeeze_pages_user');
}
};
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function run(): void
$this->call([ArticlesTableSeeder::class]);
$this->call(UserJobSeeder::class);
$this->call(BlogSeeder::class);
$this->call(SqueezePageUserSeeder::class);


UserSubscription::factory()->create();
Expand Down
3 changes: 3 additions & 0 deletions database/seeders/SqueezePageSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;


class SqueezePageSeeder extends Seeder
{
/**
* Run the database seeds.
*/

public function run(): void
{

$squeezePages = [
[
'title' => 'Digital Marketing',
Expand Down
18 changes: 18 additions & 0 deletions database/seeders/SqueezePageUserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\SqueezePageUser;

class SqueezePageUserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
SqueezePageUser::factory()->count(15)->create();
}
}
Binary file added public/uploads/1723194360.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions resources/docs/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5408,20 +5408,6 @@
}
}
},
"Organisation": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
}
}
},
"OrganisationInput": {
"required": [
"name"
Expand Down
9 changes: 8 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use App\Http\Controllers\UserNotificationController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\Admin\AdminDashboardController;
use App\Http\Controllers\SqueezePageUserController;
use App\Http\Controllers\Api\V1\NewsletterSubscriptionController;

/*
Expand Down Expand Up @@ -156,6 +157,9 @@
Route::post('/products', [SuperAdminProductController::class, 'store']);
Route::patch('/products/{productId}', [SuperAdminProductController::class, 'update']);
Route::delete('/products/{productId}', [SuperAdminProductController::class, 'destroy']);


Route::get('/squeeze-pages-users', [SqueezePageUserController::class, 'index']);
});

Route::middleware(['auth:api', 'admin'])->group(function () {
Expand Down Expand Up @@ -313,6 +317,9 @@
// quest
Route::get('/quests/{id}/messages', [QuestController::class, 'getQuestMessages']);

Route::post('/squeeze-user', [SqueezePageUserController::class, 'store']);


//Newsletter Subscription
Route::post('newsletter-subscription', [NewsletterSubscriptionController::class, 'store']);
});
});
Loading

0 comments on commit 05402a2

Please sign in to comment.