Skip to content

Commit

Permalink
Merge pull request #103 from RiwRiwara/add-create-event
Browse files Browse the repository at this point in the history
Update create event
  • Loading branch information
RiwRiwara authored Mar 7, 2024
2 parents b7463b6 + 443f54e commit 8556c11
Show file tree
Hide file tree
Showing 44 changed files with 788 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Laravel\Facades\Image;
use App\Models\User;
use App\Services\AzureBlobService;


Expand Down Expand Up @@ -47,10 +48,11 @@ public function uploadUserProfile(Request $request)
$blobService->deleteBlob($containerName, auth()->user()->profile_img);

// update User profile image
$user = auth()->user();
$user = User::where('user_id', auth()->user()->user_id)->first();
$user->profile_img = $blobName;
$user->save();


return response()->json([
'message' => 'Profile image uploaded',
'user' => $user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
$request->session()->regenerate();
toastr()->addSuccess(__('success.success_login'));
return redirect()->intended(RouteServiceProvider::HOME);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RegisteredUserController extends Controller
*/
public function create(): View
{
$FORM_DATA_ITEMS = [
$page_data = [
'provinces' => Provinces::provinces(),
'districts' => Cities::cities(),
'cities' => Districts::districts(),
Expand All @@ -40,7 +40,7 @@ public function create(): View
];


return view('guest.register', compact('FORM_DATA_ITEMS', 'breadcrumbItems'));
return view('guest.register', compact('page_data', 'breadcrumbItems'));
}


Expand Down
22 changes: 22 additions & 0 deletions app/Http/Controllers/Event/CreateEvent/CreateEventController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\Event\CreateEvent;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CreateEventController extends Controller
{
public function __invoke(Request $request)
{
$page_data = [
'breadcrumbItems' => [
['label' => 'Events', 'url' => route('create-event')],
['label' => 'Create Eevnt'],
],
'event_types' => \App\Models\EventType::all(),
'badge_types' => \App\Models\Badge::all(),
];
return view('logged_in.create_event', compact('page_data'),);
}
}
21 changes: 21 additions & 0 deletions app/Http/Controllers/Event/EventList/EventListController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers\Event\EventList;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class EventListController extends Controller
{
public function __invoke(Request $request)
{
$page_data = [
'breadcrumbItems' => [
['label' => 'Events', 'url' => route('create-event')],
['label' => 'Create Event'],
]
];

return view('logged_in.event-list', compact('page_data'));
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function myProfileDetail(Request $request): View
$user->gender = Gender::getGenderById($user->gender);
$user->date_of_birth = (new Time($user->date_of_birth, $isThai))->getDateBirthObject();

$FORM_DATA_ITEMS = [
$page_data = [
'isThai' => $isThai,
'provinces' => Provinces::provinces(),
'districts' => Cities::cities(),
Expand All @@ -49,7 +49,7 @@ public function myProfileDetail(Request $request): View

];

return view('profile.profilePage', compact('user', 'FORM_DATA_ITEMS'));
return view('profile.profilePage', compact('user', 'page_data'));
}


Expand Down
66 changes: 34 additions & 32 deletions app/Http/Controllers/User/UploadUserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,47 @@
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Laravel\Facades\Image;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class UploadUserProfileController extends Controller
{
public function __invoke(Request $request): RedirectResponse
{
$response = redirect()->back();

$image_tmp = json_decode($request->input('image'), true);
if (!$image_tmp) {
toastr()->addWarning('please upload an image first');
return redirect()->back();
}

try {
$path = Storage::path($image_tmp['path']);
$image = Image::read($path)->toWebp();

$blobService = new AzureBlobService();
$containerName = 'testprofileimgs';
$blobName = auth()->user()->user_id . '_' . now() . '.webp';

$decodeImage = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image->toDataUri()));

$blobService->uploadBlob($containerName, $blobName, $decodeImage, $image->mediaType());

// delete temp image
Storage::deleteDirectory('tmp');

// delete old image
// $blobService->deleteBlob($containerName, auth()->user()->profile_img);

// update User profile image
$user = User::where('user_id', auth()->user()->user_id)->first();
$user->profile_img = $blobName;
$user->save();

toastr()->addSuccess('Image uploaded successfully');
} catch (\Exception $e) {
toastr()->addError('Error uploading image' . $e->getMessage());
return redirect()->back();
toastr()->addWarning(__('error.upload_profile_img'));
} else {
try {
$path = Storage::path($image_tmp['path']);
$image = Image::read($path)->toWebp();

$blobService = new AzureBlobService();
$containerName = 'testprofileimgs';
$blobName = auth()->user()->user_id . '_' . now() . '.webp';

$decodeImage = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image->toDataUri()));

$blobService->uploadBlob($containerName, $blobName, $decodeImage, $image->mediaType());

// delete temp image
Storage::deleteDirectory('tmp');

// delete old image
$blobService->deleteBlob($containerName, auth()->user()->profile_img);

// update User profile image
$user = User::where('user_id', auth()->user()->user_id)->first();
$user->profile_img = $blobName;
$user->save();
toastr()->addSuccess('Image uploaded successfully');
} catch (\Exception $e) {
toastr()->addError('Error uploading image' . $e->getMessage());

}
}
return redirect()->back();
return $response;

}
}
9 changes: 9 additions & 0 deletions app/Models/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ class Badge extends Model
{
public $table = 'badges';
use HasFactory;

protected $fillable = [
'name_th',
'name_en',
'description',
'icon',
];


}
19 changes: 19 additions & 0 deletions app/Models/EventType.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;

class EventType extends Model
{
public $table = 'event_types';
use HasFactory;

protected $fillable = [
'name_th',
'name_en',
'description',
'icon',
];
}
2 changes: 2 additions & 0 deletions app/Models/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ class Event extends Model
public $table = 'events';

use HasFactory;


}
7 changes: 6 additions & 1 deletion app/Services/AzureBlobService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ public function uploadBlob(string $containerName, string $blobName, string $cont
}


