-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from Facts-and-Files/feat/transcritpion
feat: new transcritpion endpoints
- Loading branch information
Showing
26 changed files
with
958 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\ResponseController; | ||
use App\Models\Transcription; | ||
use App\Http\Resources\TranscriptionResource; | ||
|
||
class TranscriptionController extends ResponseController | ||
{ | ||
public function index(Request $request): JsonResponse | ||
{ | ||
$queryColumns = [ | ||
'ItemId' => 'ItemId', | ||
'UserId' => 'UserId', | ||
'EuropeanaAnnotationId' => 'EuropeanaAnnotationId', | ||
'CurrentVersion' => 'CurrentVersion', | ||
]; | ||
|
||
$initialSortColumn = 'TranscriptionId'; | ||
|
||
$model = new Transcription(); | ||
|
||
if ($request['CurrentVersion']) { | ||
$request['CurrentVersion'] = $request->boolean('CurrentVersion'); | ||
} | ||
|
||
$data = $this->getDataByRequest($request, $model, $queryColumns, $initialSortColumn); | ||
|
||
if (!$data) { | ||
return $this->sendError('Invalid data', $request . ' not valid', 400); | ||
} | ||
|
||
$collection = TranscriptionResource::collection($data); | ||
|
||
return $this->sendResponseWithMeta($collection, 'Transcriptions fetched.'); | ||
} | ||
|
||
public function show(int $id): JsonResponse | ||
{ | ||
try { | ||
$data = Transcription::findOrFail($id); | ||
$resource = new TranscriptionResource($data); | ||
|
||
return $this->sendResponse($resource, 'Transcription fetched.'); | ||
} catch (\Exception $exception) { | ||
return $this->sendError('Not found', $exception->getMessage()); | ||
} | ||
} | ||
|
||
public function store(Request $request): JsonResponse | ||
{ | ||
try { | ||
$data = new Transcription(); | ||
|
||
$data->fill($request->all()); | ||
|
||
$data->CurrentVersion = true; | ||
$data->save(); | ||
|
||
Transcription::where('ItemId', $data->ItemId) | ||
->where('CurrentVersion', '=', true) | ||
->where('TranscriptionId', '!=', $data->TranscriptionId) | ||
->update(['CurrentVersion' => false]); | ||
|
||
return $this->sendResponse(new TranscriptionResource($data), 'Transcription inserted.'); | ||
} catch (\Exception $exception) { | ||
return $this->sendError('Invalid data', $exception->getMessage(), 400); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class TranscriptionResource extends JsonResource | ||
{ | ||
public function toArray($request): array | ||
{ | ||
return parent::toArray($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Support\Facades\Gate; | ||
use Laravel\Telescope\IncomingEntry; | ||
use Laravel\Telescope\Telescope; | ||
use Laravel\Telescope\TelescopeApplicationServiceProvider; | ||
|
||
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider | ||
{ | ||
/** | ||
* Register any application services. | ||
*/ | ||
public function register(): void | ||
{ | ||
// Telescope::night(); | ||
|
||
$this->hideSensitiveRequestDetails(); | ||
|
||
$isLocal = $this->app->environment('local'); | ||
|
||
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) { | ||
return $isLocal || | ||
$entry->isReportableException() || | ||
$entry->isFailedRequest() || | ||
$entry->isFailedJob() || | ||
$entry->isScheduledTask() || | ||
$entry->hasMonitoredTag(); | ||
}); | ||
} | ||
|
||
/** | ||
* Prevent sensitive request details from being logged by Telescope. | ||
*/ | ||
protected function hideSensitiveRequestDetails(): void | ||
{ | ||
if ($this->app->environment('local')) { | ||
return; | ||
} | ||
|
||
Telescope::hideRequestParameters(['_token']); | ||
|
||
Telescope::hideRequestHeaders([ | ||
'cookie', | ||
'x-csrf-token', | ||
'x-xsrf-token', | ||
]); | ||
} | ||
|
||
/** | ||
* Register the Telescope gate. | ||
* | ||
* This gate determines who can access Telescope in non-local environments. | ||
*/ | ||
protected function gate(): void | ||
{ | ||
Gate::define('viewTelescope', function ($user) { | ||
return in_array($user->email, [ | ||
// | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.