Skip to content

Commit

Permalink
Private Races export/import/api
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Jul 1, 2024
1 parent f234862 commit e753b78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Http/Resources/CharacterResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -26,6 +27,7 @@ public function toArray($request)
'sex' => $model->sex,
'pronouns' => $model->pronouns,
'races' => $raceIDs,
'private_races' => $privateRaceIDs,
'type' => $model->type,

'families' => $familyIDs,
Expand Down
6 changes: 5 additions & 1 deletion app/Services/Campaign/Import/Mappers/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions resources/api-docs/1.0/characters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e753b78

Please sign in to comment.