Merge branch 'feature/import' into feature/add_frontend_dashboard

# Conflicts:
#	app/Http/Controllers/Api/V1/TimeEntryController.php
#	app/Providers/JetstreamServiceProvider.php
This commit is contained in:
Constantin Graf
2024-03-12 17:55:49 +01:00
96 changed files with 3444 additions and 109 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Requests\V1\Import\ImportRequest;
use App\Models\Organization;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\ImportService;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\JsonResponse;
class ImportController extends Controller
{
/**
* Import data into the organization
*
* @throws AuthorizationException
*/
public function import(Organization $organization, ImportRequest $request, ImportService $importService): JsonResponse
{
$this->checkPermission($organization, 'import');
try {
$report = $importService->import(
$organization,
$request->input('type'),
$request->input('data')
);
return new JsonResponse([
/** @var array{
* clients: array{
* created: int,
* },
* projects: array{
* created: int,
* },
* tasks: array{
* created: int,
* },
* time-entries: array{
* created: int,
* },
* tags: array{
* created: int,
* },
* users: array{
* created: int,
* }
* } $report Import report */
'report' => $report->toArray(),
], 200);
} catch (ImportException $exception) {
report($exception);
return new JsonResponse([
'message' => $exception->getMessage(),
], 400);
}
}
}

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Exceptions\TimeEntryStillRunning;
use App\Exceptions\Api\TimeEntryStillRunningApiException;
use App\Http\Requests\V1\TimeEntry\TimeEntryIndexRequest;
use App\Http\Requests\V1\TimeEntry\TimeEntryStoreRequest;
use App\Http\Requests\V1\TimeEntry\TimeEntryUpdateRequest;
@@ -104,7 +104,7 @@ class TimeEntryController extends Controller
/**
* Create time entry
*
* @throws AuthorizationException|TimeEntryStillRunning
* @throws AuthorizationException|TimeEntryStillRunningApiException
*
* @operationId createTimeEntry
*/
@@ -118,8 +118,7 @@ class TimeEntryController extends Controller
if ($request->get('end') === null && TimeEntry::query()->where('user_id', $request->get('user_id'))->where('end', null)->exists()) {
// TODO: API documentation
// TODO: Create concept for api exceptions
throw new TimeEntryStillRunning('User already has an active time entry');
throw new TimeEntryStillRunningApiException();
}
$timeEntry = new TimeEntry();

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Exceptions\Api\UserNotPlaceholderApiException;
use App\Http\Requests\V1\User\UserIndexRequest;
use App\Http\Resources\V1\User\UserCollection;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Laravel\Jetstream\Contracts\InvitesTeamMembers;
class UserController extends Controller
{
/**
* List all users in an organization
*
* @throws AuthorizationException
*/
public function index(Organization $organization, UserIndexRequest $request): UserCollection
{
$this->checkPermission($organization, 'users:view');
$users = $organization->users()
->paginate();
return UserCollection::make($users);
}
/**
* Invite a placeholder user to become a real user in the organization
*
* @throws AuthorizationException|UserNotPlaceholderApiException
*/
public function invitePlaceholder(Organization $organization, User $user, Request $request): JsonResponse
{
$this->checkPermission($organization, 'users:invite-placeholder');
if (! $user->is_placeholder) {
throw new UserNotPlaceholderApiException();
}
app(InvitesTeamMembers::class)->invite(
$request->user(),
$organization,
$user->email,
'employee'
);
return response()->json($user);
}
}