From e753b7848554274efeedfeb7b3c0cc43cb5f65a4 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Mon, 1 Jul 2024 17:00:19 -0600 Subject: [PATCH] Private Races export/import/api --- app/Http/Resources/CharacterResource.php | 4 +++- app/Services/Campaign/Import/Mappers/EntityMapper.php | 6 +++++- resources/api-docs/1.0/characters.md | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Resources/CharacterResource.php b/app/Http/Resources/CharacterResource.php index cd7d7b9605..a0e06eb602 100644 --- a/app/Http/Resources/CharacterResource.php +++ b/app/Http/Resources/CharacterResource.php @@ -17,7 +17,8 @@ public function toArray($request) /** @var Character $model */ $model = $this->resource; - $raceIDs = $model->characterRaces->pluck('race.id'); + $raceIDs = $model->characterRaces->where('is_private', false)->pluck('race.id'); + $privateRaceIDs = $model->characterRaces->where('is_private', true)->pluck('race.id'); $familyIDs = $model->families->pluck('id'); $character = [ @@ -26,6 +27,7 @@ public function toArray($request) 'sex' => $model->sex, 'pronouns' => $model->pronouns, 'races' => $raceIDs, + 'private_races' => $privateRaceIDs, 'type' => $model->type, 'families' => $familyIDs, diff --git a/app/Services/Campaign/Import/Mappers/EntityMapper.php b/app/Services/Campaign/Import/Mappers/EntityMapper.php index 9f9f8f5d43..a94d63ac1c 100644 --- a/app/Services/Campaign/Import/Mappers/EntityMapper.php +++ b/app/Services/Campaign/Import/Mappers/EntityMapper.php @@ -357,7 +357,11 @@ protected function pivot(string $relation, string $model, string $field): self continue; } $foreignID = ImportIdMapper::get($model, $pivot[$field]); - $this->model->{$model}()->attach($foreignID); + if (array_key_exists('is_private', $pivot)) { + $this->model->{$model}()->attach($foreignID, ['is_private' => $pivot['is_private']]); + } else { + $this->model->{$model}()->attach($foreignID); + } } return $this; } diff --git a/resources/api-docs/1.0/characters.md b/resources/api-docs/1.0/characters.md index 1410ded053..8a4664d12b 100644 --- a/resources/api-docs/1.0/characters.md +++ b/resources/api-docs/1.0/characters.md @@ -54,6 +54,7 @@ The list of returned entities can be filtered. The available filters are [availa "sex": "Male", "pronouns": null, "races": [3], + "private_races": [2, 5], "type": null, "families": [34], "is_dead": true, @@ -111,6 +112,7 @@ To get the details of a single character, use the following endpoint. "sex": "Male", "pronouns": null, "races": [3], + "private_races": [2, 5], "type": null, "families": [34], "is_dead": true,