Skip to content

Commit

Permalink
Merge pull request #398 from tulbadex/fix/fix-auth-docs
Browse files Browse the repository at this point in the history
Fix: fix auth docs
  • Loading branch information
timiajayi authored Aug 7, 2024
2 parents 18ab233 + 40898ca commit 201b9a8
Show file tree
Hide file tree
Showing 19 changed files with 1,510 additions and 62 deletions.
27 changes: 25 additions & 2 deletions app/Http/Controllers/Api/V1/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Illuminate\Support\Facades\Hash;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Models\User;
use App\Models\Organisation;
use App\Models\OrganisationUser;
use Illuminate\Support\Facades\Log;
use App\Models\Validators\AuthValidator;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -47,6 +49,7 @@ public function store(Request $request)
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|string|email:rfc|max:255|unique:users',
'admin_secret' => 'nullable|string|max:255',
'password' => ['required', 'string', Password::min(8)
->letters()
->mixedCase()
Expand All @@ -63,26 +66,45 @@ public function store(Request $request)
try {
DB::beginTransaction();

$role = $request->admin_secret ? 'admin' : 'user';

// Creating the user
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
'role' => 'user'
'role' => $role
]);

$profile = $user->profile()->create([
'first_name' => $request->first_name,
'last_name' => $request->last_name
]);

$organization = $user->owned_organisations()->create([
'name' => $request->first_name."'s Organisation",
]);

$organization_user = OrganisationUser::create([
'user_id' => $user->id,
'org_id' => $organization->org_id
]);

$roles = $user->roles()->create([
'name' => $role,
'org_id' => $organization->org_id
]);
DB::table('users_roles')->insert([
'user_id' => $user->id,
'role_id' => $roles->id
]);

// Generate JWT token
$token = JWTAuth::fromUser($user);

DB::commit();

return response()->json([

'status' => 201,
"message" => "User Created Successfully",
'access_token' => $token,
Expand All @@ -103,6 +125,7 @@ public function store(Request $request)

return $this->apiResponse('Registration unsuccessful', Response::HTTP_BAD_REQUEST);
}

}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function users()
return $this->belongsToMany(User::class, 'organisation_user', 'org_id', 'user_id')->using(OrganisationUser::class);
}

// Define the inverse relationship
public function owner()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}

public function getPublicColumns()
{
$publicColumns = ['org_id', "user_id", "name", "slug", "description", "email", "industry", "type", "country", "address", "state"];
Expand Down
6 changes: 4 additions & 2 deletions config/swagger-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
/*
* The path where the swagger file is served.
*/
'path' => 'documentation',
// 'path' => 'documentation',
'path' => 'docs',

/*
* The versions of the swagger file. The key is the version name and the value is the path to the file.
*/
'versions' => [
'v1' => resource_path('docs/documentation.json'),
// 'v1' => resource_path('docs/documentation.json'),
'v1' => resource_path('docs/docs.json'),
],

/*
Expand Down
24 changes: 23 additions & 1 deletion database/factories/OrderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Product;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\DB;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Order>
Expand All @@ -18,12 +19,33 @@ class OrderFactory extends Factory
*/
public function definition(): array
{
$orderNumber = $this->generateUniqueOrderNumber();

return [
'user_id' => User::factory(),
'product_id' => Product::factory(),
'status' => $this->faker->boolean,
'quantity' => $this->faker->randomDigit(),
'amount' => $this->faker->randomDigit(),
'total_amount' => $this->faker->randomDigit(),
'order_number' => $orderNumber,
];
}

protected function generateUniqueOrderNumber()
{
$unique = false;
$orderNumber = null;

while (!$unique) {
// Generate a random order number (e.g., 8 digits)
$orderNumber = $this->faker->unique()->regexify('[A-Za-z0-9]{8}');

// Check if the generated order number is unique in the database
if (!DB::table('orders')->where('order_number', $orderNumber)->exists()) {
$unique = true;
}
}

return $orderNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function up(): void
$table->uuid('org_id')->primary();
$table->foreignUuid('user_id')->constrained()->onDelete('cascade')->onUpdate('cascade');
$table->string('name');
$table->string('email')->unique();
$table->string('email')->nullable()->unique();
$table->text('description')->nullable();
$table->string('industry');
$table->string('industry')->nullable();
$table->string('type')->nullable();
$table->string('country');
$table->string('address');
$table->string('state');
$table->string('country')->nullable();
$table->string('address')->nullable();
$table->string('state')->nullable();

$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function up(): void
public function down(): void
{
Schema::table('blogs', function (Blueprint $table) {
$table->string('content')->change();
$table->text('content')->change();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
public function up(): void
{
Schema::table('blogs', function (Blueprint $table) {
$table->dropColumn('tags');
$table->dropColumn('imageUrl');
$table->dropColumn(['tags', 'imageUrl']);
});
}

Expand All @@ -23,8 +22,8 @@ public function up(): void
public function down(): void
{
Schema::table('blogs', function (Blueprint $table) {
$table->string('tags');
$table->string('imageUrl');
$table->string('tags')->default('default_value');
$table->string('imageUrl')->default('default_value');
});
}
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ public function up(): void
Schema::table('blogs', function (Blueprint $table) {
$table->string('category')->nullable();
$table->text('image_url')->nullable();
$table->dropForeign(['blog_category_id']);
$table->dropColumn('blog_category_id');
$table->foreignUuid('author_id')->nullable()->constrained('users', 'id')->cascadeOnDelete()->cascadeOnUpdate();
});
Schema::dropIfExists('blog_categories');
Schema::dropIfExists('blog_images');
}

Expand All @@ -29,7 +26,6 @@ public function down(): void
{
Schema::table('blogs', function (Blueprint $table) {
$table->dropColumn('category');
$table->uuid('blog_category_id');
});

Schema::create('blog_images', function (Blueprint $table) {
Expand All @@ -39,12 +35,5 @@ public function down(): void
$table->timestamps();
});


Schema::create('blog_categories', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->string('description')->nullable();
$table->timestamps();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function up(): void
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
//
$table->dropSoftDeletes();
});
}
};
2 changes: 2 additions & 0 deletions database/migrations/2024_08_06_182021_create_orders_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function up(): void
$table->string('payment_method')->nullable();
$table->string('shipping_address')->nullable();
$table->string('billing_address')->nullable();
$table->unsignedInteger('quantity')->nullable();
$table->text('notes')->nullable();
$table->foreignUuid('product_id')->nullable()->references('product_id')->on('products')->onDelete('cascade');
$table->timestamps();
$table->softDeletes();

Expand Down
3 changes: 2 additions & 1 deletion database/seeders/CategoriesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class CategoriesTableSeeder extends Seeder
public function run()
{
// Truncate the table to remove existing records
// Category::truncate();
Category::truncate();

// Define categories
$categories = [
[
'name' => 'Electronics',
Expand Down
5 changes: 1 addition & 4 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public function run(): void
OrderSeeder::class,
SqueezePageSeeder::class,
TimezoneSeeder::class,
]);

$this->call([
QuestsSeeder::class,
QuestSeeder::class,
QuestMessageSeeder::class,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class QuestsSeeder extends Seeder
class QuestSeeder extends Seeder
{
public function run()
{
Expand Down
Binary file added public/uploads/1723052951.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/1723053078.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/1723053336.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 201b9a8

Please sign in to comment.