mandant-crm/backend/app/Modules/History/Controllers/HistoryController.php
Tim Stollberg f0bb80707a feat(backend): commit uncommitted CustomField, dynamic HistoryType, and Import modules
Mirrors the frontend catch-up in 570f17e: a substantial amount of
finished-but-never-committed backend work had accumulated locally.

- New CustomField module: admin-managed field definitions per client,
  reorderable, typed values stored per client (backing the frontend's
  ClientCustomFieldCard + settings/fields page)
- History entries switch from a hardcoded type enum to a dynamic,
  admin-managed HistoryType module (reorderable, backing
  settings/history-types)
- New Import module: CSV client import (backing settings/import)
- Clients table gains soft deletes (deleted_at)
- Supporting factories, seeders, policies, and feature tests for all
  of the above

All 63 backend tests pass locally before this commit.
2026-07-18 16:34:18 +07:00

55 lines
2.1 KiB
PHP

<?php
namespace App\Modules\History\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Client\Models\Client;
use App\Modules\History\Actions\CreateHistoryEntryAction;
use App\Modules\History\Actions\UpdateHistoryEntryAction;
use App\Modules\History\DTOs\HistoryEntryData;
use App\Modules\History\Models\HistoryEntry;
use App\Modules\History\Requests\CreateHistoryEntryRequest;
use App\Modules\History\Requests\UpdateHistoryEntryRequest;
use App\Modules\History\Resources\HistoryEntryResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
class HistoryController extends Controller
{
public function index(Client $client): AnonymousResourceCollection
{
$this->authorize('viewAny', HistoryEntry::class);
$entries = $client->historyEntries()
->with(['author', 'updatedBy', 'entryType'])
->orderByDesc('created_at')
->get();
return HistoryEntryResource::collection($entries);
}
public function store(
CreateHistoryEntryRequest $request,
Client $client,
CreateHistoryEntryAction $action
): JsonResponse {
$this->authorize('create', HistoryEntry::class);
$entry = $action->handle($client, HistoryEntryData::fromCreateRequest($request), $request->user());
return HistoryEntryResource::make($entry->load(['author', 'entryType']))->response()->setStatusCode(201);
}
public function update(
UpdateHistoryEntryRequest $request,
HistoryEntry $historyEntry,
UpdateHistoryEntryAction $action
): HistoryEntryResource {
$this->authorize('update', $historyEntry);
$updated = $action->handle($historyEntry, HistoryEntryData::fromUpdateRequest($request), $request->user());
return HistoryEntryResource::make($updated->load(['author', 'updatedBy', 'entryType']));
}
public function destroy(HistoryEntry $historyEntry): JsonResponse
{
$this->authorize('delete', $historyEntry);
$historyEntry->delete();
return response()->json(null, 204);
}
}