-
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 #122 from Facts-and-Files/feat/transcriptionProvider
feat: transcription provider for htrdata
- Loading branch information
Showing
14 changed files
with
552 additions
and
3 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/app/Http/Controllers/TranscriptionProviderController.php
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,94 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\ResponseController; | ||
use App\Models\TranscriptionProvider; | ||
use App\Http\Resources\TranscriptionProviderResource; | ||
|
||
class TranscriptionProviderController extends ResponseController | ||
{ | ||
public function index(Request $request): JsonResponse | ||
{ | ||
$queryColumns = []; | ||
|
||
$initialSortColumn = 'TranscriptionProviderId'; | ||
|
||
$model = new TranscriptionProvider(); | ||
|
||
$data = $this->getDataByRequest($request, $model, $queryColumns, $initialSortColumn); | ||
|
||
if (!$data) { | ||
return $this->sendError('Invalid data', $request . ' not valid', 400); | ||
} | ||
|
||
$collection = TranscriptionProviderResource::collection($data); | ||
|
||
return $this->sendResponseWithMeta($collection, 'TranscriptionProviders fetched.'); | ||
} | ||
|
||
public function show(int $id): JsonResponse | ||
{ | ||
try { | ||
$data = TranscriptionProvider::findOrFail($id); | ||
$resource = new TranscriptionProviderResource($data); | ||
|
||
return $this->sendResponse($resource, 'TranscriptionProvider fetched.'); | ||
} catch (\Exception $exception) { | ||
return $this->sendError('Not found', $exception->getMessage()); | ||
} | ||
} | ||
|
||
public function store(Request $request): JsonResponse | ||
{ | ||
try { | ||
$data = new TranscriptionProvider(); | ||
$data->fill($request->all()); | ||
$data->save(); | ||
|
||
return $this->sendResponse(new TranscriptionProviderResource($data), 'Transcription provider inserted.'); | ||
} catch (\Exception $exception) { | ||
return $this->sendError('Invalid data', $exception->getMessage(), 400); | ||
} | ||
} | ||
|
||
|
||
public function update(Request $request, int $id): JsonResponse | ||
{ | ||
try { | ||
$data = TranscriptionProvider::findOrfail($id); | ||
} catch(\Exception $exception) { | ||
return $this->sendError('Not found', $exception->getMessage(), 404); | ||
} | ||
|
||
try { | ||
$data->fill($request->all()); | ||
$data->save(); | ||
|
||
return $this->sendResponse(new TranscriptionProviderResource($data), 'Transcription provider updated.'); | ||
} catch(\Exception $exception) { | ||
return $this->sendError('Invalid data', $exception->getMessage(), 400); | ||
} | ||
} | ||
|
||
public function destroy(int $id): JsonResponse | ||
{ | ||
try { | ||
$data = TranscriptionProvider::findOrfail($id); | ||
} catch(\Exception $exception) { | ||
return $this->sendError('Not found', $exception->getMessage(), 404); | ||
} | ||
|
||
try { | ||
$resource = $data->toArray(); | ||
$resource = new TranscriptionProviderResource($resource); | ||
$data->delete(); | ||
|
||
return $this->sendResponse($resource, 'Transcription provider deleted.'); | ||
} 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 TranscriptionProviderResource 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class TranscriptionProvider extends Model | ||
{ | ||
const CREATED_AT = null; | ||
const UPDATED_AT = null; | ||
|
||
protected $table = 'TranscriptionProvider'; | ||
|
||
protected $primaryKey = 'TranscriptionProviderId'; | ||
|
||
protected $guarded = ['TranscriptionProviderId']; | ||
|
||
public function htrData(): HasMany | ||
{ | ||
return $this->hasMany(HtrData::class, 'TranscriptionProviderId'); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/database/migrations/2024_09_19_115300_create_transcription_provider_table.php
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,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('TranscriptionProvider', function (Blueprint $table) { | ||
$table->charset = 'utf8mb4'; | ||
$table->collation = 'utf8mb4_unicode_ci'; | ||
|
||
$table->smallIncrements('TranscriptionProviderId'); | ||
$table->string('Name'); | ||
}); | ||
|
||
DB::table('TranscriptionProvider')->insert([ | ||
['Name' => 'ReadCoop-Transkribus'], | ||
['Name' => 'CrossLang-Occam'] | ||
]); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('TranscriptionProvider'); | ||
} | ||
}; |
35 changes: 35 additions & 0 deletions
35
src/database/migrations/2024_09_19_121100_add_transcription_provider_id_to_htrdata_table.php
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,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::table('HtrData', function (Blueprint $table) { | ||
|
||
$table | ||
->unsignedSmallInteger('TranscriptionProviderId') | ||
->after('EuropeanaAnnotationId') | ||
->nullable(); | ||
|
||
$table->foreign('TranscriptionProviderId') | ||
->references('TranscriptionProviderId') | ||
->on('TranscriptionProvider') | ||
->nullOnDelete(); | ||
}); | ||
|
||
DB::table('HtrData')->update(['TranscriptionProviderId' => 1]); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::table('HtrData', function (Blueprint $table) { | ||
$table->dropForeign(['TranscriptionProviderId']); | ||
$table->dropColumn('TranscriptionProviderId'); | ||
}); | ||
} | ||
}; |
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
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,62 @@ | ||
get: | ||
tags: | ||
- htrdata | ||
summary: Get all stored transcription providers | ||
description: The index endpoint can be used to get all teams. The output is limited to 100 but can be filtered, sorted and paginated. The returned data is always an array even if the filter criteria is a unique identifier. | ||
parameters: | ||
- $ref: 'basic-query-parameter.yaml#/PaginationParameters/limit' | ||
- $ref: 'basic-query-parameter.yaml#/PaginationParameters/page' | ||
- in: query | ||
name: orderBy | ||
default: TranscriptionProviderId | ||
description: Table column to order the return | ||
schema: | ||
type: string | ||
- $ref: 'basic-query-parameter.yaml#/SortParameters/orderDir' | ||
responses: | ||
200: | ||
description: Ok | ||
content: | ||
application/json: | ||
schema: | ||
allOf: | ||
- $ref: 'responses.yaml#/BasicSuccessResponse' | ||
- properties: | ||
meta: | ||
type: object | ||
description: Meta data with pagination details | ||
$ref: 'meta-responses.yaml#MetaPaginationResponse' | ||
data: | ||
type: array | ||
description: A transcription provider entry objects as array | ||
items: | ||
$ref: 'transcription-providers-schema.yaml#/TranscriptionProvidersGetResponseSchema' | ||
401: | ||
$ref: 'responses.yaml#/401ErrorResponse' | ||
post: | ||
tags: | ||
- htrdata | ||
summary: Store a new transcription provider entry | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: 'transcription-providers-schema.yaml#/TranscriptionProvidersPostRequestSchema' | ||
responses: | ||
200: | ||
description: Ok | ||
content: | ||
application/json: | ||
schema: | ||
allOf: | ||
- $ref: 'responses.yaml#/BasicSuccessResponse' | ||
- properties: | ||
message: | ||
example: Transcription provider inserted. | ||
data: | ||
$ref: 'transcription-providers-schema.yaml#/TranscriptionProvidersGetResponseSchema' | ||
401: | ||
$ref: 'responses.yaml#/401ErrorResponse' | ||
400: | ||
$ref: 'responses.yaml#/400ErrorResponse' |
Oops, something went wrong.