34 lines
874 B
PHP
34 lines
874 B
PHP
<?php
|
|
|
|
namespace App\Services\CafeBazaar;
|
|
|
|
use App\Models\BazaarRelease;
|
|
use App\Models\MobileApp;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class BazaarReleaseRecorder
|
|
{
|
|
public function record(MobileApp $app, string $status, BazaarResponse $response, array $attributes = []): ?BazaarRelease
|
|
{
|
|
if (! $response->successful()) {
|
|
return null;
|
|
}
|
|
|
|
$release = BazaarRelease::query()
|
|
->whereBelongsTo($app)
|
|
->latest()
|
|
->first();
|
|
|
|
$release ??= new BazaarRelease(['mobile_app_id' => $app->id]);
|
|
$release->fill([
|
|
...$attributes,
|
|
'bazaar_release_id' => Arr::get($response->body, 'release.id', $release->bazaar_release_id),
|
|
'status' => $status,
|
|
'bazaar_response' => $response->body,
|
|
]);
|
|
$release->save();
|
|
|
|
return $release;
|
|
}
|
|
}
|