Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions backend/app/Http/Controllers/Api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;

use Illuminate\Support\Facades\Storage;

class AuthController extends Controller
{
use PasswordValidationRules;
Expand Down Expand Up @@ -82,4 +84,40 @@ public function user(Request $request)
{
return response()->json($request->user());
}

public function updateProfile(Request $request)
{
$user = $request->user();

$request->validate([
'name' => 'required|string|max:255',
'name_bo' => 'nullable|string|max:255',
'nickname' => 'nullable|string|max:255',
'nickname_bo' => 'nullable|string|max:255',
'avatar' => 'nullable|image|mimes:jpeg,jpg,png,webp|max:5120',
]);

$updates = [
'name' => $request->name,
'name_bo' => $request->name_bo,
'nickname' => $request->nickname,
'nickname_bo' => $request->nickname_bo,
];

if ($request->hasFile('avatar')) {
$oldAvatar = $user->avatar;
if ($oldAvatar && ! str_starts_with($oldAvatar, 'http') && ! str_starts_with($oldAvatar, 'data:')) {
Storage::disk('public')->delete($oldAvatar);
}

$updates['avatar'] = $request->file('avatar')->store('avatars', 'public');
}

$user->update($updates);

return response()->json([
'message' => 'Profile updated successfully',
'user' => $user->fresh(),
]);
}
}
2 changes: 1 addition & 1 deletion backend/app/Http/Controllers/Api/BroadcastController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function index(Request $request)
$userId = $request->user()->id;

// Get active broadcasts from the last 24 hours
$broadcasts = Broadcast::with('user:id,name,role')
$broadcasts = Broadcast::with('user:id,name,name_bo,nickname,nickname_bo,role')
->where('created_at', '>=', Carbon::now()->subHours(24))
->orderBy('created_at', 'desc')
->get();
Expand Down
9 changes: 9 additions & 0 deletions backend/app/Http/Controllers/Api/LunchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ public function chefDashboardData(Request $request)
$employeeDetails[] = [
'id' => $emp->id,
'name' => $emp->name,
'name_bo' => $emp->name_bo,
'nickname' => $emp->nickname,
'nickname_bo' => $emp->nickname_bo,
'department' => $emp->department ?? 'General',
'status' => $status,
'votedAt' => $votedAt,
Expand All @@ -448,6 +451,9 @@ public function chefDashboardData(Request $request)
$employeeDetails[] = [
'id' => $emp->id,
'name' => $emp->name,
'name_bo' => $emp->name_bo,
'nickname' => $emp->nickname,
'nickname_bo' => $emp->nickname_bo,
'department' => $emp->department ?? 'General',
'status' => $status,
'votedAt' => '--:--',
Expand Down Expand Up @@ -542,6 +548,9 @@ public function participationReport(Request $request)
$usersData[] = [
'id' => $user->id,
'name' => $user->name,
'name_bo' => $user->name_bo,
'nickname' => $user->nickname,
'nickname_bo' => $user->nickname_bo,
'role' => $user->role,
'department' => $user->department ?? 'General',
'status' => $status,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/Http/Controllers/Api/MonthlyBillController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function show(MonthlyBill $monthlyBill): JsonResponse

$monthlyBill->load([
'uploader:id,name,email',
'userBills' => fn ($q) => $q->with('user:id,name,email,department')->orderByDesc('amount_due'),
'userBills' => fn ($q) => $q->with('user:id,name,name_bo,nickname,nickname_bo,email,department')->orderByDesc('amount_due'),
]);

$monthlyBill->payment_statistics = $this->billingService->paymentStatistics($monthlyBill);
Expand Down
20 changes: 20 additions & 0 deletions backend/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Sanctum\HasApiTokens;

use Illuminate\Support\Facades\Storage;

#[Fillable([
'name',
'name_bo',
'nickname',
'nickname_bo',
'email',
'password',
'role',
Expand All @@ -38,6 +43,21 @@ class User extends Authenticatable
Notifiable,
TwoFactorAuthenticatable;

protected $appends = ['avatar_url'];

public function getAvatarUrlAttribute(): ?string
{
if (! $this->avatar) {
return null;
}

if (str_starts_with($this->avatar, 'http://') || str_starts_with($this->avatar, 'https://') || str_starts_with($this->avatar, 'data:')) {
return $this->avatar;
}

return Storage::disk('public')->url($this->avatar);
}

/*
|--------------------------------------------------------------------------
| Relationships
Expand Down
4 changes: 2 additions & 2 deletions backend/app/Services/MonthlyBillingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function createMonthlyBill(

return $monthlyBill->load([
'uploader:id,name,email',
'userBills.user:id,name,email,department',
'userBills.user:id,name,name_bo,nickname,nickname_bo,email,department',
]);
});
}
Expand Down Expand Up @@ -202,6 +202,6 @@ public function updatePaymentStatus(UserMonthlyBill $userBill, string $paymentSt
'paid_at' => $paymentStatus === 'paid' ? now() : null,
]);

return $userBill->fresh(['user:id,name,email,department']);
return $userBill->fresh(['user:id,name,name_bo,nickname,nickname_bo,email,department']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('name_bo')->nullable()->after('name');
$table->string('nickname')->nullable()->after('name_bo');
$table->string('nickname_bo')->nullable()->after('nickname');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['name_bo', 'nickname', 'nickname_bo']);
});
}
};
1 change: 1 addition & 0 deletions backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

// Auth User
Route::get('/user', [AuthController::class, 'user']);
Route::post('/user/profile', [AuthController::class, 'updateProfile']);

Route::post('/logout', [AuthController::class, 'logout']);

Expand Down
Loading
Loading