public function deleteBlob(string $containerName, string $blobName): bool
public function deleteBlob(string $containerName, ?string $blobName): bool
{
if ($blobName === null) {
return false;
}

try {
$this->blobClient->deleteBlob($containerName, $blobName);
return true;
} catch (\Exception $e) {
return false;
}
}



public function getBlobUrl(string $containerName, string $blobName): string
Expand Down
2 changes: 1 addition & 1 deletion app/Utils/Filepond/LoadImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __invoke(string $img_url)

if ($response->status() !== 200) {
$img = file_get_contents(public_path('images/default_thumnail.png'));
return response($img, 200, ['Content-Type' => 'image/png']);
return response($img, 200, ['Content-Type' => 'image/webp']);
}

$response = response($img, 200, ['Content-Type' => 'image/webp']);
Expand Down
2 changes: 2 additions & 0 deletions database/migrations/2014_10_12_000000_create_roles_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function up(): void
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description')->nullable();
$table->string('icon')->nullable();
$table->timestamps();
});
}
Expand Down
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('event_types', function (Blueprint $table) {
$table->id();
$table->string('name_th');
$table->string('name_en');
$table->string('description')->nullable();
$table->string('icon')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('event_types');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
public function up(): void
{
Schema::create('badges', function (Blueprint $table) {
$table->bigIncrements('badge_id');
$table->string('title')->nullable();
$table->id();
$table->string('name_th');
$table->string('name_en');
$table->string('description')->nullable();
$table->string('img_src')->nullable();
$table->string('icon');
$table->timestamps();
});
}
Expand Down
46 changes: 34 additions & 12 deletions database/migrations/2024_01_18_163524_create_events_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,43 @@
public function up(): void
{
Schema::create('events', function (Blueprint $table) {
$table->bigIncrements('event_id');
$table->string('event_name', 50);
$table->string('event_category', 50);
$table->string('event_event', 50)->unique();
// information
$table->id();
$table->string('event_id')->unique();
$table->string('name')->nullable();
$table->string('description')->nullable();
$table->string('categories')->nullable(); // 1, 2

// Contact
$table->string('contact_email', 50)->nullable();
$table->string('contact_phone', 15)->nullable();

// Date
$table->dateTime('start_date')->nullable();
$table->dateTime('end_date')->nullable();
$table->text('event_description');
$table->string('event_location');
// $table->string('event_time', 50);
$table->integer('event_staff_number');
$table->integer('event_part_number');
$table->enum('event_phase', ['Upcoming', 'In progress', 'Reviewing', 'Compelete'])->nullable();
$table->timestamps();
$table->time('start_time')->nullable();
$table->time('end_time')->nullable();

// Location
$table->string('address')->nullable();
$table->string('city')->nullable();
$table->string('district')->nullable();
$table->string('province')->nullable();
$table->string('zipcode')->nullable();

$table->integer('organizer_id'); //FK user_id from user
// Status
$table->enum('event_phase', ['Upcoming', 'In progress', 'Reviewing', 'Complete'])->nullable();
$table->enum('event_status', ['Draft', 'Published', 'Cancelled'])->nullable();
$table->boolean('is_specific_date')->nullable()->default(false);
$table->boolean('is_online')->nullable()->default(false);

// Organizer
$table->string('organizer_id');

// Image
$table->string('thumbnail')->nullable();

$table->timestamps();
});
}

Expand Down
Loading

0 comments on commit 8556c11

Please sign in to comment.