Skip to content

Commit

Permalink
Merge pull request #392 from RaphAlemoh/feat/list-all-squeeze-pages
Browse files Browse the repository at this point in the history
feat: list all squeeze pages
  • Loading branch information
Dev-Tonia authored Aug 6, 2024
2 parents 4c4bb8a + 021a70c commit ce0fbe6
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 10 deletions.
79 changes: 79 additions & 0 deletions app/Http/Controllers/Api/V1/SqueezePageCoontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Models\SqueezePage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class SqueezePageCoontroller extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
try {
$plans = SqueezePage::select(['id', 'title', 'slug', 'created_at', 'status', 'activate'])->get();
return response()->json([
'status' => Response::HTTP_OK,
'message' => 'Squeeze Pages retrieved successfully',
'data' => $plans,
]);
} catch (\Exception $e) {
return response()->json([
'message' => 'Internal server error',
'status' => Response::HTTP_INTERNAL_SERVER_ERROR
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
14 changes: 14 additions & 0 deletions app/Models/SqueezePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@
class SqueezePage extends Model
{
use HasFactory, HasUuids;


protected $fillable = [
'title',
'slug',
'status',
'activate',
'headline',
'sub_headline',
'hero_image',
'content',
];


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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::table('squeeze_pages', function (Blueprint $table) {
$table->string('title');
$table->string('slug')->unique();
$table->enum('status', ['offline', 'online'])->default('online');
$table->boolean('activate');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('squeeze_pages', function (Blueprint $table) {
$table->dropColumn('title');
$table->dropColumn('slug');
$table->dropColumn('status');
$table->dropColumn('activate');
});
}
};
3 changes: 2 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function run(): void
FaqSeeder::class,
UserNotificationSeeder::class,
NotificationSettingSeeder::class,
OrderSeeder::class
OrderSeeder::class,
SqueezePageSeeder::class
]);

}
Expand Down
58 changes: 57 additions & 1 deletion database/seeders/SqueezePageSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

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

Expand All @@ -12,6 +13,61 @@ class SqueezePageSeeder extends Seeder
*/
public function run(): void
{
//
$squeezePages = [
[
'title' => 'Digital Marketing',
'slug' => 'digital-marketing',
'status' => 'online',
'activate' => true,
'headline' => 'Master Digital Marketing',
'sub_headline' => 'Unlock the Secrets of Online Success',
'hero_image' => 'digital_marketing.jpg',
'content' => 'Learn the best strategies to excel in digital marketing...',
],
[
'title' => 'Conversion Secrets',
'slug' => 'conversion-secrets',
'status' => 'online',
'activate' => true,
'headline' => 'Increase Your Conversions',
'sub_headline' => 'Discover Proven Techniques',
'hero_image' => 'conversion_secrets.jpg',
'content' => 'Find out how to turn visitors into customers...',
],
[
'title' => 'Email Mastery',
'slug' => 'email-mastery',
'status' => 'offline',
'activate' => false,
'headline' => 'Master Email Marketing',
'sub_headline' => 'Boost Your Campaigns',
'hero_image' => 'email_mastery.jpg',
'content' => 'Effective email marketing strategies to engage your audience...',
],
[
'title' => 'Social Growth',
'slug' => 'social-growth',
'status' => 'offline',
'activate' => false,
'headline' => 'Grow Your Social Media',
'sub_headline' => 'Strategies for Success',
'hero_image' => 'social_growth.jpg',
'content' => 'Learn how to grow your social media presence...',
],
[
'title' => 'Content Blueprint',
'slug' => 'content-blueprint',
'status' => 'online',
'activate' => true,
'headline' => 'Content Marketing Blueprint',
'sub_headline' => 'Your Guide to Success',
'hero_image' => 'content_blueprint.jpg',
'content' => 'Step-by-step guide to successful content marketing...',
],
];

foreach ($squeezePages as $squeezePage) {
SqueezePage::create($squeezePage);
}
}
}
10 changes: 2 additions & 8 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
use App\Http\Controllers\Api\V1\JobSearchController;
use App\Http\Controllers\Api\V1\WaitListController;
use App\Http\Controllers\Api\V1\CookiePreferencesController;


use App\Http\Controllers\Api\V1\SqueezePageCoontroller;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -129,7 +128,6 @@
Route::get('/cookies/preferences', [CookiePreferencesController::class, 'getPreferences']);



// Help Articles
Route::post('/help-center/topics', [HelpArticleController::class, 'store']);
Route::patch('/help-center/topics/{articleId}', [HelpArticleController::class, 'update']);
Expand Down Expand Up @@ -220,13 +218,9 @@
Route::patch('/blogs/edit/{id}', [BlogController::class, 'update'])->name('admin.blogs.update');
Route::delete('/blogs/{id}', [BlogController::class, 'destroy']);
Route::get('/waitlists', [WaitListController::class, 'index']);
Route::apiResource('squeeze-pages', SqueezePageCoontroller::class);
});






Route::post('/waitlists', [WaitListController::class, 'store']);
Route::apiResource('faqs', FaqController::class);

Expand Down
55 changes: 55 additions & 0 deletions tests/Feature/SqueezePagesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Tymon\JWTAuth\Facades\JWTAuth;

class SqueezePagesTest extends TestCase
{
use RefreshDatabase;

protected $adminUser;
protected $adminToken;

public function setUp(): void
{
parent::setUp();

$this->adminUser = User::factory()->create(['role' => 'admin']);
$this->adminToken = JWTAuth::fromUser($this->adminUser);
}


public function test_it_retrieves_squeeze_pages_successfully()
{
$response = $this->withHeaders(['Authorization' => "Bearer $this->adminToken"])
->getJson('/api/v1/squeeze-pages');

$response->assertStatus(200)
->assertJsonStructure([
'status',
'message',
'data' => [
'*' => [
'id',
'title',
'slug',
'created_at',
'status',
'activate',
]
]
]);
}

public function test_if_it_fails_for_unathorised_access_to_squeeze_pages()
{

$response = $this->getJson('/api/v1/squeeze-pages');
$response->assertStatus(401);
}
}

0 comments on commit ce0fbe6

Please sign in to comment.