-
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 branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
…php_laravel_web into feat/fetch-a-role-in-an-organisation-endpoint
- Loading branch information
Showing
20 changed files
with
401 additions
and
127 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 |
---|---|---|
|
@@ -20,4 +20,4 @@ yarn-error.log | |
docker-compose.yml | ||
/public/uploads | ||
ResponseHTTP_OK, | ||
can | ||
can |
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,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); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -21,6 +21,4 @@ class SqueezePage extends Model | |
'hero_image', | ||
'content', | ||
]; | ||
|
||
|
||
} |
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,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'; | ||
|
||
} |
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,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), | ||
]; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
database/migrations/2024_08_08_155430_create_squeeze_pages_user_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,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'); | ||
} | ||
}; |
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,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(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.