Skip to content

Commit

Permalink
Merge pull request #4734 from RoboJackets/kristaps/distribution-merch…
Browse files Browse the repository at this point in the history
…-size

Provide merch size in distribution API
  • Loading branch information
kberzinch authored Jul 28, 2024
2 parents b502c67 + 39a3e62 commit 4290b81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Http/Controllers/MerchandiseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ private static function getDuesTransactionMerchandise(
'dues_transaction_merchandise.provided_at',
'dues_transaction_merchandise.provided_by',
'dues_transaction_merchandise.provided_via',
'dues_transaction_merchandise.merchandise_id'
'dues_transaction_merchandise.merchandise_id',
'dues_transaction_merchandise.dues_transaction_id'
)
->whereHas('transaction', static function (Builder $query) use ($user) {
$query->where('user_id', $user->id)
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Resources/DuesTransactionMerchandise.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function toArray(Request $request): array
'provided_at' => $this->provided_at,
'provided_by' => Manager::make($this->providedBy),
'provided_via' => $this->provided_via,
'size' => [
'short' => $this->size,
'display_name' => $this->size === null ? null : \App\Models\User::$shirt_sizes[$this->size],
],
'merchandise' => $this->when($this->withMerchandise, $this->merchandise),
];
}
Expand Down
16 changes: 16 additions & 0 deletions app/Models/DuesTransactionMerchandise.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Str;

/**
* App\Models\DuesTransactionMerchandise.
Expand All @@ -19,6 +20,7 @@
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\User|null $providedBy
* @property-read ?string $size
*
* @method static \Illuminate\Database\Eloquent\Builder|DuesTransactionMerchandise newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|DuesTransactionMerchandise newQuery()
Expand Down Expand Up @@ -80,4 +82,18 @@ public function merchandise(): BelongsTo
{
return $this->belongsTo(Merchandise::class);
}

/**
* Get the size for this DuesTransactionMerchandise based on data about the merchandise item and user.
*/
public function getSizeAttribute(): ?string
{
if (Str::contains(Str::lower($this->merchandise->name), 'shirt')) {
return $this->transaction->user->shirt_size;
} elseif (Str::contains(Str::lower($this->merchandise->name), 'polo')) {
return $this->transaction->user->polo_size;
} else {
return null;
}
}
}

0 comments on commit 4290b81

Please sign in to comment.