Skip to content

Commit

Permalink
refactor: Add class name to factions
Browse files Browse the repository at this point in the history
Fixes #125
  • Loading branch information
octfx committed May 8, 2024
1 parent 9a6e97a commit d272e61
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/Http/Resources/SC/Faction/FactionLinkResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
properties: [
new OA\Property(property: 'uuid', type: 'string'),
new OA\Property(property: 'name', type: 'string'),
new OA\Property(property: 'class_name', type: 'string'),
new OA\Property(property: 'link', type: 'string'),
],
type: 'object'
Expand All @@ -23,6 +24,7 @@ public function toArray(Request $request): array
return [
'uuid' => $this->uuid,
'name' => $this->name,
'class_name' => $this->class_name,
'link' => $this->makeApiUrl(self::FACTIONS_SHOW, $this->uuid),
];
}
Expand Down
22 changes: 11 additions & 11 deletions app/Http/Resources/SC/Faction/FactionRelationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
schema: 'faction_relation_v2',
title: 'Faction Relation',
description: 'Relation between two factions',
properties: [
new OA\Property(property: 'uuid', type: 'string'),
new OA\Property(property: 'name', type: 'string'),
new OA\Property(property: 'relation', type: 'string'),
new OA\Property(property: 'link', type: 'string'),
],
type: 'object'
type: 'object',
allOf: [
new OA\Schema(ref: '#/components/schemas/faction_link_v2'),
new OA\Schema(
properties: [
new OA\Property(property: 'relation', type: 'string'),
],
type: 'object'
),
]
)]
class FactionRelationResource extends AbstractBaseResource
{
public function toArray(Request $request): array
{
return [
'uuid' => $this->faction->uuid,
'name' => $this->faction->name,
return (new FactionLinkResource($this->faction))->resolve($request) + [
'relation' => $this->relation,
'link' => $this->makeApiUrl(self::FACTIONS_SHOW, $this->faction->uuid),
];
}
}
7 changes: 6 additions & 1 deletion app/Models/SC/Faction/Faction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Faction extends Model

public function relations(): HasMany
{
return $this->hasMany(FactionRelation::class);
return $this->hasMany(
FactionRelation::class,
'faction_id',
'id',
)
->whereHas('faction');
}
}
6 changes: 5 additions & 1 deletion app/Models/SC/Faction/FactionRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class FactionRelation extends Model

public function faction(): BelongsTo
{
return $this->belongsTo(Faction::class, 'other_faction_uuid', 'uuid');
return $this->belongsTo(
Faction::class,
'other_faction_uuid',
'uuid'
);
}
}

0 comments on commit d272e61

Please sign in to comment.