Skip to content

Commit

Permalink
Merge pull request #136 from Facts-and-Files/feat/transcritpion
Browse files Browse the repository at this point in the history
feat: new transcritpion endpoints
  • Loading branch information
trenc authored Jan 24, 2025
2 parents bdc51ee + 912f250 commit 7c9a3c5
Show file tree
Hide file tree
Showing 26 changed files with 958 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

L5_SWAGGER_GENERATE_ALWAYS=false
L5_FORMAT_TO_USE_FOR_DOCS=yaml
L5_SWAGGER_UI_PERSIST_AUTHORIZATION=true

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
Expand Down
73 changes: 73 additions & 0 deletions src/app/Http/Controllers/TranscriptionController.php
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);
}
}
}
13 changes: 13 additions & 0 deletions src/app/Http/Resources/TranscriptionResource.php
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);
}
}
7 changes: 6 additions & 1 deletion src/app/Models/Transcription.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ class Transcription extends Model

protected $primaryKey = 'TranscriptionId';

protected $casts = ['CurrentVersion' => 'boolean'];
protected $casts = [
'CurrentVersion' => 'boolean',
'NoText' => 'boolean',
];

protected $guarded = ['CurrentVersion'];
}
5 changes: 4 additions & 1 deletion src/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
//
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
}

/**
Expand Down
64 changes: 64 additions & 0 deletions src/app/Providers/TelescopeServiceProvider.php
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, [
//
]);
});
}
}
5 changes: 4 additions & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"require-dev": {
"laravel/pint": "^1.1",
"laravel/telescope": "^5.3",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.0",
"phpunit/phpunit": "^9.5.10"
Expand Down Expand Up @@ -48,7 +49,9 @@
},
"extra": {
"laravel": {
"dont-discover": []
"dont-discover": [
"laravel/telescope"
]
}
},
"config": {
Expand Down
103 changes: 85 additions & 18 deletions src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
// App\Providers\TelescopeServiceProvider::class,

],

Expand Down
Loading

0 comments on commit 7c9a3c5

Please sign in to comment.