|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Http\Controllers\Api\V1; |
| 6 | + |
| 7 | +use App\Enums\Role; |
| 8 | +use App\Models\Organization; |
| 9 | +use App\Service\DashboardService; |
| 10 | +use App\Service\PermissionStore; |
| 11 | +use Illuminate\Auth\Access\AuthorizationException; |
| 12 | +use Illuminate\Http\JsonResponse; |
| 13 | + |
| 14 | +class ChartController extends Controller |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @throws AuthorizationException |
| 18 | + */ |
| 19 | + public function weeklyProjectOverview(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 20 | + { |
| 21 | + $this->checkPermission($organization, 'charts:view:own'); |
| 22 | + $user = $this->user(); |
| 23 | + |
| 24 | + $weeklyProjectOverview = $dashboardService->weeklyProjectOverview($user, $organization); |
| 25 | + |
| 26 | + return response()->json($weeklyProjectOverview); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @throws AuthorizationException |
| 31 | + */ |
| 32 | + public function latestTasks(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 33 | + { |
| 34 | + $this->checkPermission($organization, 'charts:view:own'); |
| 35 | + $user = $this->user(); |
| 36 | + |
| 37 | + $latestTasks = $dashboardService->latestTasks($user, $organization); |
| 38 | + |
| 39 | + return response()->json($latestTasks); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @throws AuthorizationException |
| 44 | + */ |
| 45 | + public function lastSevenDays(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 46 | + { |
| 47 | + $this->checkPermission($organization, 'charts:view:own'); |
| 48 | + $user = $this->user(); |
| 49 | + |
| 50 | + $lastSevenDays = $dashboardService->lastSevenDays($user, $organization); |
| 51 | + |
| 52 | + return response()->json($lastSevenDays); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @throws AuthorizationException |
| 57 | + */ |
| 58 | + public function latestTeamActivity(Organization $organization, DashboardService $dashboardService, PermissionStore $permissionStore): JsonResponse |
| 59 | + { |
| 60 | + $this->checkPermission($organization, 'charts:view:all'); |
| 61 | + |
| 62 | + $latestTeamActivity = $dashboardService->latestTeamActivity($organization); |
| 63 | + |
| 64 | + return response()->json($latestTeamActivity); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @throws AuthorizationException |
| 69 | + */ |
| 70 | + public function dailyTrackedHours(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 71 | + { |
| 72 | + $this->checkPermission($organization, 'charts:view:own'); |
| 73 | + $user = $this->user(); |
| 74 | + |
| 75 | + $dailyTrackedHours = $dashboardService->getDailyTrackedHours($user, $organization, 60); |
| 76 | + |
| 77 | + return response()->json($dailyTrackedHours); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @throws AuthorizationException |
| 82 | + */ |
| 83 | + public function totalWeeklyTime(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 84 | + { |
| 85 | + $this->checkPermission($organization, 'charts:view:own'); |
| 86 | + $user = $this->user(); |
| 87 | + |
| 88 | + $totalWeeklyTime = $dashboardService->totalWeeklyTime($user, $organization); |
| 89 | + |
| 90 | + return response()->json($totalWeeklyTime); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @throws AuthorizationException |
| 95 | + */ |
| 96 | + public function totalWeeklyBillableTime(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 97 | + { |
| 98 | + $this->checkPermission($organization, 'charts:view:own'); |
| 99 | + $user = $this->user(); |
| 100 | + |
| 101 | + $totalWeeklyBillableTime = $dashboardService->totalWeeklyBillableTime($user, $organization); |
| 102 | + |
| 103 | + return response()->json($totalWeeklyBillableTime); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @throws AuthorizationException |
| 108 | + */ |
| 109 | + public function totalWeeklyBillableAmount(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 110 | + { |
| 111 | + $this->checkPermission($organization, 'charts:view:own'); |
| 112 | + $user = $this->user(); |
| 113 | + |
| 114 | + $showBillableRate = $this->member($organization)->role !== Role::Employee->value || $organization->employees_can_see_billable_rates; |
| 115 | + if (! $showBillableRate) { |
| 116 | + throw new AuthorizationException('You do not have permission to view billable rates.'); |
| 117 | + } |
| 118 | + |
| 119 | + $totalWeeklyBillableAmount = $dashboardService->totalWeeklyBillableAmount($user, $organization); |
| 120 | + |
| 121 | + return response()->json($totalWeeklyBillableAmount); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * @throws AuthorizationException |
| 126 | + */ |
| 127 | + public function weeklyHistory(Organization $organization, DashboardService $dashboardService): JsonResponse |
| 128 | + { |
| 129 | + $this->checkPermission($organization, 'charts:view:own'); |
| 130 | + $user = $this->user(); |
| 131 | + |
| 132 | + $weeklyHistory = $dashboardService->getWeeklyHistory($user, $organization); |
| 133 | + |
| 134 | + return response()->json($weeklyHistory); |
| 135 | + } |
| 136 | +} |
0 commit comments