-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from RaphAlemoh/feat/list-all-squeeze-pages
feat: list all squeeze pages
- Loading branch information
Showing
7 changed files
with
243 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
database/migrations/2024_08_07_063753_add_columns_to_squeeze_pages_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |