Skip to content

Commit

Permalink
Merge pull request #260 from art-institute-of-chicago/fix/tour-api-ou…
Browse files Browse the repository at this point in the history
…tput

Fix tours API output [MA-156]
  • Loading branch information
nikhiltri authored Feb 28, 2024
2 parents 2ef0be7 + 3ab45cb commit 19942b4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/Models/LoanObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class LoanObject extends AbstractModel
'title',
];

protected $attributes = [
'is_on_view' => true,
];

public function gallery(): BelongsTo
{
return $this->belongsToApi(\App\Models\Api\Gallery::class, 'gallery_id');
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Stop.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function title(): Attribute
);
}

public function objectId(): Attribute
{
return Attribute::make(
get: fn (): string => $this->selector?->object->datahub_id ?? $this->selector?->object->id,
);
}

public function selector(): MorphOne
{
return $this->morphOne(Selector::class, 'selectable');
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Transformers/StopTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StopTransformer extends TransformerAbstract
public function transform(TwillModelContract $stop): array
{
return [
'object' => "$stop->object_type:$stop->object_id",
'object' => lcfirst(class_basename($stop->selector?->object)) . ':' . $stop->object_id,
'audio_id' => (string) $stop->selector?->number,
'audio_bumper' => null, // Legacy from Drupal
'sort' => $stop->pivot->position,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Database\Migrations\Migration;
use App\Models\LoanObject;

return new class extends Migration
{
public function up(): void
{
LoanObject::query()->update(['is_on_view' => 1]);
}

public function down(): void
{
LoanObject::query()->update(['is_on_view' => null]);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
$table->boolean('is_on_view')->default(true)->change();
});
}

public function down(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
$table->boolean('is_on_view')->default(null)->change();
});
}
};

0 comments on commit 19942b4

Please sign in to comment.